* [PATCH net-next] mdio_bus: Fix PTR_ERR() usage after initialization to constant
@ 2019-01-28 13:24 YueHaibing
2019-01-28 14:36 ` Andrew Lunn
0 siblings, 1 reply; 5+ messages in thread
From: YueHaibing @ 2019-01-28 13:24 UTC (permalink / raw)
To: davem, andrew, f.fainelli, hkallweit1; +Cc: linux-kernel, netdev, YueHaibing
Fix coccinelle warning:
./drivers/net/phy/mdio_bus.c:51:5-12: ERROR: PTR_ERR applied after initialization to constant on line 44
./drivers/net/phy/mdio_bus.c:52:5-12: ERROR: PTR_ERR applied after initialization to constant on line 44
fix this by using IS_ERR before PTR_ERR
Fixes: bafbdd527d56 ("phylib: Add device reset GPIO support")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
drivers/net/phy/mdio_bus.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 3d31358..802716a 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -42,17 +42,20 @@
static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
{
struct gpio_desc *gpiod = NULL;
+ int ret;
/* Deassert the optional reset signal */
if (mdiodev->dev.of_node)
gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
"reset-gpios", 0, GPIOD_OUT_LOW,
"PHY reset");
- if (PTR_ERR(gpiod) == -ENOENT ||
- PTR_ERR(gpiod) == -ENOSYS)
- gpiod = NULL;
- else if (IS_ERR(gpiod))
- return PTR_ERR(gpiod);
+ if (IS_ERR(gpiod)) {
+ ret = PTR_ERR(gpiod);
+ if (ret == -ENOENT || ret == -ENOSYS)
+ gpiod = NULL;
+ else
+ return ret;
+ }
mdiodev->reset = gpiod;
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] mdio_bus: Fix PTR_ERR() usage after initialization to constant
2019-01-28 13:24 [PATCH net-next] mdio_bus: Fix PTR_ERR() usage after initialization to constant YueHaibing
@ 2019-01-28 14:36 ` Andrew Lunn
2019-01-29 3:30 ` YueHaibing
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2019-01-28 14:36 UTC (permalink / raw)
To: YueHaibing; +Cc: davem, f.fainelli, hkallweit1, linux-kernel, netdev
On Mon, Jan 28, 2019 at 09:24:09PM +0800, YueHaibing wrote:
> Fix coccinelle warning:
>
> ./drivers/net/phy/mdio_bus.c:51:5-12: ERROR: PTR_ERR applied after initialization to constant on line 44
> ./drivers/net/phy/mdio_bus.c:52:5-12: ERROR: PTR_ERR applied after initialization to constant on line 44
>
> fix this by using IS_ERR before PTR_ERR
>
> Fixes: bafbdd527d56 ("phylib: Add device reset GPIO support")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
> drivers/net/phy/mdio_bus.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 3d31358..802716a 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -42,17 +42,20 @@
> static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
> {
> struct gpio_desc *gpiod = NULL;
> + int ret;
>
Hi YueHaibing
I think i prefer the simpler fix:
static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
{
- struct gpio_desc *gpiod = NULL;
+ struct gpio_desc *gpiod = ERR_PTR(-ENOENT);
Totally untested...
Andrew
> /* Deassert the optional reset signal */
> if (mdiodev->dev.of_node)
> gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
> "reset-gpios", 0, GPIOD_OUT_LOW,
> "PHY reset");
> - if (PTR_ERR(gpiod) == -ENOENT ||
> - PTR_ERR(gpiod) == -ENOSYS)
> - gpiod = NULL;
> - else if (IS_ERR(gpiod))
> - return PTR_ERR(gpiod);
> + if (IS_ERR(gpiod)) {
> + ret = PTR_ERR(gpiod);
> + if (ret == -ENOENT || ret == -ENOSYS)
> + gpiod = NULL;
> + else
> + return ret;
> + }
>
> mdiodev->reset = gpiod;
>
> --
> 2.7.4
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] mdio_bus: Fix PTR_ERR() usage after initialization to constant
2019-01-28 14:36 ` Andrew Lunn
@ 2019-01-29 3:30 ` YueHaibing
2019-02-01 4:24 ` Al Viro
0 siblings, 1 reply; 5+ messages in thread
From: YueHaibing @ 2019-01-29 3:30 UTC (permalink / raw)
To: Andrew Lunn; +Cc: davem, f.fainelli, hkallweit1, linux-kernel, netdev
On 2019/1/28 22:36, Andrew Lunn wrote:
> On Mon, Jan 28, 2019 at 09:24:09PM +0800, YueHaibing wrote:
>> Fix coccinelle warning:
>>
>> ./drivers/net/phy/mdio_bus.c:51:5-12: ERROR: PTR_ERR applied after initialization to constant on line 44
>> ./drivers/net/phy/mdio_bus.c:52:5-12: ERROR: PTR_ERR applied after initialization to constant on line 44
>>
>> fix this by using IS_ERR before PTR_ERR
>>
>> Fixes: bafbdd527d56 ("phylib: Add device reset GPIO support")
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>> ---
>> drivers/net/phy/mdio_bus.c | 13 ++++++++-----
>> 1 file changed, 8 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
>> index 3d31358..802716a 100644
>> --- a/drivers/net/phy/mdio_bus.c
>> +++ b/drivers/net/phy/mdio_bus.c
>> @@ -42,17 +42,20 @@
>> static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
>> {
>> struct gpio_desc *gpiod = NULL;
>> + int ret;
>>
>
> Hi YueHaibing
>
> I think i prefer the simpler fix:
>
> static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
> {
> - struct gpio_desc *gpiod = NULL;
> + struct gpio_desc *gpiod = ERR_PTR(-ENOENT);
>
But a56c69803f5a ("net: phy: Handle not having GPIO enabled in the kernel")
add a new check:
@@ -56,7 +56,8 @@ static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
"reset-gpios", 0, GPIOD_OUT_LOW,
"PHY reset");
- if (PTR_ERR(gpiod) == -ENOENT)
+ if (PTR_ERR(gpiod) == -ENOENT ||
+ PTR_ERR(gpiod) == -ENOSYS)
gpiod = NULL;
else if (IS_ERR(gpiod))
return PTR_ERR(gpiod);
> Totally untested...
>
> Andrew
>
>> /* Deassert the optional reset signal */
>> if (mdiodev->dev.of_node)
>> gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
>> "reset-gpios", 0, GPIOD_OUT_LOW,
>> "PHY reset");
>> - if (PTR_ERR(gpiod) == -ENOENT ||
>> - PTR_ERR(gpiod) == -ENOSYS)
>> - gpiod = NULL;
>> - else if (IS_ERR(gpiod))
>> - return PTR_ERR(gpiod);
>> + if (IS_ERR(gpiod)) {
>> + ret = PTR_ERR(gpiod);
>> + if (ret == -ENOENT || ret == -ENOSYS)
>> + gpiod = NULL;
>> + else
>> + return ret;
>> + }
>>
>> mdiodev->reset = gpiod;
>>
>> --
>> 2.7.4
>>
>>
>
> .
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] mdio_bus: Fix PTR_ERR() usage after initialization to constant
2019-01-29 3:30 ` YueHaibing
@ 2019-02-01 4:24 ` Al Viro
2019-02-16 2:40 ` YueHaibing
0 siblings, 1 reply; 5+ messages in thread
From: Al Viro @ 2019-02-01 4:24 UTC (permalink / raw)
To: YueHaibing
Cc: Andrew Lunn, davem, f.fainelli, hkallweit1, linux-kernel, netdev
On Tue, Jan 29, 2019 at 11:30:27AM +0800, YueHaibing wrote:
> >> gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
> >> "reset-gpios", 0, GPIOD_OUT_LOW,
> >> "PHY reset");
> >> - if (PTR_ERR(gpiod) == -ENOENT ||
> >> - PTR_ERR(gpiod) == -ENOSYS)
> >> - gpiod = NULL;
> >> - else if (IS_ERR(gpiod))
> >> - return PTR_ERR(gpiod);
> >> + if (IS_ERR(gpiod)) {
> >> + ret = PTR_ERR(gpiod);
> >> + if (ret == -ENOENT || ret == -ENOSYS)
> >> + gpiod = NULL;
> >> + else
> >> + return ret;
> >> + }
Rule of the thumb: PTR_ERR(p) == -E... is almost always better off
as p == ERR_PTR(-E...)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] mdio_bus: Fix PTR_ERR() usage after initialization to constant
2019-02-01 4:24 ` Al Viro
@ 2019-02-16 2:40 ` YueHaibing
0 siblings, 0 replies; 5+ messages in thread
From: YueHaibing @ 2019-02-16 2:40 UTC (permalink / raw)
To: Al Viro; +Cc: Andrew Lunn, davem, f.fainelli, hkallweit1, linux-kernel, netdev
On 2019/2/1 12:24, Al Viro wrote:
> On Tue, Jan 29, 2019 at 11:30:27AM +0800, YueHaibing wrote:
>>>> gpiod = fwnode_get_named_gpiod(&mdiodev->dev.of_node->fwnode,
>>>> "reset-gpios", 0, GPIOD_OUT_LOW,
>>>> "PHY reset");
>>>> - if (PTR_ERR(gpiod) == -ENOENT ||
>>>> - PTR_ERR(gpiod) == -ENOSYS)
>>>> - gpiod = NULL;
>>>> - else if (IS_ERR(gpiod))
>>>> - return PTR_ERR(gpiod);
>>>> + if (IS_ERR(gpiod)) {
>>>> + ret = PTR_ERR(gpiod);
>>>> + if (ret == -ENOENT || ret == -ENOSYS)
>>>> + gpiod = NULL;
>>>> + else
>>>> + return ret;
>>>> + }
>
> Rule of the thumb: PTR_ERR(p) == -E... is almost always better off
> as p == ERR_PTR(-E...)
Ok, will fix it.
>
> .
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-02-16 2:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28 13:24 [PATCH net-next] mdio_bus: Fix PTR_ERR() usage after initialization to constant YueHaibing
2019-01-28 14:36 ` Andrew Lunn
2019-01-29 3:30 ` YueHaibing
2019-02-01 4:24 ` Al Viro
2019-02-16 2:40 ` YueHaibing
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.