netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3] net: dsa: qca8k: fix illegal usage of GPIO
@ 2024-01-26 10:49 Michal Vokáč
  2024-01-26 13:17 ` Andrew Lunn
  2024-01-30  2:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Michal Vokáč @ 2024-01-26 10:49 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, Vladimir Oltean, David S. Miller
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Christian Marangi,
	Russell King (Oracle), Marek Behún, Christian Lamparter,
	netdev, linux-kernel, petr.benes, Michal Vokáč

When working with GPIO, its direction must be set either when the GPIO is
requested by gpiod_get*() or later on by one of the gpiod_direction_*()
functions. Neither of this is done here which results in undefined
behavior on some systems.

As the reset GPIO is used right after it is requested here, it makes sense
to configure it as GPIOD_OUT_HIGH right away. With that, the following
gpiod_set_value_cansleep(1) becomes redundant and can be safely
removed.

Fixes: a653f2f538f9 ("net: dsa: qca8k: introduce reset via gpio feature")
Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com>
---
Changes in v3:
- Keep line length under 80 characters for netdev changes

Changes in v2:
- Remove the now redundant gpiod_set_value_cansleep(1) call.

 drivers/net/dsa/qca/qca8k-8xxx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
index ec57d9d52072..c247ab09874c 100644
--- a/drivers/net/dsa/qca/qca8k-8xxx.c
+++ b/drivers/net/dsa/qca/qca8k-8xxx.c
@@ -2038,12 +2038,11 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
 	priv->info = of_device_get_match_data(priv->dev);
 
 	priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset",
-						   GPIOD_ASIS);
+						   GPIOD_OUT_HIGH);
 	if (IS_ERR(priv->reset_gpio))
 		return PTR_ERR(priv->reset_gpio);
 
 	if (priv->reset_gpio) {
-		gpiod_set_value_cansleep(priv->reset_gpio, 1);
 		/* The active low duration must be greater than 10 ms
 		 * and checkpatch.pl wants 20 ms.
 		 */
-- 
2.1.4


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

* Re: [PATCH net v3] net: dsa: qca8k: fix illegal usage of GPIO
  2024-01-26 10:49 [PATCH net v3] net: dsa: qca8k: fix illegal usage of GPIO Michal Vokáč
@ 2024-01-26 13:17 ` Andrew Lunn
  2024-01-30  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2024-01-26 13:17 UTC (permalink / raw)
  To: Michal Vokáč
  Cc: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Christian Marangi,
	Russell King (Oracle), Marek Behún, Christian Lamparter,
	netdev, linux-kernel, petr.benes

On Fri, Jan 26, 2024 at 11:49:35AM +0100, Michal Vokáč wrote:
> When working with GPIO, its direction must be set either when the GPIO is
> requested by gpiod_get*() or later on by one of the gpiod_direction_*()
> functions. Neither of this is done here which results in undefined
> behavior on some systems.
> 
> As the reset GPIO is used right after it is requested here, it makes sense
> to configure it as GPIOD_OUT_HIGH right away. With that, the following
> gpiod_set_value_cansleep(1) becomes redundant and can be safely
> removed.
> 
> Fixes: a653f2f538f9 ("net: dsa: qca8k: introduce reset via gpio feature")
> Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH net v3] net: dsa: qca8k: fix illegal usage of GPIO
  2024-01-26 10:49 [PATCH net v3] net: dsa: qca8k: fix illegal usage of GPIO Michal Vokáč
  2024-01-26 13:17 ` Andrew Lunn
@ 2024-01-30  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-30  2:40 UTC (permalink / raw)
  To: =?utf-8?b?TWljaGFsIFZva8OhxI0gPG1pY2hhbC52b2thY0B5c29mdC5jb20+?=
  Cc: andrew, f.fainelli, olteanv, davem, edumazet, kuba, pabeni,
	ansuelsmth, rmk+kernel, kabel, chunkeey, netdev, linux-kernel,
	petr.benes

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 26 Jan 2024 11:49:35 +0100 you wrote:
> When working with GPIO, its direction must be set either when the GPIO is
> requested by gpiod_get*() or later on by one of the gpiod_direction_*()
> functions. Neither of this is done here which results in undefined
> behavior on some systems.
> 
> As the reset GPIO is used right after it is requested here, it makes sense
> to configure it as GPIOD_OUT_HIGH right away. With that, the following
> gpiod_set_value_cansleep(1) becomes redundant and can be safely
> removed.
> 
> [...]

Here is the summary with links:
  - [net,v3] net: dsa: qca8k: fix illegal usage of GPIO
    https://git.kernel.org/netdev/net/c/c44fc98f0a8f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-01-30  2:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-26 10:49 [PATCH net v3] net: dsa: qca8k: fix illegal usage of GPIO Michal Vokáč
2024-01-26 13:17 ` Andrew Lunn
2024-01-30  2:40 ` patchwork-bot+netdevbpf

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).