From: Paolo Abeni <pabeni@redhat.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
Alexandra Diupina <adiupina@astralinux.ru>,
Zhao Qiang <qiang.zhao@nxp.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
"David S. Miller" <davem@davemloft.net>,
"lvc-project@linuxtesting.org" <lvc-project@linuxtesting.org>
Subject: Re: [PATCH v4] drivers/net: process the result of hdlc_open() and add call of hdlc_close() in uhdlc_close()
Date: Tue, 05 Sep 2023 12:46:26 +0200 [thread overview]
Message-ID: <c1437313a3fea94a66d33f7bf97f363c77838359.camel@redhat.com> (raw)
In-Reply-To: <1005f190-8c03-bb5d-214c-c7fca9dd876b@csgroup.eu>
On Mon, 2023-09-04 at 17:03 +0000, Christophe Leroy wrote:
>
> Le 04/09/2023 à 14:31, Alexandra Diupina a écrit :
> > diff --git a/drivers/net/wan/fsl_ucc_hdlc.c b/drivers/net/wan/fsl_ucc_hdlc.c
> > index 47c2ad7a3e42..fd999dabdd39 100644
> > --- a/drivers/net/wan/fsl_ucc_hdlc.c
> > +++ b/drivers/net/wan/fsl_ucc_hdlc.c
> > @@ -34,6 +34,8 @@
> > #define TDM_PPPOHT_SLIC_MAXIN
> > #define RX_BD_ERRORS (R_CD_S | R_OV_S | R_CR_S | R_AB_S | R_NO_S | R_LG_S)
> >
> > +static int uhdlc_close(struct net_device *dev);
> > +
> > static struct ucc_tdm_info utdm_primary_info = {
> > .uf_info = {
> > .tsa = 0,
> > @@ -731,7 +733,9 @@ static int uhdlc_open(struct net_device *dev)
> > napi_enable(&priv->napi);
> > netdev_reset_queue(dev);
> > netif_start_queue(dev);
> > - hdlc_open(dev);
> > +
> > + int rc = hdlc_open(dev);
>
> Do not mix declarations and code. Please put all declaration at the top
> of the block.
>
> > + return rc == 0 ? 0 : (uhdlc_close(dev), rc);
> > }
>
> That's not easy to read.
>
> I know that's more changes, but I'd prefer something like:
>
> static int uhdlc_open(struct net_device *dev)
> {
> u32 cecr_subblock;
> hdlc_device *hdlc = dev_to_hdlc(dev);
> struct ucc_hdlc_private *priv = hdlc->priv;
> struct ucc_tdm *utdm = priv->utdm;
> int rc;
>
> if (priv->hdlc_busy != 1)
> return 0;
>
> if (request_irq(priv->ut_info->uf_info.irq,
> ucc_hdlc_irq_handler, 0, "hdlc", priv))
> return -ENODEV;
>
> cecr_subblock = ucc_fast_get_qe_cr_subblock(
> priv->ut_info->uf_info.ucc_num);
>
> qe_issue_cmd(QE_INIT_TX_RX, cecr_subblock,
> QE_CR_PROTOCOL_UNSPECIFIED, 0);
>
> ucc_fast_enable(priv->uccf, COMM_DIR_RX | COMM_DIR_TX);
>
> /* Enable the TDM port */
> if (priv->tsa)
> qe_setbits_8(&utdm->si_regs->siglmr1_h, 0x1 << utdm->tdm_port);
>
> priv->hdlc_busy = 1;
> netif_device_attach(priv->ndev);
> napi_enable(&priv->napi);
> netdev_reset_queue(dev);
> netif_start_queue(dev);
>
> rc = hdlc_open(dev);
> if (rc)
> uhdlc_close(dev);
>
> return rc;
> }
I agree the above is more readable, but I don't think the whole
refactor is not worthy for a -net fix. I think simply rewriting the
final statements as:
rc = hdlc_open(dev);
if (rc)
uhdlc_close(dev);
return rc;
would be good for -net.
> > return 0;
> > @@ -824,6 +828,8 @@ static int uhdlc_close(struct net_device *dev)
> > netdev_reset_queue(dev);
> > priv->hdlc_busy = 0;
> >
> > + hdlc_close(dev);
> > +
> > return 0;
> >
>
> And while you are looking at the correctness of this code, is it sure
> that uhdlc_open() cannot be called twice in parallele ?
> If it can be called in parallèle I think the "if (priv->hdlc_busy != 1)"
> should be replaced by something using cmpxchg()
That part is safe, ndo_open() is invoked under the rtnl lock.
The other comments are IMHO relevant, @Alexandra: please address them.
Thanks!
Paolo
next prev parent reply other threads:[~2023-09-05 10:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-25 14:31 [PATCH] fsl_ucc_hdlc: add a check of the return value from hdlc_open Alexandra Diupina
2023-08-26 6:32 ` Christophe Leroy
2023-08-28 8:27 ` [PATCH v2] " Alexandra Diupina
2023-08-28 8:37 ` Christophe Leroy
2023-08-28 12:12 ` [PATCH v3] fsl_ucc_hdlc: process the result of hold_open() Alexandra Diupina
2023-08-28 13:11 ` Christophe Leroy
2023-08-28 19:38 ` Jakub Kicinski
2023-09-01 10:48 ` Александра Дюпина
2023-09-01 11:05 ` Denis Kirjanov
2023-09-04 12:31 ` [PATCH v4] drivers/net: process the result of hdlc_open() and add call of hdlc_close() in uhdlc_close() Alexandra Diupina
2023-09-04 17:03 ` Christophe Leroy
2023-09-04 17:04 ` Christophe Leroy
2023-09-05 10:46 ` Paolo Abeni [this message]
2023-09-19 14:25 ` [PATCH v5] " Alexandra Diupina
2023-09-22 7:09 ` Christophe Leroy
2023-09-22 7:20 ` patchwork-bot+netdevbpf
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=c1437313a3fea94a66d33f7bf97f363c77838359.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=adiupina@astralinux.ru \
--cc=christophe.leroy@csgroup.eu \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lvc-project@linuxtesting.org \
--cc=netdev@vger.kernel.org \
--cc=qiang.zhao@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;
as well as URLs for NNTP newsgroup(s).