[PATCH V3] charger: max14577: Handle NULL pdata when CONFIG_OF is not set

Charles Han posted 1 patch 7 months ago
drivers/power/supply/max14577_charger.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH V3] charger: max14577: Handle NULL pdata when CONFIG_OF is not set
Posted by Charles Han 7 months ago
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
Re: [PATCH V3] charger: max14577: Handle NULL pdata when CONFIG_OF is not set
Posted by Sebastian Reichel 5 months, 4 weeks ago
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>
Re: [PATCH V3] charger: max14577: Handle NULL pdata when CONFIG_OF is not set
Posted by Krzysztof Kozlowski 7 months ago
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