From: Andrew Lunn <andrew@lunn.ch>
To: Wei Fang <wei.fang@nxp.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, shenwei.wang@nxp.com, xiaoning.wang@nxp.com,
richardcochran@gmail.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH net-next] net: fec: Convert fec driver to use lock guards
Date: Tue, 7 May 2024 16:01:10 +0200 [thread overview]
Message-ID: <e1fa1aa5-4a40-43c5-a6ab-780667254fe9@lunn.ch> (raw)
In-Reply-To: <20240507090520.284821-1-wei.fang@nxp.com>
On Tue, May 07, 2024 at 05:05:20PM +0800, Wei Fang wrote:
> Use guard() and scoped_guard() defined in linux/cleanup.h to automate
> lock lifetime control in fec driver.
You are probably the first to use these in netdev. Or one of the very
early adopters. As such, you should explain in a bit more detail why
these changes are safe.
> - spin_lock_irqsave(&fep->tmreg_lock, flags);
> - ns = timecounter_cyc2time(&fep->tc, ts);
> - spin_unlock_irqrestore(&fep->tmreg_lock, flags);
> + scoped_guard(spinlock_irqsave, &fep->tmreg_lock) {
> + ns = timecounter_cyc2time(&fep->tc, ts);
> + }
This looks fine.
> - mutex_lock(&fep->ptp_clk_mutex);
> - ret = clk_prepare_enable(fep->clk_ptp);
> - if (ret) {
> - mutex_unlock(&fep->ptp_clk_mutex);
> - goto failed_clk_ptp;
> - } else {
> - fep->ptp_clk_on = true;
> + scoped_guard(mutex, &fep->ptp_clk_mutex) {
> + ret = clk_prepare_enable(fep->clk_ptp);
> + if (ret)
> + goto failed_clk_ptp;
> + else
> + fep->ptp_clk_on = true;
> }
As Eric pointed out, it is not obvious what the semantics are
here. You are leaving the scope, so i hope it does not matter it is a
goto you are using to leave the scope. But a quick search did not find
anything to confirm this. So i would like to see some justification in
the commit message this is safe.
> +++ b/drivers/net/ethernet/freescale/fec_ptp.c
> @@ -99,18 +99,17 @@
> */
> static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable)
> {
> - unsigned long flags;
> u32 val, tempval;
> struct timespec64 ts;
> u64 ns;
>
> - if (fep->pps_enable == enable)
> - return 0;
> -
> fep->pps_channel = DEFAULT_PPS_CHANNEL;
> fep->reload_period = PPS_OUPUT_RELOAD_PERIOD;
>
> - spin_lock_irqsave(&fep->tmreg_lock, flags);
> + guard(spinlock_irqsave)(&fep->tmreg_lock);
> +
> + if (fep->pps_enable == enable)
> + return 0;
This is not obviously correct. Why has this condition moved?
I also personally don't like guard(). scoped_guard() {} is much easier
to understand.
In order to get my Reviewed-by: you need to drop all the plain guard()
calls. I'm also not sure as a community we want to see changes like
this.
Andrew
next prev parent reply other threads:[~2024-05-07 14:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-07 9:05 Wei Fang
2024-05-07 10:39 ` Eric Dumazet
2024-05-08 2:41 ` Wei Fang
2024-05-07 11:55 ` [EXTERNAL] " Suman Ghosh
2024-05-08 2:46 ` Wei Fang
2024-05-07 14:01 ` Andrew Lunn [this message]
2024-05-08 3:29 ` Wei Fang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e1fa1aa5-4a40-43c5-a6ab-780667254fe9@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=shenwei.wang@nxp.com \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®