2024-01-24 11:38:07

by Michal Vokáč

[permalink] [raw]
Subject: [PATCH net v2] net: dsa: qca8k: fix illegal usage of GPIO

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áč <[email protected]>
---
Changes in v2:
- Remove the now redundant gpiod_set_value_cansleep(1) call.

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

diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
index ec57d9d52072..3663de8f2617 100644
--- a/drivers/net/dsa/qca/qca8k-8xxx.c
+++ b/drivers/net/dsa/qca/qca8k-8xxx.c
@@ -2037,13 +2037,11 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
priv->dev = &mdiodev->dev;
priv->info = of_device_get_match_data(priv->dev);

- priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset",
- GPIOD_ASIS);
+ priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", 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



2024-01-25 17:10:13

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net v2] net: dsa: qca8k: fix illegal usage of GPIO

> diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
> index ec57d9d52072..3663de8f2617 100644
> --- a/drivers/net/dsa/qca/qca8k-8xxx.c
> +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
> @@ -2037,13 +2037,11 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
> priv->dev = &mdiodev->dev;
> priv->info = of_device_get_match_data(priv->dev);
>
> - priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset",
> - GPIOD_ASIS);
> + priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", GPIOD_OUT_HIGH);

Sorry, i should of pointed this out on the previous version. netdev
kept with 80 character lines. That is why what you deleted was split
over two lines, and what you add should also split at the same point.

Andrew

---
pw-bot: cr

2024-01-26 10:30:19

by Michal Vokáč

[permalink] [raw]
Subject: Re: [PATCH net v2] net: dsa: qca8k: fix illegal usage of GPIO

On 25. 01. 24 17:59, Andrew Lunn wrote:
>> diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
>> index ec57d9d52072..3663de8f2617 100644
>> --- a/drivers/net/dsa/qca/qca8k-8xxx.c
>> +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
>> @@ -2037,13 +2037,11 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
>> priv->dev = &mdiodev->dev;
>> priv->info = of_device_get_match_data(priv->dev);
>>
>> - priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset",
>> - GPIOD_ASIS);
>> + priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", GPIOD_OUT_HIGH);
>
> Sorry, i should of pointed this out on the previous version. netdev
> kept with 80 character lines. That is why what you deleted was split
> over two lines, and what you add should also split at the same point.
OK, no problem I will fix that. I did not realize, that netdev kept
that rule.

Michal