linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: gpio-max730x: bring gpiochip_add_data after port config
@ 2020-05-14 13:00 Rodrigo Alencar
  2020-05-22 15:02 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Rodrigo Alencar @ 2020-05-14 13:00 UTC (permalink / raw)
  To: linux-gpio
  Cc: linux-kernel, bgolaszewski, linus.walleij, Rodrigo Alencar,
	Rodrigo Alencar

gpiochip_add_data being called before might cause premature calls of
the gpiochip operations before the port_config values are initialized,
which would possibily write zeros to port gonfiguration registers,
an operation not allowed. For example, if there are gpio-hog nodes
in a device-tree, the sequence of function calls are performed

gpiochip_add_data
of_gpiochip_add
of_gpiochip_scan_gpios
of_gpiochip_add_hog
gpiod_hog
gpiochip_request_own_desc
gpiod_configure_flags
gpiod_direction_output/gpiod_direction_input

which would call later the gpiochip operation direction_output or
direction_input prior the port_config[] initialization.

Moreover, gpiochip_get_data is replaced by the container_of macro
inside the gpiochip operations, which would allow the calling of
max7301_direction_input prior to gpiochip_add_data

Signed-off-by: Rodrigo Alencar <455.rodrigo.alencar@gmail.com>
---
 drivers/gpio/gpio-max730x.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-max730x.c b/drivers/gpio/gpio-max730x.c
index 1e1935c51096..b8c1fe20f49a 100644
--- a/drivers/gpio/gpio-max730x.c
+++ b/drivers/gpio/gpio-max730x.c
@@ -47,7 +47,7 @@
 
 static int max7301_direction_input(struct gpio_chip *chip, unsigned offset)
 {
-	struct max7301 *ts = gpiochip_get_data(chip);
+	struct max7301 *ts = container_of(chip, struct max7301, chip);
 	u8 *config;
 	u8 offset_bits, pin_config;
 	int ret;
@@ -89,7 +89,7 @@ static int __max7301_set(struct max7301 *ts, unsigned offset, int value)
 static int max7301_direction_output(struct gpio_chip *chip, unsigned offset,
 				    int value)
 {
-	struct max7301 *ts = gpiochip_get_data(chip);
+	struct max7301 *ts = container_of(chip, struct max7301, chip);
 	u8 *config;
 	u8 offset_bits;
 	int ret;
@@ -189,10 +189,6 @@ int __max730x_probe(struct max7301 *ts)
 	ts->chip.parent = dev;
 	ts->chip.owner = THIS_MODULE;
 
-	ret = gpiochip_add_data(&ts->chip, ts);
-	if (ret)
-		goto exit_destroy;
-
 	/*
 	 * initialize pullups according to platform data and cache the
 	 * register values for later use.
@@ -214,7 +210,9 @@ int __max730x_probe(struct max7301 *ts)
 		}
 	}
 
-	return ret;
+	ret = gpiochip_add_data(&ts->chip, ts);
+	if (!ret)
+		return ret;
 
 exit_destroy:
 	mutex_destroy(&ts->lock);
-- 
2.23.0.rc1


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

* Re: [PATCH] gpio: gpio-max730x: bring gpiochip_add_data after port config
  2020-05-14 13:00 [PATCH] gpio: gpio-max730x: bring gpiochip_add_data after port config Rodrigo Alencar
@ 2020-05-22 15:02 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2020-05-22 15:02 UTC (permalink / raw)
  To: Rodrigo Alencar; +Cc: linux-gpio, LKML, Linus Walleij, Rodrigo Alencar

czw., 14 maj 2020 o 15:00 Rodrigo Alencar
<455.rodrigo.alencar@gmail.com> napisał(a):
>
> gpiochip_add_data being called before might cause premature calls of
> the gpiochip operations before the port_config values are initialized,
> which would possibily write zeros to port gonfiguration registers,
> an operation not allowed. For example, if there are gpio-hog nodes
> in a device-tree, the sequence of function calls are performed
>
> gpiochip_add_data
> of_gpiochip_add
> of_gpiochip_scan_gpios
> of_gpiochip_add_hog
> gpiod_hog
> gpiochip_request_own_desc
> gpiod_configure_flags
> gpiod_direction_output/gpiod_direction_input
>
> which would call later the gpiochip operation direction_output or
> direction_input prior the port_config[] initialization.
>
> Moreover, gpiochip_get_data is replaced by the container_of macro
> inside the gpiochip operations, which would allow the calling of
> max7301_direction_input prior to gpiochip_add_data
>
> Signed-off-by: Rodrigo Alencar <455.rodrigo.alencar@gmail.com>

Applied with some tweaks to the commit message.

Bartosz

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

end of thread, other threads:[~2020-05-22 15:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 13:00 [PATCH] gpio: gpio-max730x: bring gpiochip_add_data after port config Rodrigo Alencar
2020-05-22 15:02 ` 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).