From: Julia Lawall <julia.lawall@inria.fr>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Erick Karanja <karanja99erick@gmail.com>,
outreachy@lists.linux.dev, philipp.g.hortmann@gmail.com,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] staging: rtl8723bs: Initialize local variables at declaration
Date: Sat, 5 Apr 2025 04:41:37 -0400 (EDT) [thread overview]
Message-ID: <ef088d6-cec1-9758-cc0-55fb66ca952@inria.fr> (raw)
In-Reply-To: <2025040507-attest-hyphen-5dae@gregkh>
On Sat, 5 Apr 2025, Greg KH wrote:
> On Sat, Apr 05, 2025 at 06:14:49AM +0300, Erick Karanja wrote:
> > Optimize variable initialization by integrating the initialization
> > directly into the variable declaration in cases where the initialization
> > is simple and doesn't depend on other variables or complex expressions.
> > This makes the code more concise and readable.
> >
> > Signed-off-by: Erick Karanja <karanja99erick@gmail.com>
> > ---
> > .../staging/rtl8723bs/hal/rtl8723bs_xmit.c | 56 ++++++-------------
> > 1 file changed, 16 insertions(+), 40 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c b/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
> > index 5dc1c12fe03e..ebe9562a9606 100644
> > --- a/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
> > +++ b/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
> > @@ -120,13 +120,10 @@ static s32 rtl8723_dequeue_writeport(struct adapter *padapter)
> > */
> > s32 rtl8723bs_xmit_buf_handler(struct adapter *padapter)
> > {
> > - struct xmit_priv *pxmitpriv;
> > + struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
> > u8 queue_empty, queue_pending;
> > s32 ret;
> >
> > -
> > - pxmitpriv = &padapter->xmitpriv;
> > -
> > if (wait_for_completion_interruptible(&pxmitpriv->xmit_comp)) {
> > netdev_emerg(padapter->pnetdev,
> > "%s: down SdioXmitBufSema fail!\n", __func__);
> > @@ -168,10 +165,10 @@ s32 rtl8723bs_xmit_buf_handler(struct adapter *padapter)
> > */
> > static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv)
> > {
> > - s32 err, ret;
> > + s32 err = 0, ret;
> > u32 k = 0;
> > - struct hw_xmit *hwxmits, *phwxmit;
> > - u8 idx, hwentry;
> > + struct hw_xmit *hwxmits = pxmitpriv->hwxmits, *phwxmit;
> > + u8 idx, hwentry = pxmitpriv->hwxmit_entry;
>
> These lines are NOT more understandable and readable at all, sorry. You
> are mixing pre-initialized variables with not-initialized ones, making
> this harder to read and maintain over time.
>
> Which would you want to come back to in 5 years to try to understand
> what is going on?
>
> Keep it simple please.
This is another deficiency of Coccinelle. It doesn't really see the case
where there are multiple declarations on a single line, since it is
generally more valuable to be able to work on them individually.
I guess the first change above would be ok though.
julia
next prev parent reply other threads:[~2025-04-05 8:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-05 3:14 [PATCH 0/2] Simplify local variable initialization Erick Karanja
2025-04-05 3:14 ` [PATCH 1/2] staging: rtl8723bs: Optimize variable initialization in rtl8723b_hal_init.c Erick Karanja
2025-04-05 7:39 ` Greg KH
2025-04-05 8:39 ` Julia Lawall
2025-04-05 8:45 ` Julia Lawall
2025-04-05 10:22 ` Erick Karanja
2025-04-05 10:27 ` Julia Lawall
2025-04-05 10:35 ` Erick Karanja
2025-04-05 10:38 ` Julia Lawall
2025-04-05 14:19 ` Dan Carpenter
2025-04-05 14:28 ` Julia Lawall
2025-04-05 14:43 ` Erick Karanja
2025-04-06 4:11 ` Erick Karanja
2025-04-05 3:14 ` [PATCH 2/2] staging: rtl8723bs: Initialize local variables at declaration Erick Karanja
2025-04-05 7:37 ` Greg KH
2025-04-05 8:41 ` Julia Lawall [this message]
2025-04-05 14:21 ` Dan Carpenter
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=ef088d6-cec1-9758-cc0-55fb66ca952@inria.fr \
--to=julia.lawall@inria.fr \
--cc=gregkh@linuxfoundation.org \
--cc=karanja99erick@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=outreachy@lists.linux.dev \
--cc=philipp.g.hortmann@gmail.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