Re: [PATCH 21/21] staging: ks7010: init local variables when they are declared in ks7010_sdio_probe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 23, 2018 at 03:19:49PM +0200, Sergio Paracuellos wrote:
> On Mon, Apr 23, 2018 at 2:45 PM, Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
> > On Thu, Apr 19, 2018 at 07:08:15AM +0200, Sergio Paracuellos wrote:
> >> This commit change init point of two variables to forward them to
> >> init time. This variables are just being assigned some lines after
> >> and it is more clear to init them when the init value is known and
> >> in this case this is known when they are declared.
> >>
> >> Signed-off-by: Sergio Paracuellos <sergio.paracuellos@xxxxxxxxx>
> >> ---
> >>  drivers/staging/ks7010/ks7010_sdio.c | 7 ++-----
> >>  1 file changed, 2 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c
> >> index 11839af..18e2350 100644
> >> --- a/drivers/staging/ks7010/ks7010_sdio.c
> >> +++ b/drivers/staging/ks7010/ks7010_sdio.c
> >> @@ -981,14 +981,11 @@ static void ks7010_private_init(struct ks_wlan_private *priv,
> >>  static int ks7010_sdio_probe(struct sdio_func *func,
> >>                            const struct sdio_device_id *device)
> >>  {
> >> -     struct ks_wlan_private *priv;
> >> +     struct ks_wlan_private *priv = NULL;
> >> +     struct net_device *netdev = NULL;
> >>       struct ks_sdio_card *card;
> >> -     struct net_device *netdev;
> >>       int ret;
> >>
> >> -     priv = NULL;
> >> -     netdev = NULL;
> >
> > It's better if we don't initialize these at all.  There is a bug here
> > and GCC finds it when these aren't initialized to bogus values:
> >
> > drivers/staging/ks7010/ks7010_sdio.c: In function ‘ks7010_sdio_probe’:
> > drivers/staging/ks7010/ks7010_sdio.c:932:2: warning: ‘priv’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> I see... but I am not getting any warning in my tree making them
> initialized. Am I missing something?
> 

It's possible that someone fixed them.  I pulled from Greg's
staging-next and it was still buggy but I remember someone sending
patches for these.

Anyway, the point is the same either way.  Don't initialize variables if
you don't need to because it disable's GCC static analysis for
uninitialized variable bugs.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux