Linux-LEDs Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] leds: lgm: Propagate error codes to the caller
@ 2021-04-11  7:45 Christophe JAILLET
  2021-04-11  7:45 ` [PATCH 2/2] leds: lgm: Fix an error handling path in '__sso_led_dt_parse()' Christophe JAILLET
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2021-04-11  7:45 UTC (permalink / raw)
  To: pavel, mallikarjunax.reddy
  Cc: linux-leds, linux-kernel, kernel-janitors, Christophe JAILLET

Do not always return -EINVAL in case of error in '__sso_led_dt_parse()'.
Propagate the error code instead.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/leds/blink/leds-lgm-sso.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/blink/leds-lgm-sso.c b/drivers/leds/blink/leds-lgm-sso.c
index 7d5c9ca007d6..3da242d4ce7d 100644
--- a/drivers/leds/blink/leds-lgm-sso.c
+++ b/drivers/leds/blink/leds-lgm-sso.c
@@ -643,6 +643,7 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct fwnode_handle *fw_ssoled)
 							      GPIOD_ASIS, NULL);
 		if (IS_ERR(led->gpiod)) {
 			dev_err(dev, "led: get gpio fail!\n");
+			ret = PTR_ERR(led->gpiod);
 			goto __dt_err;
 		}
 
@@ -664,6 +665,7 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct fwnode_handle *fw_ssoled)
 		ret = fwnode_property_read_u32(fwnode_child, "reg", &prop);
 		if (ret != 0 || prop >= SSO_LED_MAX_NUM) {
 			dev_err(dev, "invalid LED pin:%u\n", prop);
+			ret = ret ? ret : -EINVAL;
 			goto __dt_err;
 		}
 		desc->pin = prop;
@@ -699,8 +701,10 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct fwnode_handle *fw_ssoled)
 				desc->brightness = LED_FULL;
 		}
 
-		if (sso_create_led(priv, led, fwnode_child))
+		if (sso_create_led(priv, led, fwnode_child)) {
+			ret = -EINVAL;
 			goto __dt_err;
+		}
 	}
 	fwnode_handle_put(fw_ssoled);
 
@@ -713,7 +717,7 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct fwnode_handle *fw_ssoled)
 		sso_led_shutdown(led);
 	}
 
-	return -EINVAL;
+	return ret;
 }
 
 static int sso_led_dt_parse(struct sso_led_priv *priv)
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] leds: lgm: Fix an error handling path in '__sso_led_dt_parse()'
  2021-04-11  7:45 [PATCH 1/2] leds: lgm: Propagate error codes to the caller Christophe JAILLET
@ 2021-04-11  7:45 ` Christophe JAILLET
  0 siblings, 0 replies; 2+ messages in thread
From: Christophe JAILLET @ 2021-04-11  7:45 UTC (permalink / raw)
  To: pavel, mallikarjunax.reddy
  Cc: linux-leds, linux-kernel, kernel-janitors, Christophe JAILLET

If a memory allocation fails, we must free the already allocated resources
before returning.

Fixes: c3987cd2bca3 ("leds: lgm: Add LED controller driver for LGM SoC")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/leds/blink/leds-lgm-sso.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/blink/leds-lgm-sso.c b/drivers/leds/blink/leds-lgm-sso.c
index 3da242d4ce7d..ef632ebabac9 100644
--- a/drivers/leds/blink/leds-lgm-sso.c
+++ b/drivers/leds/blink/leds-lgm-sso.c
@@ -631,8 +631,10 @@ __sso_led_dt_parse(struct sso_led_priv *priv, struct fwnode_handle *fw_ssoled)
 
 	fwnode_for_each_child_node(fw_ssoled, fwnode_child) {
 		led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
-		if (!led)
-			return -ENOMEM;
+		if (!led) {
+			ret = -ENOMEM;
+			goto __dt_err;
+		}
 
 		INIT_LIST_HEAD(&led->list);
 		led->priv = priv;
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-11  7:45 [PATCH 1/2] leds: lgm: Propagate error codes to the caller Christophe JAILLET
2021-04-11  7:45 ` [PATCH 2/2] leds: lgm: Fix an error handling path in '__sso_led_dt_parse()' Christophe JAILLET

Linux-LEDs Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-leds/0 linux-leds/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-leds linux-leds/ https://lore.kernel.org/linux-leds \
		linux-leds@vger.kernel.org
	public-inbox-index linux-leds

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-leds


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git