diff mbox series

[-next] rtc: stmp3xxx: Add failure handling for stmp3xxx_wdt_register()

Message ID 20220914032159.94812-1-linyujun809@huawei.com
State Superseded
Headers show
Series [-next] rtc: stmp3xxx: Add failure handling for stmp3xxx_wdt_register() | expand

Commit Message

linyujun (C) Sept. 14, 2022, 3:21 a.m. UTC
Use platform_device_put() to free platform device before print
error message when platform_device_add() fails to run. Add dev_err()
to report error in case of alloc memory to wdt_pdev fail.

Fixes: 1a71fb84fda6 ("rtc: stmp3xxx: add wdt-accessor function")
Signed-off-by: Lin Yujun <linyujun809@huawei.com>
---
 drivers/rtc/rtc-stmp3xxx.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Wolfram Sang Sept. 14, 2022, 11:02 p.m. UTC | #1
> +		if (rc)
> +			platform_device_put(wdt_pdev);

This is correct, thanks.

> +	} else {
> +		dev_err(&rtc_pdev->dev,
> +			"failed to allocate stmp3xxx_rtc_wdt\n");

This is superfluous because rc is initialized to -1.
linyujun (C) Sept. 15, 2022, 1:29 a.m. UTC | #2
Thank you for your suggestion, I will send out the v2 version as soon as 
possible.

在 2022/9/15 7:02, Wolfram Sang 写道:
> This is correct, thanks.
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index 40c0f7ed36e0..b2f4b034cdb6 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -107,6 +107,11 @@  static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev)
 		wdt_pdev->dev.parent = &rtc_pdev->dev;
 		wdt_pdev->dev.platform_data = &wdt_pdata;
 		rc = platform_device_add(wdt_pdev);
+		if (rc)
+			platform_device_put(wdt_pdev);
+	} else {
+		dev_err(&rtc_pdev->dev,
+			"failed to allocate stmp3xxx_rtc_wdt\n");
 	}
 
 	if (rc)