Skip to contentSkip to conversation

greybus: gb-beagleplay: remove unneeded calls to devm_gpiod_put()

PATCH Superseded Bartosz Golaszewski 2 participants 2 messages Jun 18, 2025 – Jun 23, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 greybus: gb-beagleplay: remove unneeded calls to devm_gpiod_put()

From: Bartosz Golaszewski <[email protected]>

gb_fw_init() is only called in this driver's probe() and we abort the probing if it fails. This means that calling devm_gpiod_put() in error path is not required as devres will already manage the releasing of the resources when the device is detached.

---
 drivers/greybus/gb-beagleplay.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)
drivers/greybus/gb-beagleplay.c +4 -17
index da31f1131afc..1ea48b71a030 100644
@@ -1041,7 +1041,6 @@ static const struct fw_upload_ops cc1352_bootloader_ops = {
 
 static int gb_fw_init(struct gb_beagleplay *bg)
 {
-	int ret;
 	struct fw_upload *fwl;
 	struct gpio_desc *desc;
 
@@ -1060,29 +1059,17 @@ static int gb_fw_init(struct gb_beagleplay *bg)
 	bg->bootloader_backdoor_gpio = desc;
 
 	desc = devm_gpiod_get(&bg->sd->dev, "reset", GPIOD_IN);
-	if (IS_ERR(desc)) {
-		ret = PTR_ERR(desc);
-		goto free_boot;
-	}
+	if (IS_ERR(desc))
+		return PTR_ERR(desc);
 	bg->rst_gpio = desc;
 
 	fwl = firmware_upload_register(THIS_MODULE, &bg->sd->dev, "cc1352p7",
 				       &cc1352_bootloader_ops, bg);
-	if (IS_ERR(fwl)) {
-		ret = PTR_ERR(fwl);
-		goto free_reset;
-	}
+	if (IS_ERR(fwl))
+		return PTR_ERR(fwl);
 	bg->fwl = fwl;
 
 	return 0;
-
-free_reset:
-	devm_gpiod_put(&bg->sd->dev, bg->rst_gpio);
-	bg->rst_gpio = NULL;
-free_boot:
-	devm_gpiod_put(&bg->sd->dev, bg->bootloader_backdoor_gpio);
-	bg->bootloader_backdoor_gpio = NULL;
-	return ret;
 }
 
 static void gb_fw_deinit(struct gb_beagleplay *bg)
Signature · 1 line
2.48.1
maintainer
#1 lore raw
Quoted 48 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

gb_fw_init() is only called in this driver's probe() and we abort the probing if it fails. This means that calling devm_gpiod_put() in error path is not required as devres will already manage the releasing of the resources when the device is detached.

---
  drivers/greybus/gb-beagleplay.c | 21 ++++-----------------
  1 file changed, 4 insertions(+), 17 deletions(-)
drivers/greybus/gb-beagleplay.c +4 -10
index da31f1131afc..1ea48b71a030 100644
@@ -1041,7 +1041,6 @@ static const struct fw_upload_ops cc1352_bootloader_ops = {
 
  static int gb_fw_init(struct gb_beagleplay *bg)
  {
-	int ret;
  	struct fw_upload *fwl;
  	struct gpio_desc *desc;
 
@@ -1060,29 +1059,17 @@ static int gb_fw_init(struct gb_beagleplay *bg)
  	bg->bootloader_backdoor_gpio = desc;
 
  	desc = devm_gpiod_get(&bg->sd->dev, "reset", GPIOD_IN);
-	if (IS_ERR(desc)) {
-		ret = PTR_ERR(desc);
-		goto free_boot;
-	}
+	if (IS_ERR(desc))
+		return PTR_ERR(desc);
  	bg->rst_gpio = desc;
 
  	fwl = firmware_upload_register(THIS_MODULE, &bg->sd->dev, "cc1352p7",
  				       &cc1352_bootloader_ops, bg);
-	if (IS_ERR(fwl)) {
-		ret = PTR_ERR(fwl);
-		goto free_reset;
-	}
+	if (IS_ERR(fwl))
+		return PTR_ERR(fwl);
  	bg->fwl = fwl;
 
  	return 0;
-

drivers/greybus/gb-beagleplay.c static int gb_fw_init(struct gb_beagleplay *bg) · line 1075

Quoted 10 lines
drivers/greybus/gb-beagleplay.c +0 -7
-free_reset:
-	devm_gpiod_put(&bg->sd->dev, bg->rst_gpio);
-	bg->rst_gpio = NULL;
-free_boot:
-	devm_gpiod_put(&bg->sd->dev, bg->bootloader_backdoor_gpio);
-	bg->bootloader_backdoor_gpio = NULL;
-	return ret;
  }
 
  static void gb_fw_deinit(struct gb_beagleplay *bg)

Can you add a comment above the function that it should only ever be called from probing code since it does not free up the resources? I might end up forgetting and using it improperly in the future.

Best Regards,

Ayush Singh