Skip to contentSkip to conversation

led: drivers bug fixes

PATCH New Simon Guinot 3 participants 9 messages Mar 19, 2013 – Mar 21, 2013 LED

lore
Share & tools
lore
#0 lore raw

cover led: drivers bug fixes

Here are some bug fixes for the LED drivers leds-ns2, leds-lt3593 and leds-renesas-tpu. Note that I don't have tested the patches related with the two lasts. I don't have the hardware.

Regards,

Simon

Simon Guinot (4):
leds: leds-ns2: fix oops at module removal
leds: leds-ns2: fix devm_gpio_request_one() flags parameter
leds: leds-lt3593: fix devm_gpio_request_one() flags parameter
leds: renesas: fix devm_gpio_request_one() flags parameter

 drivers/leds/leds-lt3593.c      |    5 +++--
 drivers/leds/leds-ns2.c         |   44 ++++++++++++++++++++++++++-------------
 drivers/leds/leds-renesas-tpu.c |    3 ++-
 3 files changed, 34 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/4 leds: leds-ns2: fix oops at module removal

This patch fixes a regression introduced by commit 72052fcc10 ("leds: leds-ns2: add device tree binding").

When the driver is initialized with device tree data, platform_data pointer is NULL. This causes a kernel oops at removal.

To fix this bug, num_leds is moved into driver_data and platform_data is not longer used from ns2_led_remove().

---
 drivers/leds/leds-ns2.c |   38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
drivers/leds/leds-ns2.c +25 -13
index d978171..81af8e9 100644
@@ -306,10 +306,21 @@ static const struct of_device_id of_ns2_leds_match[] = {
 };
 #endif /* CONFIG_OF_GPIO */
 
+struct ns2_led_priv {
+	int num_leds;
+	struct ns2_led_data leds_data[];
+};
+
+static inline int sizeof_ns2_led_priv(int num_leds)
+{
+	return sizeof(struct ns2_led_priv) +
+		      (sizeof(struct ns2_led_data) * num_leds);
+}
+
 static int ns2_led_probe(struct platform_device *pdev)
 {
 	struct ns2_led_platform_data *pdata = pdev->dev.platform_data;
-	struct ns2_led_data *leds_data;
+	struct ns2_led_priv *priv;
 	int i;
 	int ret;
 
@@ -330,21 +341,23 @@ static int ns2_led_probe(struct platform_device *pdev)
 		return -EINVAL;
 #endif /* CONFIG_OF_GPIO */
 
-	leds_data = devm_kzalloc(&pdev->dev, sizeof(struct ns2_led_data) *
-				 pdata->num_leds, GFP_KERNEL);
-	if (!leds_data)
+	priv = devm_kzalloc(&pdev->dev,
+			    sizeof_ns2_led_priv(pdata->num_leds), GFP_KERNEL);
+	if (!priv)
 		return -ENOMEM;
+	priv->num_leds = pdata->num_leds;
 
-	for (i = 0; i < pdata->num_leds; i++) {
-		ret = create_ns2_led(pdev, &leds_data[i], &pdata->leds[i]);
+	for (i = 0; i < priv->num_leds; i++) {
+		ret = create_ns2_led(pdev, &priv->leds_data[i],
+				     &pdata->leds[i]);
 		if (ret < 0) {
 			for (i = i - 1; i >= 0; i--)
-				delete_ns2_led(&leds_data[i]);
+				delete_ns2_led(&priv->leds_data[i]);
 			return ret;
 		}
 	}
 
-	platform_set_drvdata(pdev, leds_data);
+	platform_set_drvdata(pdev, priv);
 
 	return 0;
 }
@@ -352,13 +365,12 @@ static int ns2_led_probe(struct platform_device *pdev)
 static int ns2_led_remove(struct platform_device *pdev)
 {
 	int i;
-	struct ns2_led_platform_data *pdata = pdev->dev.platform_data;
-	struct ns2_led_data *leds_data;
+	struct ns2_led_priv *priv;
 
-	leds_data = platform_get_drvdata(pdev);
+	priv = platform_get_drvdata(pdev);
 
-	for (i = 0; i < pdata->num_leds; i++)
-		delete_ns2_led(&leds_data[i]);
+	for (i = 0; i < priv->num_leds; i++)
+		delete_ns2_led(&priv->leds_data[i]);
 
 	platform_set_drvdata(pdev, NULL);
 
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/4 leds: leds-ns2: fix devm_gpio_request_one() flags parameter

In reply to Simon Guinot

This patch fixes a regression introduced by commit 31c3dc7488 ("leds: leds-ns2: use gpio_request_one").

gpio_request_one is called with a wrong flag value: The initial GPIO state is used to configure the direction (bit 0) instead of the value (bit 1). As a result, if the initial GPIO state is non null then the GPIO will be configured as input.

This patch fixes the issue by using the dedicated macros GPIOF_OUT_INIT_{LOW,HIGH} to configure the initial GPIO value.

---
 drivers/leds/leds-ns2.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/leds/leds-ns2.c +4 -2
index 81af8e9..70137b1 100644
@@ -193,7 +193,8 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
 	enum ns2_led_modes mode;
 
 	ret = devm_gpio_request_one(&pdev->dev, template->cmd,
-			GPIOF_DIR_OUT | gpio_get_value(template->cmd),
+			gpio_get_value(template->cmd) ?
+			GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
 			template->name);
 	if (ret) {
 		dev_err(&pdev->dev, "%s: failed to setup command GPIO\n",
@@ -202,7 +203,8 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
 	}
 
 	ret = devm_gpio_request_one(&pdev->dev, template->slow,
-			GPIOF_DIR_OUT | gpio_get_value(template->slow),
+			gpio_get_value(template->slow) ?
+			GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
 			template->name);
 	if (ret) {
 		dev_err(&pdev->dev, "%s: failed to setup slow GPIO\n",
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 2/4 leds: leds-ns2: fix devm_gpio_request_one() flags parameter

Quoted 9 lines · Simon Guinot

This patch fixes a regression introduced by commit 31c3dc7488 ("leds: leds-ns2: use gpio_request_one").

gpio_request_one is called with a wrong flag value: The initial GPIO state is used to configure the direction (bit 0) instead of the value (bit 1). As a result, if the initial GPIO state is non null then the GPIO will be configured as input.

Quoted 4 lines

This patch fixes the issue by using the dedicated macros GPIOF_OUT_INIT_{LOW,HIGH} to configure the initial GPIO value.

Hi Simon Guinot,

The same patch was already merged to Bryan's git.
Thus, this patch is not necessary.
(http://www.spinics.net/lists/linux-leds/msg00756.html)

Best regards,
Jingoo Han

Quoted 35 lines
---
 drivers/leds/leds-ns2.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/leds/leds-ns2.c +4 -3
index 81af8e9..70137b1 100644
@@ -193,7 +193,8 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
 	enum ns2_led_modes mode;
 
 	ret = devm_gpio_request_one(&pdev->dev, template->cmd,
-			GPIOF_DIR_OUT | gpio_get_value(template->cmd),
+			gpio_get_value(template->cmd) ?
+			GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
 			template->name);
 	if (ret) {
 		dev_err(&pdev->dev, "%s: failed to setup command GPIO\n",
@@ -202,7 +203,8 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
 	}
 
 	ret = devm_gpio_request_one(&pdev->dev, template->slow,
-			GPIOF_DIR_OUT | gpio_get_value(template->slow),
+			gpio_get_value(template->slow) ?
+			GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
 			template->name);
 	if (ret) {
 		dev_err(&pdev->dev, "%s: failed to setup slow GPIO\n",
--

1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

PATCH 3/4 leds: leds-lt3593: fix devm_gpio_request_one() flags parameter

In reply to Simon Guinot

This patch fixes a regression introduced by commit 507d967bc1 ("leds: leds-lt3593: use gpio_request_one").

gpio_request_one is called with a wrong flag value: The GPIO default state is used to configure the direction (bit 0) instead of the value (bit 1). As a result, if the default GPIO state is non null then the GPIO will be configured as input.

This patch fixes the issue by using the dedicated macros GPIOF_OUT_INIT_{LOW,HIGH} to configure the initial GPIO value.

---
 drivers/leds/leds-lt3593.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/leds/leds-lt3593.c +3 -2
index c9b9e1f..ca48a7d 100644
@@ -106,8 +106,9 @@ static int create_lt3593_led(const struct gpio_led *template,
 	if (!template->retain_state_suspended)
 		led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
 
-	ret = devm_gpio_request_one(parent, template->gpio,
-				    GPIOF_DIR_OUT | state, template->name);
+	ret = devm_gpio_request_one(parent, template->gpio, state ?
+				    GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
+				    template->name);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 3/4 leds: leds-lt3593: fix devm_gpio_request_one() flags parameter

Quoted 9 lines · Simon Guinot

This patch fixes a regression introduced by commit 507d967bc1 ("leds: leds-lt3593: use gpio_request_one").

gpio_request_one is called with a wrong flag value: The GPIO default state is used to configure the direction (bit 0) instead of the value (bit 1). As a result, if the default GPIO state is non null then the GPIO will be configured as input.

Quoted 4 lines

This patch fixes the issue by using the dedicated macros GPIOF_OUT_INIT_{LOW,HIGH} to configure the initial GPIO value.

Hi Simon Guinot,

The same patch was already merged to Bryan's git.
Thus, this patch is not necessary.
(http://www.spinics.net/lists/linux-leds/msg00755.html)

Best regards,
Jingoo Han

Quoted 27 lines
---
 drivers/leds/leds-lt3593.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/leds/leds-lt3593.c +3 -3
index c9b9e1f..ca48a7d 100644
@@ -106,8 +106,9 @@ static int create_lt3593_led(const struct gpio_led *template,
 	if (!template->retain_state_suspended)
 		led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
 
-	ret = devm_gpio_request_one(parent, template->gpio,
-				    GPIOF_DIR_OUT | state, template->name);
+	ret = devm_gpio_request_one(parent, template->gpio, state ?
+				    GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
+				    template->name);
 	if (ret < 0)
 		return ret;
 
--

1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

PATCH 4/4 leds: renesas: fix devm_gpio_request_one() flags parameter

In reply to Simon Guinot

This patch fixes a regression introduced by commit b0053aaa23 ("leds: renesas: use gpio_request_one").

gpio_request_one is called with a wrong flag value: The brightness is used to configure the direction (bit 0) instead of the value (bit 1).

This patch fixes the issue by using the dedicated macros GPIOF_OUT_INIT_{LOW,HIGH} to configure the initial GPIO value.

---
 drivers/leds/leds-renesas-tpu.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/leds/leds-renesas-tpu.c +2 -1
index d3c2b7e..79cca23 100644
@@ -205,7 +205,8 @@ static void r_tpu_set_pin(struct r_tpu_priv *p, enum r_tpu_pin new_state,
 		gpio_free(cfg->pin_gpio_fn);
 
 	if (new_state == R_TPU_PIN_GPIO)
-		gpio_request_one(cfg->pin_gpio, GPIOF_DIR_OUT | !!brightness,
+		gpio_request_one(cfg->pin_gpio, brightness ?
+				GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
 				cfg->name);
 
 	if (new_state == R_TPU_PIN_GPIO_FN)
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 4/4 leds: renesas: fix devm_gpio_request_one() flags parameter

Quoted 11 lines · Simon Guinot

This patch fixes a regression introduced by commit b0053aaa23 ("leds: renesas: use gpio_request_one").

gpio_request_one is called with a wrong flag value: The brightness is used to configure the direction (bit 0) instead of the value (bit 1).

This patch fixes the issue by using the dedicated macros GPIOF_OUT_INIT_{LOW,HIGH} to configure the initial GPIO value.

Hi Simon Guinot,

The same patch was already merged to Bryan's git.
Thus, this patch is not necessary.
(http://www.spinics.net/lists/linux-leds/msg00757.html)

Best regards,
Jingoo Han

Quoted 25 lines
---
 drivers/leds/leds-renesas-tpu.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/leds/leds-renesas-tpu.c +2 -2
index d3c2b7e..79cca23 100644
@@ -205,7 +205,8 @@ static void r_tpu_set_pin(struct r_tpu_priv *p, enum r_tpu_pin new_state,
 		gpio_free(cfg->pin_gpio_fn);
 
 	if (new_state == R_TPU_PIN_GPIO)
-		gpio_request_one(cfg->pin_gpio, GPIOF_DIR_OUT | !!brightness,
+		gpio_request_one(cfg->pin_gpio, brightness ?
+				GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW,
 				cfg->name);
 
 	if (new_state == R_TPU_PIN_GPIO_FN)
--

1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

cover led: drivers bug fixes

In reply to Simon Guinot
Quoted 10 lines · Simon Guinot

Here are some bug fixes for the LED drivers leds-ns2, leds-lt3593 and leds-renesas-tpu. Note that I don't have tested the patches related with the two lasts. I don't have the hardware.

Regards,

Simon

Simon Guinot (4):
leds: leds-ns2: fix oops at module removal

Thanks, I merged this patch and other 3 patches are already in my git tree.

-Bryan

Quoted 12 lines

leds: leds-ns2: fix devm_gpio_request_one() flags parameter
leds: leds-lt3593: fix devm_gpio_request_one() flags parameter
leds: renesas: fix devm_gpio_request_one() flags parameter

 drivers/leds/leds-lt3593.c      |    5 +++--
 drivers/leds/leds-ns2.c         |   44 ++++++++++++++++++++++++++-------------
 drivers/leds/leds-renesas-tpu.c |    3 ++-
 3 files changed, 34 insertions(+), 18 deletions(-)

--
1.7.10.4