linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev
@ 2024-10-09 16:29 Bartosz Golaszewski
  2024-10-09 16:29 ` [PATCH 2/2] gpio: mpc8xxx: use generic device_is_compatible() Bartosz Golaszewski
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-10-09 16:29 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Instead of repeatedly dereferencing pdev, just store the address of the
embedded struct device in a local variable and use it instead for
improved readability.

While at it: rearrange variable declarations.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpio-mpc8xxx.c | 46 +++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 685ec31db409..30f36f94ba1b 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -300,14 +300,15 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = {
 
 static int mpc8xxx_probe(struct platform_device *pdev)
 {
+	const struct mpc8xxx_gpio_devtype *devtype = NULL;
 	struct device_node *np = pdev->dev.of_node;
 	struct mpc8xxx_gpio_chip *mpc8xxx_gc;
-	struct gpio_chip	*gc;
-	const struct mpc8xxx_gpio_devtype *devtype = NULL;
+	struct device *dev = &pdev->dev;
 	struct fwnode_handle *fwnode;
+	struct gpio_chip *gc;
 	int ret;
 
-	mpc8xxx_gc = devm_kzalloc(&pdev->dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
+	mpc8xxx_gc = devm_kzalloc(dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
 	if (!mpc8xxx_gc)
 		return -ENOMEM;
 
@@ -320,32 +321,28 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 		return PTR_ERR(mpc8xxx_gc->regs);
 
 	gc = &mpc8xxx_gc->gc;
-	gc->parent = &pdev->dev;
+	gc->parent = dev;
 
-	if (device_property_read_bool(&pdev->dev, "little-endian")) {
-		ret = bgpio_init(gc, &pdev->dev, 4,
-				 mpc8xxx_gc->regs + GPIO_DAT,
-				 NULL, NULL,
-				 mpc8xxx_gc->regs + GPIO_DIR, NULL,
-				 BGPIOF_BIG_ENDIAN);
+	if (device_property_read_bool(dev, "little-endian")) {
+		ret = bgpio_init(gc, dev, 4, mpc8xxx_gc->regs + GPIO_DAT,
+				 NULL, NULL, mpc8xxx_gc->regs + GPIO_DIR,
+				 NULL, BGPIOF_BIG_ENDIAN);
 		if (ret)
 			return ret;
-		dev_dbg(&pdev->dev, "GPIO registers are LITTLE endian\n");
+		dev_dbg(dev, "GPIO registers are LITTLE endian\n");
 	} else {
-		ret = bgpio_init(gc, &pdev->dev, 4,
-				 mpc8xxx_gc->regs + GPIO_DAT,
-				 NULL, NULL,
-				 mpc8xxx_gc->regs + GPIO_DIR, NULL,
-				 BGPIOF_BIG_ENDIAN
+		ret = bgpio_init(gc, dev, 4, mpc8xxx_gc->regs + GPIO_DAT,
+				 NULL, NULL, mpc8xxx_gc->regs + GPIO_DIR,
+				 NULL, BGPIOF_BIG_ENDIAN
 				 | BGPIOF_BIG_ENDIAN_BYTE_ORDER);
 		if (ret)
 			return ret;
-		dev_dbg(&pdev->dev, "GPIO registers are BIG endian\n");
+		dev_dbg(dev, "GPIO registers are BIG endian\n");
 	}
 
 	mpc8xxx_gc->direction_output = gc->direction_output;
 
-	devtype = device_get_match_data(&pdev->dev);
+	devtype = device_get_match_data(dev);
 	if (!devtype)
 		devtype = &mpc8xxx_gpio_devtype_default;
 
@@ -370,7 +367,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 	 * associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate
 	 * the port value to the GPIO Data Register.
 	 */
-	fwnode = dev_fwnode(&pdev->dev);
+	fwnode = dev_fwnode(dev);
 	if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
 	    of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
 	    of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
@@ -381,9 +378,9 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 			gc->read_reg(mpc8xxx_gc->regs + GPIO_DIR);
 	}
 
-	ret = devm_gpiochip_add_data(&pdev->dev, gc, mpc8xxx_gc);
+	ret = devm_gpiochip_add_data(dev, gc, mpc8xxx_gc);
 	if (ret) {
-		dev_err(&pdev->dev,
+		dev_err(dev,
 			"GPIO chip registration failed with status %d\n", ret);
 		return ret;
 	}
@@ -404,18 +401,17 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 	gc->write_reg(mpc8xxx_gc->regs + GPIO_IER, 0xffffffff);
 	gc->write_reg(mpc8xxx_gc->regs + GPIO_IMR, 0);
 
-	ret = devm_request_irq(&pdev->dev, mpc8xxx_gc->irqn,
+	ret = devm_request_irq(dev, mpc8xxx_gc->irqn,
 			       mpc8xxx_gpio_irq_cascade,
 			       IRQF_NO_THREAD | IRQF_SHARED, "gpio-cascade",
 			       mpc8xxx_gc);
 	if (ret) {
-		dev_err(&pdev->dev,
-			"failed to devm_request_irq(%d), ret = %d\n",
+		dev_err(dev, "failed to devm_request_irq(%d), ret = %d\n",
 			mpc8xxx_gc->irqn, ret);
 		goto err;
 	}
 
-	device_init_wakeup(&pdev->dev, true);
+	device_init_wakeup(dev, true);
 
 	return 0;
 err:
-- 
2.43.0


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

* [PATCH 2/2] gpio: mpc8xxx: use generic device_is_compatible()
  2024-10-09 16:29 [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev Bartosz Golaszewski
@ 2024-10-09 16:29 ` Bartosz Golaszewski
  2024-10-11  7:05   ` Linus Walleij
  2024-10-11  7:05 ` [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev Linus Walleij
  2024-10-14  8:31 ` Bartosz Golaszewski
  2 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-10-09 16:29 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

This driver doesn't need to include of.h and use OF-specific interfaces.
Use generic property helpers instead.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpio-mpc8xxx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 30f36f94ba1b..2f66e24127f4 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -15,7 +15,6 @@
 #include <linux/irq.h>
 #include <linux/kernel.h>
 #include <linux/mod_devicetable.h>
-#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
@@ -301,7 +300,6 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = {
 static int mpc8xxx_probe(struct platform_device *pdev)
 {
 	const struct mpc8xxx_gpio_devtype *devtype = NULL;
-	struct device_node *np = pdev->dev.of_node;
 	struct mpc8xxx_gpio_chip *mpc8xxx_gc;
 	struct device *dev = &pdev->dev;
 	struct fwnode_handle *fwnode;
@@ -368,9 +366,9 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 	 * the port value to the GPIO Data Register.
 	 */
 	fwnode = dev_fwnode(dev);
-	if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
-	    of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
-	    of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
+	if (device_is_compatible(dev, "fsl,qoriq-gpio") ||
+	    device_is_compatible(dev, "fsl,ls1028a-gpio") ||
+	    device_is_compatible(dev, "fsl,ls1088a-gpio") ||
 	    is_acpi_node(fwnode)) {
 		gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0xffffffff);
 		/* Also, latch state of GPIOs configured as output by bootloader. */
-- 
2.43.0


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

* Re: [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev
  2024-10-09 16:29 [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev Bartosz Golaszewski
  2024-10-09 16:29 ` [PATCH 2/2] gpio: mpc8xxx: use generic device_is_compatible() Bartosz Golaszewski
@ 2024-10-11  7:05 ` Linus Walleij
  2024-10-14  8:31 ` Bartosz Golaszewski
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2024-10-11  7:05 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Wed, Oct 9, 2024 at 6:29 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Instead of repeatedly dereferencing pdev, just store the address of the
> embedded struct device in a local variable and use it instead for
> improved readability.
>
> While at it: rearrange variable declarations.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH 2/2] gpio: mpc8xxx: use generic device_is_compatible()
  2024-10-09 16:29 ` [PATCH 2/2] gpio: mpc8xxx: use generic device_is_compatible() Bartosz Golaszewski
@ 2024-10-11  7:05   ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2024-10-11  7:05 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Wed, Oct 9, 2024 at 6:29 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> This driver doesn't need to include of.h and use OF-specific interfaces.
> Use generic property helpers instead.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev
  2024-10-09 16:29 [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev Bartosz Golaszewski
  2024-10-09 16:29 ` [PATCH 2/2] gpio: mpc8xxx: use generic device_is_compatible() Bartosz Golaszewski
  2024-10-11  7:05 ` [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev Linus Walleij
@ 2024-10-14  8:31 ` Bartosz Golaszewski
  2 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-10-14  8:31 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Bartosz Golaszewski, linux-gpio, linux-kernel

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Wed, 09 Oct 2024 18:29:09 +0200, Bartosz Golaszewski wrote:
> Instead of repeatedly dereferencing pdev, just store the address of the
> embedded struct device in a local variable and use it instead for
> improved readability.
> 
> While at it: rearrange variable declarations.
> 
> 
> [...]

Applied, thanks!

[1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev
      commit: 2707a028c9b9c54a6dff22c9dcfebf3083ea095e
[2/2] gpio: mpc8xxx: use generic device_is_compatible()
      commit: a937ee6d7eba055226fba300e17ade6f65de6d93

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

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

end of thread, other threads:[~2024-10-14  8:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 16:29 [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev Bartosz Golaszewski
2024-10-09 16:29 ` [PATCH 2/2] gpio: mpc8xxx: use generic device_is_compatible() Bartosz Golaszewski
2024-10-11  7:05   ` Linus Walleij
2024-10-11  7:05 ` [PATCH 1/2] gpio: mpc8xxx: use a helper variable to store the address of pdev->dev Linus Walleij
2024-10-14  8:31 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).