diff mbox series

[net-next,1/4] ptp: vmclock: Set driver data before its usage

Message ID 20250206-vmclock-probe-v1-1-17a3ea07be34@linutronix.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ptp: vmclock: bugfixes and cleanups for error handling | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1 this patch: 1
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest warning net-next-2025-02-07--03-00 (tests: 478)

Commit Message

Thomas Weißschuh Feb. 6, 2025, 5:45 p.m. UTC
If vmlock_ptp_register() fails during probing, vmclock_remove() is
called to clean up the ptp clock and misc device.
It uses dev_get_drvdata() to access the vmclock state.
However the driver data is not yet set at this point.

Assign the driver data earlier.

Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 drivers/ptp/ptp_vmclock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Mateusz Polchlopek Feb. 7, 2025, 7:07 a.m. UTC | #1
On 2/6/2025 6:45 PM, Thomas Weißschuh wrote:
> If vmlock_ptp_register() fails during probing, vmclock_remove() is

Typo: you missed 'c' in function name - vmclock_ptp_register

> called to clean up the ptp clock and misc device.
> It uses dev_get_drvdata() to access the vmclock state.
> However the driver data is not yet set at this point.
> 
> Assign the driver data earlier.
> 
> Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
>   drivers/ptp/ptp_vmclock.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
> index 0a2cfc8ad3c5408a87fd8fedeff274ab895de3dd..1920698ae6eba6abfff5b61afae1b047910026fd 100644
> --- a/drivers/ptp/ptp_vmclock.c
> +++ b/drivers/ptp/ptp_vmclock.c
> @@ -524,6 +524,8 @@ static int vmclock_probe(struct platform_device *pdev)
>   		goto out;
>   	}
>   
> +	dev_set_drvdata(dev, st);
> +
>   	if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC ||
>   	    le32_to_cpu(st->clk->size) > resource_size(&st->res) ||
>   	    le16_to_cpu(st->clk->version) != 1) {
> @@ -587,8 +589,6 @@ static int vmclock_probe(struct platform_device *pdev)
>   		 (st->miscdev.minor && st->ptp_clock) ? ", " : "",
>   		 st->ptp_clock ? "PTP" : "");
>   
> -	dev_set_drvdata(dev, st);
> -
>    out:
>   	return ret;
>   }
> 

Nice catch! The code looks good but please fix the typo in the
commit msg, as this may be misleading. When applied please add my:

Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com>
diff mbox series

Patch

diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index 0a2cfc8ad3c5408a87fd8fedeff274ab895de3dd..1920698ae6eba6abfff5b61afae1b047910026fd 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -524,6 +524,8 @@  static int vmclock_probe(struct platform_device *pdev)
 		goto out;
 	}
 
+	dev_set_drvdata(dev, st);
+
 	if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC ||
 	    le32_to_cpu(st->clk->size) > resource_size(&st->res) ||
 	    le16_to_cpu(st->clk->version) != 1) {
@@ -587,8 +589,6 @@  static int vmclock_probe(struct platform_device *pdev)
 		 (st->miscdev.minor && st->ptp_clock) ? ", " : "",
 		 st->ptp_clock ? "PTP" : "");
 
-	dev_set_drvdata(dev, st);
-
  out:
 	return ret;
 }