Skip to contentSkip to conversation

nvmem: core: fix return value

PATCH Applied Russell King (Oracle) 3 participants 4 messages Jan 10, 2023 NVMEM framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: core: fix return value

Dan Carpenter points out that the return code was not set in commit 60c8b4aebd8e ("nvmem: core: fix cleanup after dev_set_name()"), but this is not the only issue - we also need to zero wp_gpio to prevent gpiod_put() being called on an error value.

Fixes 60c8b4aebd8e ("nvmem: core: fix cleanup after dev_set_name()")
---
 drivers/nvmem/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvmem/core.c +4 -1
index 082cda7ac199..1ee2e9255f7b 100644
@@ -781,8 +781,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (!config->ignore_wp)
 		nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
 						    GPIOD_OUT_HIGH);
-	if (IS_ERR(nvmem->wp_gpio))
+	if (IS_ERR(nvmem->wp_gpio)) {
+		rval = PTR_ERR(nvmem->wp_gpio);
+		nvmem->wp_gpio = NULL;
 		goto err_put_device;
+	}
 
 	kref_init(&nvmem->refcnt);
 	INIT_LIST_HEAD(&nvmem->cells);
Signature · 7 lines
2.30.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

Hi Russell,

Quoted 18 lines · Russell King (Oracle)

Dan Carpenter points out that the return code was not set in commit 60c8b4aebd8e ("nvmem: core: fix cleanup after dev_set_name()"), but this is not the only issue - we also need to zero wp_gpio to prevent gpiod_put() being called on an error value.

Fixes 60c8b4aebd8e ("nvmem: core: fix cleanup after dev_set_name()")
---
  drivers/nvmem/core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvmem/core.c +0 -0
index 082cda7ac199..1ee2e9255f7b 100644

drivers/nvmem/core.c struct nvmem_device *nvmem_register(const struct nvmem_config *config) · line 787

Quoted 8 lines
drivers/nvmem/core.c +3 -1
@@ -781,8 +781,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
  	if (!config->ignore_wp)
  		nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
  						    GPIOD_OUT_HIGH);
-	if (IS_ERR(nvmem->wp_gpio))
+	if (IS_ERR(nvmem->wp_gpio)) {
+		rval = PTR_ERR(nvmem->wp_gpio);
+		nvmem->wp_gpio = NULL;
  		goto err_put_device;

I have already added this change while applying v3 patches.

thanks,

--srini

drivers/nvmem/core.c struct nvmem_device *nvmem_register(const struct nvmem_config *config) · line 791

Quoted 4 lines
drivers/nvmem/core.c +1 -0
+	}
 
  	kref_init(&nvmem->refcnt);
  	INIT_LIST_HEAD(&nvmem->cells);

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw
Quoted 16 lines · Srinivas Kandagatla

Hi Russell,

Quoted 13 lines · Russell King (Oracle)

Dan Carpenter points out that the return code was not set in commit 60c8b4aebd8e ("nvmem: core: fix cleanup after dev_set_name()"), but this is not the only issue - we also need to zero wp_gpio to prevent gpiod_put() being called on an error value.

Fixes 60c8b4aebd8e ("nvmem: core: fix cleanup after dev_set_name()")
---
  drivers/nvmem/core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 15 lines

drivers/nvmem/core.c struct nvmem_device *nvmem_register(const struct nvmem_config *config) · line 787

Quoted 13 lines
drivers/nvmem/core.c +3 -1
index 082cda7ac199..1ee2e9255f7b 100644
@@ -781,8 +781,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
  	if (!config->ignore_wp)
  		nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
  						    GPIOD_OUT_HIGH);
-	if (IS_ERR(nvmem->wp_gpio))
+	if (IS_ERR(nvmem->wp_gpio)) {
+		rval = PTR_ERR(nvmem->wp_gpio);
+		nvmem->wp_gpio = NULL;
  		goto err_put_device;

I have already added this change while applying v3 patches.

You still need wp_gpio to be NULL'd out, otherwise we'll end up calling gpiod_put() on the error-pointer.

Signature · 7 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#3 lore raw
Quoted 33 lines · Russell King (Oracle)
Quoted 16 lines · Srinivas Kandagatla

Hi Russell,

Quoted 13 lines · Russell King (Oracle)

Dan Carpenter points out that the return code was not set in commit 60c8b4aebd8e ("nvmem: core: fix cleanup after dev_set_name()"), but this is not the only issue - we also need to zero wp_gpio to prevent gpiod_put() being called on an error value.

Fixes 60c8b4aebd8e ("nvmem: core: fix cleanup after dev_set_name()")
---
   drivers/nvmem/core.c | 5 ++++-
   1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 15 lines

drivers/nvmem/core.c struct nvmem_device *nvmem_register(const struct nvmem_config *config) · line 787

Quoted 13 lines
drivers/nvmem/core.c +3 -1
index 082cda7ac199..1ee2e9255f7b 100644
@@ -781,8 +781,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
   	if (!config->ignore_wp)
   		nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
   						    GPIOD_OUT_HIGH);
-	if (IS_ERR(nvmem->wp_gpio))
+	if (IS_ERR(nvmem->wp_gpio)) {
+		rval = PTR_ERR(nvmem->wp_gpio);
+		nvmem->wp_gpio = NULL;
   		goto err_put_device;

I have already added this change while applying v3 patches.

Quoted 2 lines

You still need wp_gpio to be NULL'd out, otherwise we'll end up calling gpiod_put() on the error-pointer.

That is true..

applied

thanks,
--srini

Quoted 1 line

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel