public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic
@ 2023-10-16 16:10 Andy Shevchenko
  2023-10-16 16:10 ` [PATCH v1 2/6] leds: gpio: Utilise PTR_ERR_OR_ZERO() Andy Shevchenko
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-10-16 16:10 UTC (permalink / raw)
  To: Andy Shevchenko, linux-leds, linux-kernel; +Cc: Pavel Machek, Lee Jones

The of.h is used as a proxy to mod_devicetable, replace former by
latter.

The commit 2d6180147e92 ("leds: gpio: Configure per-LED pin control")
added yet another unneeded OF APIs. Replace with direct use of fwnode.

Altogether this makes driver agnostic to the firmware interface in use.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-gpio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index a6597f0f3eb4..debadb48ceda 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -11,8 +11,8 @@
 #include <linux/gpio/consumer.h>
 #include <linux/kernel.h>
 #include <linux/leds.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
-#include <linux/of.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
@@ -129,8 +129,8 @@ static int create_gpio_led(const struct gpio_led *template,
 		ret = PTR_ERR(pinctrl);
 		if (ret != -ENODEV) {
 			dev_warn(led_dat->cdev.dev,
-				 "Failed to select %pOF pinctrl: %d\n",
-				 to_of_node(fwnode), ret);
+				 "Failed to select %pfw pinctrl: %d\n",
+				 fwnode, ret);
 		} else {
 			/* pinctrl-%d not present, not an error */
 			ret = 0;
-- 
2.40.0.1.gaa8946217a0b


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

* [PATCH v1 2/6] leds: gpio: Utilise PTR_ERR_OR_ZERO()
  2023-10-16 16:10 [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Andy Shevchenko
@ 2023-10-16 16:10 ` Andy Shevchenko
  2023-10-16 16:10 ` [PATCH v1 3/6] leds: gpio: Refactor code to use devm_gpiod_get_index_optional() Andy Shevchenko
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-10-16 16:10 UTC (permalink / raw)
  To: Andy Shevchenko, linux-leds, linux-kernel; +Cc: Pavel Machek, Lee Jones

Avoid a boilerplate code by using PTR_ERR_OR_ZERO() in create_gpio_led().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-gpio.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index debadb48ceda..4071cb9eefec 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -125,16 +125,13 @@ static int create_gpio_led(const struct gpio_led *template,
 		return ret;
 
 	pinctrl = devm_pinctrl_get_select_default(led_dat->cdev.dev);
-	if (IS_ERR(pinctrl)) {
-		ret = PTR_ERR(pinctrl);
-		if (ret != -ENODEV) {
-			dev_warn(led_dat->cdev.dev,
-				 "Failed to select %pfw pinctrl: %d\n",
-				 fwnode, ret);
-		} else {
-			/* pinctrl-%d not present, not an error */
-			ret = 0;
-		}
+	ret = PTR_ERR_OR_ZERO(pinctrl);
+	/* pinctrl-%d not present, not an error */
+	if (ret == -ENODEV)
+		ret = 0;
+	if (ret) {
+		dev_warn(led_dat->cdev.dev, "Failed to select %pfw pinctrl: %d\n",
+			 fwnode, ret);
 	}
 
 	return ret;
-- 
2.40.0.1.gaa8946217a0b


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

* [PATCH v1 3/6] leds: gpio: Refactor code to use devm_gpiod_get_index_optional()
  2023-10-16 16:10 [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Andy Shevchenko
  2023-10-16 16:10 ` [PATCH v1 2/6] leds: gpio: Utilise PTR_ERR_OR_ZERO() Andy Shevchenko
@ 2023-10-16 16:10 ` Andy Shevchenko
  2023-10-16 16:10 ` [PATCH v1 4/6] leds: gpio: Move temporary variable for struct device to gpio_led_probe() Andy Shevchenko
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-10-16 16:10 UTC (permalink / raw)
  To: Andy Shevchenko, linux-leds, linux-kernel; +Cc: Pavel Machek, Lee Jones

Instead of checking for the specific error codes, replace
devm_gpiod_get_index() with devm_gpiod_get_index_optional().
In this case we just return all errors to the caller and
simply check for NULL in case if legacy GPIO is being used.
As the result the code is easier to read and maintain.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-gpio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 4071cb9eefec..7c9c6a93dfd7 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -218,13 +218,13 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx,
 	 * device, this will hit the board file, if any and get
 	 * the GPIO from there.
 	 */
-	gpiod = devm_gpiod_get_index(dev, NULL, idx, GPIOD_OUT_LOW);
-	if (!IS_ERR(gpiod)) {
+	gpiod = devm_gpiod_get_index_optional(dev, NULL, idx, GPIOD_OUT_LOW);
+	if (IS_ERR(gpiod))
+		return gpiod;
+	if (gpiod) {
 		gpiod_set_consumer_name(gpiod, template->name);
 		return gpiod;
 	}
-	if (PTR_ERR(gpiod) != -ENOENT)
-		return gpiod;
 
 	/*
 	 * This is the legacy code path for platform code that
-- 
2.40.0.1.gaa8946217a0b


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

* [PATCH v1 4/6] leds: gpio: Move temporary variable for struct device to gpio_led_probe()
  2023-10-16 16:10 [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Andy Shevchenko
  2023-10-16 16:10 ` [PATCH v1 2/6] leds: gpio: Utilise PTR_ERR_OR_ZERO() Andy Shevchenko
  2023-10-16 16:10 ` [PATCH v1 3/6] leds: gpio: Refactor code to use devm_gpiod_get_index_optional() Andy Shevchenko
@ 2023-10-16 16:10 ` Andy Shevchenko
  2023-10-16 16:10 ` [PATCH v1 5/6] leds: gpio: Remove unneeded assignment Andy Shevchenko
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-10-16 16:10 UTC (permalink / raw)
  To: Andy Shevchenko, linux-leds, linux-kernel; +Cc: Pavel Machek, Lee Jones

Use temporary variable for struct device in gpio_led_probe() in order
to make code neater.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-gpio.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 7c9c6a93dfd7..fd3f90f95fa2 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -142,9 +142,8 @@ struct gpio_leds_priv {
 	struct gpio_led_data leds[] __counted_by(num_leds);
 };
 
-static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
+static struct gpio_leds_priv *gpio_leds_create(struct device *dev)
 {
-	struct device *dev = &pdev->dev;
 	struct fwnode_handle *child;
 	struct gpio_leds_priv *priv;
 	int count, ret;
@@ -253,13 +252,13 @@ static struct gpio_desc *gpio_led_get_gpiod(struct device *dev, int idx,
 
 static int gpio_led_probe(struct platform_device *pdev)
 {
-	struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev);
+	struct device *dev = &pdev->dev;
+	struct gpio_led_platform_data *pdata = dev_get_platdata(dev);
 	struct gpio_leds_priv *priv;
 	int i, ret = 0;
 
 	if (pdata && pdata->num_leds) {
-		priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, pdata->num_leds),
-				    GFP_KERNEL);
+		priv = devm_kzalloc(dev, struct_size(priv, leds, pdata->num_leds), GFP_KERNEL);
 		if (!priv)
 			return -ENOMEM;
 
@@ -272,22 +271,20 @@ static int gpio_led_probe(struct platform_device *pdev)
 				led_dat->gpiod = template->gpiod;
 			else
 				led_dat->gpiod =
-					gpio_led_get_gpiod(&pdev->dev,
-							   i, template);
+					gpio_led_get_gpiod(dev, i, template);
 			if (IS_ERR(led_dat->gpiod)) {
-				dev_info(&pdev->dev, "Skipping unavailable LED gpio %d (%s)\n",
+				dev_info(dev, "Skipping unavailable LED gpio %d (%s)\n",
 					 template->gpio, template->name);
 				continue;
 			}
 
-			ret = create_gpio_led(template, led_dat,
-					      &pdev->dev, NULL,
+			ret = create_gpio_led(template, led_dat, dev, NULL,
 					      pdata->gpio_blink_set);
 			if (ret < 0)
 				return ret;
 		}
 	} else {
-		priv = gpio_leds_create(pdev);
+		priv = gpio_leds_create(dev);
 		if (IS_ERR(priv))
 			return PTR_ERR(priv);
 	}
-- 
2.40.0.1.gaa8946217a0b


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

* [PATCH v1 5/6] leds: gpio: Remove unneeded assignment
  2023-10-16 16:10 [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Andy Shevchenko
                   ` (2 preceding siblings ...)
  2023-10-16 16:10 ` [PATCH v1 4/6] leds: gpio: Move temporary variable for struct device to gpio_led_probe() Andy Shevchenko
@ 2023-10-16 16:10 ` Andy Shevchenko
  2023-10-16 16:10 ` [PATCH v1 6/6] leds: gpio: Update headers Andy Shevchenko
  2023-10-19 12:26 ` [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Lee Jones
  5 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-10-16 16:10 UTC (permalink / raw)
  To: Andy Shevchenko, linux-leds, linux-kernel; +Cc: Pavel Machek, Lee Jones

The initial ret is not used anywhere, drop the unneeded assignment.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index fd3f90f95fa2..d6e8298ffb3e 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -255,7 +255,7 @@ static int gpio_led_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct gpio_led_platform_data *pdata = dev_get_platdata(dev);
 	struct gpio_leds_priv *priv;
-	int i, ret = 0;
+	int i, ret;
 
 	if (pdata && pdata->num_leds) {
 		priv = devm_kzalloc(dev, struct_size(priv, leds, pdata->num_leds), GFP_KERNEL);
-- 
2.40.0.1.gaa8946217a0b


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

* [PATCH v1 6/6] leds: gpio: Update headers
  2023-10-16 16:10 [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Andy Shevchenko
                   ` (3 preceding siblings ...)
  2023-10-16 16:10 ` [PATCH v1 5/6] leds: gpio: Remove unneeded assignment Andy Shevchenko
@ 2023-10-16 16:10 ` Andy Shevchenko
  2023-10-19 12:26 ` [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Lee Jones
  5 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-10-16 16:10 UTC (permalink / raw)
  To: Andy Shevchenko, linux-leds, linux-kernel; +Cc: Pavel Machek, Lee Jones

Include headers which we are direct users of, no need
to have proxies.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/leds/leds-gpio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index d6e8298ffb3e..710c319ad312 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -6,17 +6,21 @@
  * Raphael Assenat <raph@8d.com>
  * Copyright (C) 2008 Freescale Semiconductor, Inc.
  */
+#include <linux/container_of.h>
+#include <linux/device.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/gpio/consumer.h>
-#include <linux/kernel.h>
 #include <linux/leds.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/overflow.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/slab.h>
+#include <linux/types.h>
+
 #include "leds.h"
 
 struct gpio_led_data {
-- 
2.40.0.1.gaa8946217a0b


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

* Re: [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic
  2023-10-16 16:10 [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Andy Shevchenko
                   ` (4 preceding siblings ...)
  2023-10-16 16:10 ` [PATCH v1 6/6] leds: gpio: Update headers Andy Shevchenko
@ 2023-10-19 12:26 ` Lee Jones
  5 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2023-10-19 12:26 UTC (permalink / raw)
  To: linux-leds, linux-kernel, Andy Shevchenko; +Cc: Pavel Machek, Lee Jones

On Mon, 16 Oct 2023 19:10:00 +0300, Andy Shevchenko wrote:
> The of.h is used as a proxy to mod_devicetable, replace former by
> latter.
> 
> The commit 2d6180147e92 ("leds: gpio: Configure per-LED pin control")
> added yet another unneeded OF APIs. Replace with direct use of fwnode.
> 
> Altogether this makes driver agnostic to the firmware interface in use.
> 
> [...]

Applied, thanks!

[1/6] leds: gpio: Keep driver firmware interface agnostic
      commit: 04262082e2c203e6834bf65c7a46e2eadf212c66
[2/6] leds: gpio: Utilise PTR_ERR_OR_ZERO()
      commit: 36d270892d4733439d3fd5b713ef07029aae1bf4
[3/6] leds: gpio: Refactor code to use devm_gpiod_get_index_optional()
      commit: 4c5f908c04fda867c8130087a628a1bccec3fb05
[4/6] leds: gpio: Move temporary variable for struct device to gpio_led_probe()
      commit: 087da384361247adeb894dcb38fbbec8d4d53790
[5/6] leds: gpio: Remove unneeded assignment
      commit: cdae3873bb328fbc690722b76b67f00213c92ade
[6/6] leds: gpio: Update headers
      commit: 1f313de42c4ff9b590f00d747bab25adc0cb011c

--
Lee Jones [李琼斯]


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

end of thread, other threads:[~2023-10-19 12:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-16 16:10 [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Andy Shevchenko
2023-10-16 16:10 ` [PATCH v1 2/6] leds: gpio: Utilise PTR_ERR_OR_ZERO() Andy Shevchenko
2023-10-16 16:10 ` [PATCH v1 3/6] leds: gpio: Refactor code to use devm_gpiod_get_index_optional() Andy Shevchenko
2023-10-16 16:10 ` [PATCH v1 4/6] leds: gpio: Move temporary variable for struct device to gpio_led_probe() Andy Shevchenko
2023-10-16 16:10 ` [PATCH v1 5/6] leds: gpio: Remove unneeded assignment Andy Shevchenko
2023-10-16 16:10 ` [PATCH v1 6/6] leds: gpio: Update headers Andy Shevchenko
2023-10-19 12:26 ` [PATCH v1 1/6] leds: gpio: Keep driver firmware interface agnostic Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox