[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7ae9b0c0-c84a-4c2c-b2ee-9252e9c411b0@linux.dev>
Date: Wed, 12 Nov 2025 13:45:31 +0000
From: Vadim Fedorenko <vadim.fedorenko@...ux.dev>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: Richard Cochran <richardcochran@...il.com>,
Jonathan Lemon <jonathan.lemon@...il.com>,
Andrew Lunn <andrew+netdev@...n.ch>, "David S. Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>
Subject: Re: [PATCH net-next v1 3/7] ptp: ocp: Refactor
ptp_ocp_i2c_notifier_call()
On 11/11/2025 16:52, Andy Shevchenko wrote:
> Refactor ptp_ocp_i2c_notifier_call() to avoid unneeded local variable.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> ---
> drivers/ptp/ptp_ocp.c | 21 +++++++++------------
> 1 file changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 28243fb1d78f..1dbbca4197bc 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -4872,16 +4872,6 @@ ptp_ocp_i2c_notifier_call(struct notifier_block *nb,
> {
> struct device *dev, *child = data;
> struct ptp_ocp *bp;
> - bool add;
> -
> - switch (action) {
> - case BUS_NOTIFY_ADD_DEVICE:
> - case BUS_NOTIFY_DEL_DEVICE:
> - add = action == BUS_NOTIFY_ADD_DEVICE;
> - break;
> - default:
> - return 0;
> - }
the reason we've done it is to avoid iterating over devices and do
string comparisons for actions we don't care about. We can still avoid
local variable by changing if condition later in the code, but I'm not
sure this refactor gives any benefits.
>
> if (!i2c_verify_adapter(child))
> return 0;
> @@ -4894,10 +4884,17 @@ ptp_ocp_i2c_notifier_call(struct notifier_block *nb,
>
> found:
> bp = dev_get_drvdata(dev);
> - if (add)
> +
> + switch (action) {
> + case BUS_NOTIFY_ADD_DEVICE:
> ptp_ocp_symlink(bp, child, "i2c");
> - else
> + break;
> + case BUS_NOTIFY_DEL_DEVICE:
> sysfs_remove_link(&bp->dev.kobj, "i2c");
> + break;
> + default:
> + return 0;
> + }
>
> return 0;
> }
Powered by blists - more mailing lists