2023-05-11 07:22:54

by Yang Li

[permalink] [raw]
Subject: [PATCH -next] leds: trigger: netdev: NULL check before dev_{put, hold}

The call netdev_{put, hold} of dev_{put, hold} will check NULL,
so there is no need to check before using dev_{put, hold},
remove it to silence the warnings:

./drivers/leds/trigger/ledtrig-netdev.c:291:3-10: WARNING: NULL check before dev_{put, hold} functions is not needed.
./drivers/leds/trigger/ledtrig-netdev.c:401:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed.

Reported-by: Abaci Robot <[email protected]>
Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4929
Signed-off-by: Yang Li <[email protected]>
---
drivers/leds/trigger/ledtrig-netdev.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 305eb543ba84..92de22be5f1c 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -287,8 +287,7 @@ static int netdev_trig_notify(struct notifier_block *nb,
trigger_data->carrier_link_up = netif_carrier_ok(dev);
fallthrough;
case NETDEV_REGISTER:
- if (trigger_data->net_dev)
- dev_put(trigger_data->net_dev);
+ dev_put(trigger_data->net_dev);
dev_hold(dev);
trigger_data->net_dev = dev;
break;
@@ -397,8 +396,7 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev)

cancel_delayed_work_sync(&trigger_data->work);

- if (trigger_data->net_dev)
- dev_put(trigger_data->net_dev);
+ dev_put(trigger_data->net_dev);

kfree(trigger_data);
}
--
2.20.1.7.g153144c



2023-05-18 12:55:52

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH -next] leds: trigger: netdev: NULL check before dev_{put, hold}

On Thu, 11 May 2023, Yang Li wrote:

> The call netdev_{put, hold} of dev_{put, hold} will check NULL,
> so there is no need to check before using dev_{put, hold},
> remove it to silence the warnings:
>
> ./drivers/leds/trigger/ledtrig-netdev.c:291:3-10: WARNING: NULL check before dev_{put, hold} functions is not needed.
> ./drivers/leds/trigger/ledtrig-netdev.c:401:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed.
>
> Reported-by: Abaci Robot <[email protected]>
> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4929
> Signed-off-by: Yang Li <[email protected]>
> ---
> drivers/leds/trigger/ledtrig-netdev.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)

Don't forget to run checkpatch.pl before submission.

WARNING: Reported-by: should be immediately followed by Closes: with a URL to the report

Fixed and applied, thanks.

--
Lee Jones [李琼斯]