All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dafna Hirschfeld <dafna3@gmail.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: aditya.shankar@microchip.com, ganesh.krishna@microchip.com,
	gregkh@linuxfoundation.org, outreachy-kernel@googlegroups.com
Subject: Re: [Outreachy kernel] [PATCH] staging: wilc1000: merge 'if' statements that test the same condition
Date: Sat, 24 Feb 2018 11:02:04 +0200	[thread overview]
Message-ID: <20180224090203.GA29453@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1802240859300.16912@hadrien>

On Sat, Feb 24, 2018 at 09:03:20AM +0100, Julia Lawall wrote:
> 
> 
> On Sat, 24 Feb 2018, Dafna Hirschfeld wrote:
> 
> > Merge the instructions of two 'if' statements that test the same
> > condition and move a 'memcpy' instruction related to a different variable.
> > Issue found with coccicheck.
> >
> > Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
> > ---
> >  drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> > index 621810d..f6f2c7f8 100644
> > --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> > +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> > @@ -962,15 +962,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
> >
> >  				priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
> >
> > +				memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
> >  				kfree(priv->wilc_ptk[key_index]->seq);
> 
> How about moving the memcpy up a line to be next to the kmalloc, and to be
> separated by a blank line from the kfree, which is on a different
> location.
> 
> These kmallocs should also have null tests to check for failure.  That
> could be the first patch in the series with this patch being the second
> one.  The missing null checks represent a small bug, and a bug should not
> depend on a cleanup.
> 
> julia
> 
Hi, the file has about 17 calls to kmalloc that are not tested for null.
Wouldn't it be better to fix all of them in a different patch?

Dafna
 
> >
> > -				if (params->seq_len > 0)
> > +				if (params->seq_len > 0) {
> >  					priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
> > -
> > -				memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
> > -
> > -				if (params->seq_len > 0)
> >  					memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
> > +				}
> >
> >  				priv->wilc_ptk[key_index]->cipher = params->cipher;
> >  				priv->wilc_ptk[key_index]->key_len = params->key_len;
> > --
> > 2.7.4
> >
> > --
> > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> > To post to this group, send email to outreachy-kernel@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180224074733.GA6487%40gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
> >


  reply	other threads:[~2018-02-24  9:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-24  7:47 [PATCH] staging: wilc1000: merge 'if' statements that test the same condition Dafna Hirschfeld
2018-02-24  8:03 ` [Outreachy kernel] " Julia Lawall
2018-02-24  9:02   ` Dafna Hirschfeld [this message]
2018-02-24  9:38     ` Julia Lawall
2018-02-25  6:06       ` Dafna Hirschfeld
2018-02-25  8:50         ` Julia Lawall

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=20180224090203.GA29453@gmail.com \
    --to=dafna3@gmail.com \
    --cc=aditya.shankar@microchip.com \
    --cc=ganesh.krishna@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=julia.lawall@lip6.fr \
    --cc=outreachy-kernel@googlegroups.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.