* [PATCH] charger: max14577: Handle NULL pdata when CONFIG_OF is not set
@ 2025-05-16 9:53 Charles Han
2025-05-16 12:32 ` Krzysztof Kozlowski
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Charles Han @ 2025-05-16 9:53 UTC (permalink / raw)
To: krzk, sre, akpm, lee; +Cc: linux-pm, linux-kernel, Charles Han
When the kernel is not configured CONFIG_OF, the max14577_charger_dt_init
function returns NULL. Fix the max14577_charger_probe functionby returning
-ENODATA instead of potentially passing a NULL pointer to PTR_ERR.
Fix below smatch warning.
smatch warnings:
drivers/power/supply/max14577_charger.c:576 max14577_charger_probe() warn: passing zero to 'PTR_ERR'
Fixes: e30110e9c96f ("charger: max14577: Configure battery-dependent settings from DTS and sysfs")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
drivers/power/supply/max14577_charger.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/max14577_charger.c b/drivers/power/supply/max14577_charger.c
index 1cef2f860b5f..ed6f5a584c2c 100644
--- a/drivers/power/supply/max14577_charger.c
+++ b/drivers/power/supply/max14577_charger.c
@@ -572,8 +572,10 @@ static int max14577_charger_probe(struct platform_device *pdev)
chg->max14577 = max14577;
chg->pdata = max14577_charger_dt_init(pdev);
- if (IS_ERR_OR_NULL(chg->pdata))
+ if (IS_ERR(chg->pdata))
return PTR_ERR(chg->pdata);
+ else if (!chg->pdata)
+ return -ENODATA;
ret = max14577_charger_reg_init(chg);
if (ret)
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] charger: max14577: Handle NULL pdata when CONFIG_OF is not set 2025-05-16 9:53 [PATCH] charger: max14577: Handle NULL pdata when CONFIG_OF is not set Charles Han @ 2025-05-16 12:32 ` Krzysztof Kozlowski 2025-05-19 1:48 ` [PATCH V2] " Charles Han 2025-05-19 6:16 ` [PATCH V3] " Charles Han 2 siblings, 0 replies; 8+ messages in thread From: Krzysztof Kozlowski @ 2025-05-16 12:32 UTC (permalink / raw) To: Charles Han, sre, akpm, lee; +Cc: linux-pm, linux-kernel On 16/05/2025 11:53, Charles Han wrote: > When the kernel is not configured CONFIG_OF, the max14577_charger_dt_init > function returns NULL. Fix the max14577_charger_probe functionby returning > -ENODATA instead of potentially passing a NULL pointer to PTR_ERR. > > Fix below smatch warning. > smatch warnings: > drivers/power/supply/max14577_charger.c:576 max14577_charger_probe() warn: passing zero to 'PTR_ERR' > > Fixes: e30110e9c96f ("charger: max14577: Configure battery-dependent settings from DTS and sysfs") > Signed-off-by: Charles Han <hanchunchao@inspur.com> > --- > drivers/power/supply/max14577_charger.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/power/supply/max14577_charger.c b/drivers/power/supply/max14577_charger.c > index 1cef2f860b5f..ed6f5a584c2c 100644 > --- a/drivers/power/supply/max14577_charger.c > +++ b/drivers/power/supply/max14577_charger.c > @@ -572,8 +572,10 @@ static int max14577_charger_probe(struct platform_device *pdev) > chg->max14577 = max14577; > > chg->pdata = max14577_charger_dt_init(pdev); Thanks for the fix. I would prefer to fix the max14577_charger_dt_init() stub to return ERR_PTR(-ENODATA) in such case and then you have here only if (IS_ERR()). > - if (IS_ERR_OR_NULL(chg->pdata)) Best regards, Krzysztof ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH V2] charger: max14577: Handle NULL pdata when CONFIG_OF is not set 2025-05-16 9:53 [PATCH] charger: max14577: Handle NULL pdata when CONFIG_OF is not set Charles Han 2025-05-16 12:32 ` Krzysztof Kozlowski @ 2025-05-19 1:48 ` Charles Han 2025-05-19 5:51 ` Krzysztof Kozlowski 2025-05-19 5:58 ` kernel test robot 2025-05-19 6:16 ` [PATCH V3] " Charles Han 2 siblings, 2 replies; 8+ messages in thread From: Charles Han @ 2025-05-19 1:48 UTC (permalink / raw) To: krzk, sre, akpm, lee; +Cc: linux-pm, linux-kernel, Charles Han When the kernel is not configured CONFIG_OF, the max14577_charger_dt_init function returns NULL. Fix the max14577_charger_probe functionby returning -ENODATA instead of potentially passing a NULL pointer to PTR_ERR. Fix below smatch warning. smatch warnings: drivers/power/supply/max14577_charger.c:576 max14577_charger_probe() warn: passing zero to 'PTR_ERR' Fixes: e30110e9c96f ("charger: max14577: Configure battery-dependent settings from DTS and sysfs") Signed-off-by: Charles Han <hanchunchao@inspur.com> --- drivers/power/supply/max14577_charger.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/max14577_charger.c b/drivers/power/supply/max14577_charger.c index 1cef2f860b5f..af1694cac5ea 100644 --- a/drivers/power/supply/max14577_charger.c +++ b/drivers/power/supply/max14577_charger.c @@ -501,7 +501,7 @@ static struct max14577_charger_platform_data *max14577_charger_dt_init( static struct max14577_charger_platform_data *max14577_charger_dt_init( struct platform_device *pdev) { - return NULL; + return -ENODATA; } #endif /* CONFIG_OF */ @@ -572,7 +572,7 @@ static int max14577_charger_probe(struct platform_device *pdev) chg->max14577 = max14577; chg->pdata = max14577_charger_dt_init(pdev); - if (IS_ERR_OR_NULL(chg->pdata)) + if (IS_ERR(chg->pdata)) return PTR_ERR(chg->pdata); ret = max14577_charger_reg_init(chg); -- 2.43.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH V2] charger: max14577: Handle NULL pdata when CONFIG_OF is not set 2025-05-19 1:48 ` [PATCH V2] " Charles Han @ 2025-05-19 5:51 ` Krzysztof Kozlowski 2025-05-19 5:58 ` kernel test robot 1 sibling, 0 replies; 8+ messages in thread From: Krzysztof Kozlowski @ 2025-05-19 5:51 UTC (permalink / raw) To: Charles Han, sre, akpm, lee; +Cc: linux-pm, linux-kernel On 19/05/2025 03:48, Charles Han wrote: > When the kernel is not configured CONFIG_OF, the max14577_charger_dt_init > function returns NULL. Fix the max14577_charger_probe functionby returning > -ENODATA instead of potentially passing a NULL pointer to PTR_ERR. > > Fix below smatch warning. > smatch warnings: > drivers/power/supply/max14577_charger.c:576 max14577_charger_probe() warn: passing zero to 'PTR_ERR' > > Fixes: e30110e9c96f ("charger: max14577: Configure battery-dependent settings from DTS and sysfs") > Signed-off-by: Charles Han <hanchunchao@inspur.com> > --- > drivers/power/supply/max14577_charger.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/power/supply/max14577_charger.c b/drivers/power/supply/max14577_charger.c > index 1cef2f860b5f..af1694cac5ea 100644 > --- a/drivers/power/supply/max14577_charger.c > +++ b/drivers/power/supply/max14577_charger.c > @@ -501,7 +501,7 @@ static struct max14577_charger_platform_data *max14577_charger_dt_init( > static struct max14577_charger_platform_data *max14577_charger_dt_init( > struct platform_device *pdev) > { > - return NULL; > + return -ENODATA; No, you did not test it and it is obviously buggy code. Please learn first about pointers. Best regards, Krzysztof ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V2] charger: max14577: Handle NULL pdata when CONFIG_OF is not set 2025-05-19 1:48 ` [PATCH V2] " Charles Han 2025-05-19 5:51 ` Krzysztof Kozlowski @ 2025-05-19 5:58 ` kernel test robot 1 sibling, 0 replies; 8+ messages in thread From: kernel test robot @ 2025-05-19 5:58 UTC (permalink / raw) To: Charles Han, krzk, sre, akpm, lee Cc: oe-kbuild-all, linux-pm, linux-kernel, Charles Han Hi Charles, kernel test robot noticed the following build errors: [auto build test ERROR on sre-power-supply/for-next] [also build test ERROR on linus/master v6.15-rc7 next-20250516] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Charles-Han/charger-max14577-Handle-NULL-pdata-when-CONFIG_OF-is-not-set/20250519-095431 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next patch link: https://lore.kernel.org/r/20250519014804.2244-1-hanchunchao%40inspur.com patch subject: [PATCH V2] charger: max14577: Handle NULL pdata when CONFIG_OF is not set config: sh-randconfig-002-20250519 (https://download.01.org/0day-ci/archive/20250519/202505191305.un0tzZu1-lkp@intel.com/config) compiler: sh4-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250519/202505191305.un0tzZu1-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202505191305.un0tzZu1-lkp@intel.com/ All errors (new ones prefixed by >>): drivers/power/supply/max14577_charger.c: In function 'max14577_charger_dt_init': >> drivers/power/supply/max14577_charger.c:504:16: error: returning 'int' from a function with return type 'struct max14577_charger_platform_data *' makes pointer from integer without a cast [-Wint-conversion] 504 | return -ENODATA; | ^ vim +504 drivers/power/supply/max14577_charger.c 454 455 #ifdef CONFIG_OF 456 static struct max14577_charger_platform_data *max14577_charger_dt_init( 457 struct platform_device *pdev) 458 { 459 struct max14577_charger_platform_data *pdata; 460 struct device_node *np = pdev->dev.of_node; 461 int ret; 462 463 if (!np) { 464 dev_err(&pdev->dev, "No charger OF node\n"); 465 return ERR_PTR(-EINVAL); 466 } 467 468 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 469 if (!pdata) 470 return ERR_PTR(-ENOMEM); 471 472 ret = of_property_read_u32(np, "maxim,constant-uvolt", 473 &pdata->constant_uvolt); 474 if (ret) { 475 dev_err(&pdev->dev, "Cannot parse maxim,constant-uvolt field from DT\n"); 476 return ERR_PTR(ret); 477 } 478 479 ret = of_property_read_u32(np, "maxim,fast-charge-uamp", 480 &pdata->fast_charge_uamp); 481 if (ret) { 482 dev_err(&pdev->dev, "Cannot parse maxim,fast-charge-uamp field from DT\n"); 483 return ERR_PTR(ret); 484 } 485 486 ret = of_property_read_u32(np, "maxim,eoc-uamp", &pdata->eoc_uamp); 487 if (ret) { 488 dev_err(&pdev->dev, "Cannot parse maxim,eoc-uamp field from DT\n"); 489 return ERR_PTR(ret); 490 } 491 492 ret = of_property_read_u32(np, "maxim,ovp-uvolt", &pdata->ovp_uvolt); 493 if (ret) { 494 dev_err(&pdev->dev, "Cannot parse maxim,ovp-uvolt field from DT\n"); 495 return ERR_PTR(ret); 496 } 497 498 return pdata; 499 } 500 #else /* CONFIG_OF */ 501 static struct max14577_charger_platform_data *max14577_charger_dt_init( 502 struct platform_device *pdev) 503 { > 504 return -ENODATA; 505 } 506 #endif /* CONFIG_OF */ 507 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH V3] charger: max14577: Handle NULL pdata when CONFIG_OF is not set 2025-05-16 9:53 [PATCH] charger: max14577: Handle NULL pdata when CONFIG_OF is not set Charles Han 2025-05-16 12:32 ` Krzysztof Kozlowski 2025-05-19 1:48 ` [PATCH V2] " Charles Han @ 2025-05-19 6:16 ` Charles Han 2025-05-19 16:20 ` Krzysztof Kozlowski 2025-06-22 19:13 ` Sebastian Reichel 2 siblings, 2 replies; 8+ messages in thread From: Charles Han @ 2025-05-19 6:16 UTC (permalink / raw) To: krzk, sre, akpm, lee; +Cc: linux-pm, linux-kernel, Charles Han When the kernel is not configured CONFIG_OF, the max14577_charger_dt_init function returns NULL. Fix the max14577_charger_probe functionby returning -ENODATA instead of potentially passing a NULL pointer to PTR_ERR. Fix below smatch warning. smatch warnings: drivers/power/supply/max14577_charger.c:576 max14577_charger_probe() warn: passing zero to 'PTR_ERR' Fixes: e30110e9c96f ("charger: max14577: Configure battery-dependent settings from DTS and sysfs") Signed-off-by: Charles Han <hanchunchao@inspur.com> --- drivers/power/supply/max14577_charger.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/max14577_charger.c b/drivers/power/supply/max14577_charger.c index 1cef2f860b5f..63077d38ea30 100644 --- a/drivers/power/supply/max14577_charger.c +++ b/drivers/power/supply/max14577_charger.c @@ -501,7 +501,7 @@ static struct max14577_charger_platform_data *max14577_charger_dt_init( static struct max14577_charger_platform_data *max14577_charger_dt_init( struct platform_device *pdev) { - return NULL; + return ERR_PTR(-ENODATA); } #endif /* CONFIG_OF */ @@ -572,7 +572,7 @@ static int max14577_charger_probe(struct platform_device *pdev) chg->max14577 = max14577; chg->pdata = max14577_charger_dt_init(pdev); - if (IS_ERR_OR_NULL(chg->pdata)) + if (IS_ERR(chg->pdata)) return PTR_ERR(chg->pdata); ret = max14577_charger_reg_init(chg); -- 2.43.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH V3] charger: max14577: Handle NULL pdata when CONFIG_OF is not set 2025-05-19 6:16 ` [PATCH V3] " Charles Han @ 2025-05-19 16:20 ` Krzysztof Kozlowski 2025-06-22 19:13 ` Sebastian Reichel 1 sibling, 0 replies; 8+ messages in thread From: Krzysztof Kozlowski @ 2025-05-19 16:20 UTC (permalink / raw) To: Charles Han, sre, akpm, lee; +Cc: linux-pm, linux-kernel On 19/05/2025 08:16, Charles Han wrote: > When the kernel is not configured CONFIG_OF, the max14577_charger_dt_init > function returns NULL. Fix the max14577_charger_probe functionby returning Typo, "function by" Please wrap commit message according to Linux coding style / submission process (neither too early nor over the limit): https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597 Please use subject prefixes matching the subsystem. You can get them for example with `git log --oneline -- DIRECTORY_OR_FILE` on the directory your patch is touching. For bindings, the preferred subjects are explained here: https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters (there is no subsystem "charger"). > -ENODATA instead of potentially passing a NULL pointer to PTR_ERR. > > Fix below smatch warning. > smatch warnings: > drivers/power/supply/max14577_charger.c:576 max14577_charger_probe() warn: passing zero to 'PTR_ERR' > Do not attach (thread) your patchsets to some other threads (unrelated or older versions). This buries them deep in the mailbox and might interfere with applying entire sets. With that: Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Best regards, Krzysztof ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3] charger: max14577: Handle NULL pdata when CONFIG_OF is not set 2025-05-19 6:16 ` [PATCH V3] " Charles Han 2025-05-19 16:20 ` Krzysztof Kozlowski @ 2025-06-22 19:13 ` Sebastian Reichel 1 sibling, 0 replies; 8+ messages in thread From: Sebastian Reichel @ 2025-06-22 19:13 UTC (permalink / raw) To: krzk, sre, akpm, lee, Charles Han; +Cc: linux-pm, linux-kernel On Mon, 19 May 2025 14:16:01 +0800, Charles Han wrote: > When the kernel is not configured CONFIG_OF, the max14577_charger_dt_init > function returns NULL. Fix the max14577_charger_probe functionby returning > -ENODATA instead of potentially passing a NULL pointer to PTR_ERR. > > Fix below smatch warning. > smatch warnings: > drivers/power/supply/max14577_charger.c:576 max14577_charger_probe() warn: passing zero to 'PTR_ERR' > > [...] Applied, thanks! [1/1] charger: max14577: Handle NULL pdata when CONFIG_OF is not set commit: 2937f5d2e24eefef8cb126244caec7fe3307f724 Best regards, -- Sebastian Reichel <sebastian.reichel@collabora.com> ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-06-22 19:13 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-05-16 9:53 [PATCH] charger: max14577: Handle NULL pdata when CONFIG_OF is not set Charles Han 2025-05-16 12:32 ` Krzysztof Kozlowski 2025-05-19 1:48 ` [PATCH V2] " Charles Han 2025-05-19 5:51 ` Krzysztof Kozlowski 2025-05-19 5:58 ` kernel test robot 2025-05-19 6:16 ` [PATCH V3] " Charles Han 2025-05-19 16:20 ` Krzysztof Kozlowski 2025-06-22 19:13 ` Sebastian Reichel
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.