Re: [PATCH v2] Staging: zram: Fix variable dereferenced before check
On Sat, Oct 19, 2013 at 01:59:05PM -0700, Greg KH wrote: > On Sat, Oct 19, 2013 at 10:01:42PM +0530, Rashika Kheria wrote: > > This patch fixes the following Smatch warning in zram_drv.c- > > ~/git/kernels/linux/drivers/staging/zram/zram_drv.c:663 > > reset_store() warn: variable dereferenced before check 'bdev' (see line 652) > > ~/git/kernels/linux/drivers/staging/zram/zram_drv.c:899 > > destroy_device() warn: variable dereferenced before check 'zram->disk' (see > > line 896) > > > > Signed-off-by: Rashika Kheria > > zram is messy, tricky, and I hate it. Seriously, I which I had never > taken it into the staging tree... > > Anyway, I want the existing zram developers/maintainers to review this > patch before I can accept it, as I don't trust anything that is ever > done in that code, especially as I don't test it :) > > Minchan, Jiang, Nitin, what do you think of the patch below? Can I get > your ack on it so that I can apply it? Hello Greg, I will review he send v3 again if anybody doesn't review it. Hope that Jerome or someone could review because I'm in LinuxCon now and totally fail to adjust time zone. So, Please understand late reply. Thanks. > > thanks, > > greg k-h > > > --- > > > > This revision fixes the following issues of the previous revision- > > Incorrect Correction of Sparse Warning > > > > drivers/staging/zram/zram_drv.c |8 +++- > > 1 file changed, 3 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/staging/zram/zram_drv.c > > b/drivers/staging/zram/zram_drv.c > > index 2c4ed52..a74108a 100644 > > --- a/drivers/staging/zram/zram_drv.c > > +++ b/drivers/staging/zram/zram_drv.c > > @@ -660,8 +660,7 @@ static ssize_t reset_store(struct device *dev, > > return -EINVAL; > > > > /* Make sure all pending I/O is finished */ > > - if (bdev) > > - fsync_bdev(bdev); > > + fsync_bdev(bdev); > > > > zram_reset_device(zram, true); > > return len; > > @@ -893,10 +892,9 @@ out: > > > > static void destroy_device(struct zram *zram) > > { > > - sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, > > - &zram_disk_attr_group); > > - > > if (zram->disk) { > > + sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, > > + &zram_disk_attr_group); > > del_gendisk(zram->disk); > > put_disk(zram->disk); > > } > > -- > > 1.7.9.5 > > > > -- > > You received this message because you are subscribed to the Google Groups > > "opw-kernel" group. > > To unsubscribe from this group and stop receiving emails from it, send an > > email to opw-kernel+unsubscr...@googlegroups.com. > > For more options, visit https://groups.google.com/groups/opt_out. -- Kind regards, Minchan Kim ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 09/11] staging: comedi: s626: expand standardized IndxSrc values
The 'IndxSrc' value for the standardized encoder setup is currently 1 bit wide and takes one of the following values: S626_INDXSRC_HARD = 0 // index source from hardware encoder S626_INDXSRC_SOFT = 1 // index source software controlled by IndxPol However the hardware 'IndxSrcA' and 'IndxSrcB' values for the 'A' and 'B' counters are 2 bits wide. The above standardized values 0 and 1 correspond to the hardware values 0 and 2. In order to simplify conversions between the standardized values and hardware values, expand the range of standardized values to cover all four possible values. The new values are as follows: S626_INDXSRC_ENCODER = 0 // index source from hardware encoder S626_INDXSRC_DIGIN = 1// index source from digital inputs S626_INDXSRC_SOFT = 2 // index source s/w controlled by IndxPol S626_INDXSRC_DISABLED = 2 // index source disabled (Note the change in value for `S626_INDXSRC_SOFT` and the replacement of `S626_INDXSRC_HARD` with `S626_INDXSRC_ENCODER` for consistency with the `CntSrc` values.) Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten --- v2: rebase, resend --- drivers/staging/comedi/drivers/s626.c | 22 ++ drivers/staging/comedi/drivers/s626.h | 8 +--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index 3fd5447..c2837da 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -708,7 +708,6 @@ static uint16_t s626_get_mode_a(struct comedi_device *dev, /* * Populate the standardized counter setup bit fields. -* Note: IndexSrc is restricted to ENC_X or IndxPol. */ setup = /* LoadSrc = LoadSrcA. */ @@ -717,8 +716,8 @@ static uint16_t s626_get_mode_a(struct comedi_device *dev, S626_SET_STD_LATCHSRC(S626_GET_CRB_LATCHSRC(crb)) | /* IntSrc = IntSrcA. */ S626_SET_STD_INTSRC(S626_GET_CRA_INTSRC_A(cra)) | - /* IndxSrc = IndxSrcA<1>. */ - S626_SET_STD_INDXSRC(S626_GET_CRA_INDXSRC_A(cra) >> 1) | + /* IndxSrc = IndxSrcA. */ + S626_SET_STD_INDXSRC(S626_GET_CRA_INDXSRC_A(cra)) | /* IndxPol = IndxPolA. */ S626_SET_STD_INDXPOL(S626_GET_CRA_INDXPOL_A(cra)) | /* ClkEnab = ClkEnabA. */ @@ -764,7 +763,6 @@ static uint16_t s626_get_mode_b(struct comedi_device *dev, /* * Populate the standardized counter setup bit fields. -* Note: IndexSrc is restricted to ENC_X or IndxPol. */ setup = /* IntSrc = IntSrcB. */ @@ -777,8 +775,8 @@ static uint16_t s626_get_mode_b(struct comedi_device *dev, S626_SET_STD_INDXPOL(S626_GET_CRB_INDXPOL_B(crb)) | /* ClkEnab = ClkEnabB. */ S626_SET_STD_CLKENAB(S626_GET_CRB_CLKENAB_B(crb)) | - /* IndxSrc = IndxSrcB<1>. */ - S626_SET_STD_INDXSRC(S626_GET_CRA_INDXSRC_B(cra) >> 1); + /* IndxSrc = IndxSrcB. */ + S626_SET_STD_INDXSRC(S626_GET_CRA_INDXSRC_B(cra)); /* Adjust mode-dependent parameters. */ cntsrc = S626_GET_CRA_CNTSRC_B(cra); @@ -829,8 +827,8 @@ static void s626_set_mode_a(struct comedi_device *dev, /* Initialize CRA and CRB images. */ /* Preload trigger is passed through. */ cra = S626_SET_CRA_LOADSRC_A(S626_GET_STD_LOADSRC(setup)); - /* IndexSrc is restricted to ENC_X or IndxPol. */ - cra |= S626_SET_CRA_INDXSRC_A(S626_GET_STD_INDXSRC(setup) << 1); + /* IndexSrc is passed through. */ + cra |= S626_SET_CRA_INDXSRC_A(S626_GET_STD_INDXSRC(setup)); /* Reset any pending CounterA event captures. */ crb = S626_SET_CRB_INTRESETCMD(1) | S626_SET_CRB_INTRESET_A(1); @@ -874,7 +872,7 @@ static void s626_set_mode_a(struct comedi_device *dev, * Force positive index polarity if IndxSrc is software-driven only, * otherwise pass it through. */ - if (S626_GET_STD_INDXSRC(setup) == S626_INDXSRC_HARD) + if (S626_GET_STD_INDXSRC(setup) != S626_INDXSRC_SOFT) cra |= S626_SET_CRA_INDXPOL_A(S626_GET_STD_INDXPOL(setup)); /* @@ -904,8 +902,8 @@ static void s626_set_mode_b(struct comedi_device *dev, unsigned cntsrc, clkmult, clkpol; /* Initialize CRA and CRB images. */ - /* IndexSrc field is restricted to ENC_X or IndxPol. */ - cra = S626_SET_CRA_INDXSRC_B(S626_GET_STD_INDXSRC(setup) << 1); + /* IndexSrc is passed through. */ + cra = S626_SET_CRA_INDXSRC_B(S626_GET_STD_INDXSRC(setup)); /* Reset event captures and disable interrupts. */ crb = S626_SET_CRB_INTRESETCMD(1) | S626_SET_CRB_INTRESET_B(1); @@ -958,7 +956,7 @@ static void s626_set_mode_b(struct comedi_device *dev, * Force positive index polarity if Indx
[PATCH v2 08/11] staging: comedi: s626: make CRA and CRB setup conversions more readable
Use the new macros defined in "s626.h" for constructing and decomposing 'CRA', 'CRB' and standardized encoder setup values to make the conversions between standardized encoder setup values, and CRA/CRB register values easier to follow. There is some messing about with the 'IndxSrc' values which are 1-bit wide in the standardized encoder setup, and 2-bit wide in the 'CRA' and 'CRB' register values. This will be addressed by a later patch. Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten --- v2: fix possibly uninitialized `clkpol` in `s626_get_mode_b()` (spotted by Hartley Sweeten). Note: patches 01 to 07/11 already applied. --- drivers/staging/comedi/drivers/s626.c | 317 -- 1 file changed, 151 insertions(+), 166 deletions(-) diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index 92062ed..3fd5447 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -656,7 +656,7 @@ static void s626_set_latch_source(struct comedi_device *dev, { s626_debi_replace(dev, k->my_crb, ~(S626_CRBMSK_INTCTRL | S626_CRBMSK_LATCHSRC), - value << S626_CRBBIT_LATCHSRC); + S626_SET_CRB_LATCHSRC(value)); } /* @@ -678,14 +678,16 @@ static void s626_reset_cap_flags_a(struct comedi_device *dev, const struct s626_enc_info *k) { s626_debi_replace(dev, k->my_crb, ~S626_CRBMSK_INTCTRL, - S626_CRBMSK_INTRESETCMD | S626_CRBMSK_INTRESET_A); + (S626_SET_CRB_INTRESETCMD(1) | + S626_SET_CRB_INTRESET_A(1))); } static void s626_reset_cap_flags_b(struct comedi_device *dev, const struct s626_enc_info *k) { s626_debi_replace(dev, k->my_crb, ~S626_CRBMSK_INTCTRL, - S626_CRBMSK_INTRESETCMD | S626_CRBMSK_INTRESET_B); + (S626_SET_CRB_INTRESETCMD(1) | + S626_SET_CRB_INTRESET_B(1))); } /* @@ -698,6 +700,7 @@ static uint16_t s626_get_mode_a(struct comedi_device *dev, uint16_t cra; uint16_t crb; uint16_t setup; + unsigned cntsrc, clkmult, clkpol, encmode; /* Fetch CRA and CRB register images. */ cra = s626_debi_read(dev, k->my_cra); @@ -707,44 +710,41 @@ static uint16_t s626_get_mode_a(struct comedi_device *dev, * Populate the standardized counter setup bit fields. * Note: IndexSrc is restricted to ENC_X or IndxPol. */ - setup = (cra & S626_STDMSK_LOADSRC) | /* LoadSrc = LoadSrcA. */ - ((crb << (S626_STDBIT_LATCHSRC - S626_CRBBIT_LATCHSRC)) & -S626_STDMSK_LATCHSRC) |/* LatchSrc = LatchSrcA. */ - ((cra << (S626_STDBIT_INTSRC - S626_CRABIT_INTSRC_A)) & -S626_STDMSK_INTSRC) | /* IntSrc = IntSrcA. */ - ((cra << (S626_STDBIT_INDXSRC - (S626_CRABIT_INDXSRC_A + 1))) & -S626_STDMSK_INDXSRC) | /* IndxSrc = IndxSrcA<1>. */ - ((cra >> (S626_CRABIT_INDXPOL_A - S626_STDBIT_INDXPOL)) & -S626_STDMSK_INDXPOL) | /* IndxPol = IndxPolA. */ - ((crb >> (S626_CRBBIT_CLKENAB_A - S626_STDBIT_CLKENAB)) & -S626_STDMSK_CLKENAB); /* ClkEnab = ClkEnabA. */ + setup = + /* LoadSrc = LoadSrcA. */ + S626_SET_STD_LOADSRC(S626_GET_CRA_LOADSRC_A(cra)) | + /* LatchSrc = LatchSrcA. */ + S626_SET_STD_LATCHSRC(S626_GET_CRB_LATCHSRC(crb)) | + /* IntSrc = IntSrcA. */ + S626_SET_STD_INTSRC(S626_GET_CRA_INTSRC_A(cra)) | + /* IndxSrc = IndxSrcA<1>. */ + S626_SET_STD_INDXSRC(S626_GET_CRA_INDXSRC_A(cra) >> 1) | + /* IndxPol = IndxPolA. */ + S626_SET_STD_INDXPOL(S626_GET_CRA_INDXPOL_A(cra)) | + /* ClkEnab = ClkEnabA. */ + S626_SET_STD_CLKENAB(S626_GET_CRB_CLKENAB_A(crb)); /* Adjust mode-dependent parameters. */ - if (cra & (S626_CNTSRC_SYSCLK << S626_CRABIT_CNTSRC_A)) { + cntsrc = S626_GET_CRA_CNTSRC_A(cra); + if (cntsrc & S626_CNTSRC_SYSCLK) { /* Timer mode (CntSrcA<1> == 1): */ - /* Indicate Timer mode. */ - setup |= S626_ENCMODE_TIMER << S626_STDBIT_ENCMODE; + encmode = S626_ENCMODE_TIMER; /* Set ClkPol to indicate count direction (CntSrcA<0>). */ - setup |= (cra << (S626_STDBIT_CLKPOL - S626_CRABIT_CNTSRC_A)) & -S626_STDMSK_CLKPOL; + clkpol = cntsrc & 1; /* ClkMult must be 1x in Timer mode. */ - setup |= S626_MULT_X1 << S626_STDBIT_CLKMULT; + clkmult = S626_MULT_X1; } else { /* Coun
[PATCH v2 10/11] staging: comedi: s626: remove S626_BF_* macros
The `S626_BF_*` bitfield position macros are no longer used and are just a subset of the corresponding `S626_STDBIT_*` bitfield position macros. Remove them. Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten --- v2: rebase, resend --- drivers/staging/comedi/drivers/s626.h | 9 - 1 file changed, 9 deletions(-) diff --git a/drivers/staging/comedi/drivers/s626.h b/drivers/staging/comedi/drivers/s626.h index 8509537..cbd59eb 100644 --- a/drivers/staging/comedi/drivers/s626.h +++ b/drivers/staging/comedi/drivers/s626.h @@ -499,15 +499,6 @@ #define S626_CLKMULT_2X1 /* 2x clock multiplier. */ #define S626_CLKMULT_1X2 /* 1x clock multiplier. */ -/* Bit Field positions in COUNTER_SETUP structure: */ -#define S626_BF_LOADSRC9 /* Preload trigger. */ -#define S626_BF_INDXSRC7 /* Index source. */ -#define S626_BF_INDXPOL6 /* Index polarity. */ -#define S626_BF_ENCMODE4 /* Encoder mode. */ -#define S626_BF_CLKPOL 3 /* Clock polarity/count direction. */ -#define S626_BF_CLKMULT1 /* Clock multiplier. */ -#define S626_BF_CLKENAB0 /* Clock enable. */ - /* Enumerated counter clock multipliers. */ #define S626_MULT_X0 0x0003 /* Supports no multipliers; -- 1.8.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH v2 11/11] staging: comedi: s626: replace S626_MULT_X? values
Replace the use of the `S626_MULT_X1`, `S626_MULT_X2` and `S626_MULT_X4` clock multiplier values with the equivalent `S626_CLKMULT_1X`, `S626_CLKMULT_2X` and `S626_CLKMULT_4X` values to avoid duplication. Replace the use of `S626_MULT_X0` with a new macro `S626_CLKMULT_SPECIAL` (this is treated specially by the 'ClkMultA'/'ClkMultB' field of the 'CRA'/'CRB' register). Remove the now unused `S626_MULT_X?` macros. Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten --- v2: rebase, resend --- drivers/staging/comedi/drivers/s626.c | 28 ++-- drivers/staging/comedi/drivers/s626.h | 12 +--- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index c2837da..6815cfe 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -731,7 +731,7 @@ static uint16_t s626_get_mode_a(struct comedi_device *dev, /* Set ClkPol to indicate count direction (CntSrcA<0>). */ clkpol = cntsrc & 1; /* ClkMult must be 1x in Timer mode. */ - clkmult = S626_MULT_X1; + clkmult = S626_CLKMULT_1X; } else { /* Counter mode (CntSrcA<1> == 0): */ encmode = S626_ENCMODE_COUNTER; @@ -739,8 +739,8 @@ static uint16_t s626_get_mode_a(struct comedi_device *dev, clkpol = S626_GET_CRA_CLKPOL_A(cra); /* Force ClkMult to 1x if not legal, else pass through. */ clkmult = S626_GET_CRA_CLKMULT_A(cra); - if (clkmult == S626_MULT_X0) - clkmult = S626_MULT_X1; + if (clkmult == S626_CLKMULT_SPECIAL) + clkmult = S626_CLKMULT_1X; } setup |= S626_SET_STD_ENCMODE(encmode) | S626_SET_STD_CLKMULT(clkmult) | S626_SET_STD_CLKPOL(clkpol); @@ -781,18 +781,18 @@ static uint16_t s626_get_mode_b(struct comedi_device *dev, /* Adjust mode-dependent parameters. */ cntsrc = S626_GET_CRA_CNTSRC_B(cra); clkmult = S626_GET_CRB_CLKMULT_B(crb); - if (clkmult == S626_MULT_X0) { - /* Extender mode (ClkMultB == S626_MULT_X0): */ + if (clkmult == S626_CLKMULT_SPECIAL) { + /* Extender mode (ClkMultB == S626_CLKMULT_SPECIAL): */ encmode = S626_ENCMODE_EXTENDER; /* Indicate multiplier is 1x. */ - clkmult = S626_MULT_X1; + clkmult = S626_CLKMULT_1X; /* Set ClkPol equal to Timer count direction (CntSrcB<0>). */ clkpol = cntsrc & 1; } else if (cntsrc & S626_CNTSRC_SYSCLK) { /* Timer mode (CntSrcB<1> == 1): */ encmode = S626_ENCMODE_TIMER; /* Indicate multiplier is 1x. */ - clkmult = S626_MULT_X1; + clkmult = S626_CLKMULT_1X; /* Set ClkPol equal to Timer count direction (CntSrcB<0>). */ clkpol = cntsrc & 1; } else { @@ -853,7 +853,7 @@ static void s626_set_mode_a(struct comedi_device *dev, /* ClkPolA behaves as always-on clock enable. */ clkpol = 1; /* ClkMult must be 1x. */ - clkmult = S626_MULT_X1; + clkmult = S626_CLKMULT_1X; break; default:/* Counter Mode: */ /* Select ENC_C and ENC_D as clock/direction inputs. */ @@ -861,8 +861,8 @@ static void s626_set_mode_a(struct comedi_device *dev, /* Clock polarity is passed through. */ /* Force multiplier to x1 if not legal, else pass through. */ clkmult = S626_GET_STD_CLKMULT(setup); - if (clkmult == S626_MULT_X0) - clkmult = S626_MULT_X1; + if (clkmult == S626_CLKMULT_SPECIAL) + clkmult = S626_CLKMULT_1X; break; } cra |= S626_SET_CRA_CNTSRC_A(cntsrc) | S626_SET_CRA_CLKPOL_A(clkpol) | @@ -927,7 +927,7 @@ static void s626_set_mode_b(struct comedi_device *dev, /* ClkPolB behaves as always-on clock enable. */ clkpol = 1; /* ClkMultB must be 1x. */ - clkmult = S626_MULT_X1; + clkmult = S626_CLKMULT_1X; break; case S626_ENCMODE_EXTENDER: /* Extender Mode: */ /* CntSrcB source is OverflowA (same as "timer") */ @@ -937,7 +937,7 @@ static void s626_set_mode_b(struct comedi_device *dev, /* ClkPolB controls IndexB -- always set to active. */ clkpol = 1; /* ClkMultB selects OverflowA as the clock source. */ - clkmult = S626_MULT_X0; + clkmult = S626_CLKMULT_SPECIAL; break; default:/* Counter Mode: */ /* Select ENC_C and ENC_
[PATCH v3] Staging: zram: Fix variable dereferenced before check
This patch fixes the following Smatch warning in zram_drv.c- drivers/staging/zram/zram_drv.c:663 reset_store() warn: variable dereferenced before check 'bdev' (see line 652) drivers/staging/zram/zram_drv.c:899 destroy_device() warn: variable dereferenced before check 'zram->disk' (see line 896) Signed-off-by: Rashika Kheria --- This revision fixes the following issues of the previous revision- Not included null check drivers/staging/zram/zram_drv.c | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index 2c4ed52..5594d5b 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c @@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram = dev_to_zram(dev); bdev = bdget_disk(zram->disk, 0); + if (!bdev) + return -EBUSY; + /* Do not reset an active device! */ if (bdev->bd_holders) return -EBUSY; @@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev, return -EINVAL; /* Make sure all pending I/O is finished */ - if (bdev) - fsync_bdev(bdev); + fsync_bdev(bdev); zram_reset_device(zram, true); return len; @@ -893,10 +895,9 @@ out: static void destroy_device(struct zram *zram) { - sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, - &zram_disk_attr_group); - if (zram->disk) { + sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, + &zram_disk_attr_group); del_gendisk(zram->disk); put_disk(zram->disk); } -- 1.7.9.5 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH] staging: comedi: adl_pci9118: fix a misaligned comment
As pointed out by Hartley Sweeten, one of my recent patches resulted in the start of a multi-line comment ending up misaligned. Fix it. Signed-off-by: Ian Abbott --- drivers/staging/comedi/drivers/adl_pci9118.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c index 0f2e859..9864896 100644 --- a/drivers/staging/comedi/drivers/adl_pci9118.c +++ b/drivers/staging/comedi/drivers/adl_pci9118.c @@ -356,7 +356,7 @@ struct pci9118_private { unsigned int ai_scans; /* number of scans to do */ char dma_doublebuf; /* we can use double buffering */ unsigned int dma_actbuf;/* which buffer is used now */ - unsigned short *dmabuf_virt[2]; /* + unsigned short *dmabuf_virt[2]; /* * pointers to begin of * DMA buffer */ -- 1.8.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH v3] Staging: zram: Fix variable dereferenced before check
Hello, On Mon, Oct 21, 2013 at 02:52:41PM +0530, Rashika Kheria wrote: > This patch fixes the following Smatch warning in zram_drv.c- > drivers/staging/zram/zram_drv.c:663 > reset_store() warn: variable dereferenced before check 'bdev' (see line 652) > drivers/staging/zram/zram_drv.c:899 > destroy_device() warn: variable dereferenced before check 'zram->disk' (see > line 896) > > Signed-off-by: Rashika Kheria > --- > > This revision fixes the following issues of the previous revision- > Not included null check > > drivers/staging/zram/zram_drv.c | 11 ++- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c > index 2c4ed52..5594d5b 100644 > --- a/drivers/staging/zram/zram_drv.c > +++ b/drivers/staging/zram/zram_drv.c > @@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, > zram = dev_to_zram(dev); > bdev = bdget_disk(zram->disk, 0); > > + if (!bdev) > + return -EBUSY; > + I'm not an expert on sysfs and block so it's hard to understand when we could see NULL bdev in reset handler. I hope others could answer it. Another thing, when I review the code, I found it has a bug. reset_store doesn't put refcount by getting one by bdget_disk. It should be fixed, I think. > /* Do not reset an active device! */ > if (bdev->bd_holders) > return -EBUSY; > @@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev, > return -EINVAL; > > /* Make sure all pending I/O is finished */ > - if (bdev) > - fsync_bdev(bdev); > + fsync_bdev(bdev); > > zram_reset_device(zram, true); > return len; > @@ -893,10 +895,9 @@ out: > > static void destroy_device(struct zram *zram) > { > - sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, > - &zram_disk_attr_group); > - > if (zram->disk) { > + sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, > + &zram_disk_attr_group); Is it really necessary to check zram->disk and zram->queue in this function? As I see code roughly, it seems to be not necessary but need double check. If so, please remove the check code. > del_gendisk(zram->disk); > put_disk(zram->disk); > } > -- > 1.7.9.5 > -- Kind regards, Minchan Kim ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 2/3] staging: lustre: Remove typedef and update cfs_hash_bd struct
Remove typedef keyword and rename the cfs_hash_bd_t struct to cfs_hash_bd in libcfs_hash.h. These changes resolve the "Do not add new typedefs" warning generated by checkpatch.pl and meet kernel coding style. Struct variables in other header and source files that depend on libcfs_hash.h are updated as well. Signed-off-by: Lisa Nguyen --- .../lustre/include/linux/libcfs/libcfs_hash.h | 76 +++--- drivers/staging/lustre/lustre/include/lu_object.h | 2 +- drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 4 +- drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 4 +- drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 18 ++-- drivers/staging/lustre/lustre/libcfs/hash.c| 114 ++--- drivers/staging/lustre/lustre/llite/vvp_dev.c | 2 +- .../lustre/lustre/obdclass/lprocfs_status.c| 4 +- drivers/staging/lustre/lustre/obdclass/lu_object.c | 24 ++--- 9 files changed, 124 insertions(+), 124 deletions(-) diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h index 26c10d9..61e4fca 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h @@ -109,10 +109,10 @@ struct cfs_hash_bucket { /** * cfs_hash bucket descriptor, it's normally in stack of caller */ -typedef struct cfs_hash_bd { +struct cfs_hash_bd { struct cfs_hash_bucket *bd_bucket; /**< address of bucket */ unsigned intbd_offset; /**< offset in bucket */ -} cfs_hash_bd_t; +}; #define CFS_HASH_NAME_LEN 16 /**< default name length */ #define CFS_HASH_BIGNAME_LEN 64 /**< bigname for param tree */ @@ -287,15 +287,15 @@ typedef struct cfs_hash_lock_ops { typedef struct cfs_hash_hlist_ops { /** return hlist_head of hash-head of @bd */ - struct hlist_head *(*hop_hhead)(cfs_hash_t *hs, cfs_hash_bd_t *bd); + struct hlist_head *(*hop_hhead)(cfs_hash_t *hs, struct cfs_hash_bd *bd); /** return hash-head size */ int (*hop_hhead_size)(cfs_hash_t *hs); /** add @hnode to hash-head of @bd */ int (*hop_hnode_add)(cfs_hash_t *hs, -cfs_hash_bd_t *bd, struct hlist_node *hnode); +struct cfs_hash_bd *bd, struct hlist_node *hnode); /** remove @hnode from hash-head of @bd */ int (*hop_hnode_del)(cfs_hash_t *hs, -cfs_hash_bd_t *bd, struct hlist_node *hnode); +struct cfs_hash_bd *bd, struct hlist_node *hnode); } cfs_hash_hlist_ops_t; typedef struct cfs_hash_ops { @@ -539,13 +539,13 @@ static inline int cfs_hash_dec_and_lock(cfs_hash_t *hs, } static inline void cfs_hash_bd_lock(cfs_hash_t *hs, - cfs_hash_bd_t *bd, int excl) + struct cfs_hash_bd *bd, int excl) { hs->hs_lops->hs_bkt_lock(&bd->bd_bucket->hsb_lock, excl); } static inline void cfs_hash_bd_unlock(cfs_hash_t *hs, - cfs_hash_bd_t *bd, int excl) + struct cfs_hash_bd *bd, int excl) { hs->hs_lops->hs_bkt_unlock(&bd->bd_bucket->hsb_lock, excl); } @@ -554,56 +554,56 @@ static inline void cfs_hash_bd_unlock(cfs_hash_t *hs, * operations on cfs_hash bucket (bd: bucket descriptor), * they are normally for hash-table without rehash */ -void cfs_hash_bd_get(cfs_hash_t *hs, const void *key, cfs_hash_bd_t *bd); +void cfs_hash_bd_get(cfs_hash_t *hs, const void *key, struct cfs_hash_bd *bd); static inline void cfs_hash_bd_get_and_lock(cfs_hash_t *hs, const void *key, - cfs_hash_bd_t *bd, int excl) + struct cfs_hash_bd *bd, int excl) { cfs_hash_bd_get(hs, key, bd); cfs_hash_bd_lock(hs, bd, excl); } -static inline unsigned cfs_hash_bd_index_get(cfs_hash_t *hs, cfs_hash_bd_t *bd) +static inline unsigned cfs_hash_bd_index_get(cfs_hash_t *hs, struct cfs_hash_bd *bd) { return bd->bd_offset | (bd->bd_bucket->hsb_index << hs->hs_bkt_bits); } static inline void cfs_hash_bd_index_set(cfs_hash_t *hs, -unsigned index, cfs_hash_bd_t *bd) +unsigned index, struct cfs_hash_bd *bd) { bd->bd_bucket = hs->hs_buckets[index >> hs->hs_bkt_bits]; bd->bd_offset = index & (CFS_HASH_BKT_NHLIST(hs) - 1U); } static inline void * -cfs_hash_bd_extra_get(cfs_hash_t *hs, cfs_hash_bd_t *bd) +cfs_hash_bd_extra_get(cfs_hash_t *hs, struct cfs_hash_bd *bd) { return (void *)bd->bd_bucket + cfs_hash_bkt_size(hs) - hs->hs_extra_bytes; } static inline __u32 -cfs_hash_bd_version_get(cfs_hash_bd_t *bd) +cfs_hash_bd_version_get(struct cfs_hash_bd *bd) { /* need hold cfs_hash_bd_lock */
[PATCH 1/3] staging: lustre: Remove typedef and update cfs_debug_limit_state struct
Removed typedef keyword and rename the cfs_debug_limit_state_t struct to cfs_debug_limit_state in libcfs_debug.h. These changes resolve the "Do not add new typedefs" warning generated by checkpatch.pl and meet kernel coding style. Struct variables in other header and source files that depend on libcfs_debug.h are updated as well. Signed-off-by: Lisa Nguyen --- drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h | 8 drivers/staging/lustre/lustre/include/lustre_dlm.h | 2 +- drivers/staging/lustre/lustre/include/lustre_net.h | 2 +- drivers/staging/lustre/lustre/libcfs/tracefile.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h index e6439d1..40282b7 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h @@ -165,11 +165,11 @@ struct ptldebug_header { #define CDEBUG_DEFAULT_MAX_DELAY (cfs_time_seconds(600))/* jiffies */ #define CDEBUG_DEFAULT_MIN_DELAY ((cfs_time_seconds(1) + 1) / 2) /* jiffies */ #define CDEBUG_DEFAULT_BACKOFF 2 -typedef struct { +struct cfs_debug_limit_state { cfs_time_t cdls_next; unsigned intcdls_delay; int cdls_count; -} cfs_debug_limit_state_t; +}; struct libcfs_debug_msg_data { const char *msg_file; @@ -177,7 +177,7 @@ struct libcfs_debug_msg_data { int msg_subsys; int msg_line; int msg_mask; - cfs_debug_limit_state_t *msg_cdls; + struct cfs_debug_limit_state *msg_cdls; }; #define LIBCFS_DEBUG_MSG_DATA_INIT(data, mask, cdls) \ @@ -226,7 +226,7 @@ do { \ #define CDEBUG_LIMIT(mask, format, ...) \ do { \ - static cfs_debug_limit_state_t cdls;\ + static struct cfs_debug_limit_state cdls;\ \ __CDEBUG(&cdls, mask, format, ## __VA_ARGS__);\ } while (0) diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h index 7020d9c..122441f 100644 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h @@ -1083,7 +1083,7 @@ void _ldlm_lock_debug(struct ldlm_lock *lock, * Rate-limited version of lock printing function. */ #define LDLM_DEBUG_LIMIT(mask, lock, fmt, a...) do {\ - static cfs_debug_limit_state_t _ldlm_cdls; \ + static struct cfs_debug_limit_state _ldlm_cdls;\ LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, mask, &_ldlm_cdls); \ ldlm_lock_debug(&msgdata, mask, &_ldlm_cdls, lock, "### " fmt , ##a);\ } while (0) diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h index e947002..cf2b90d 100644 --- a/drivers/staging/lustre/lustre/include/lustre_net.h +++ b/drivers/staging/lustre/lustre/include/lustre_net.h @@ -2206,7 +2206,7 @@ do { \ #define DEBUG_REQ(level, req, fmt, args...) \ do { \ if ((level) & (D_ERROR | D_WARNING)) { \ - static cfs_debug_limit_state_t cdls; \ + static struct cfs_debug_limit_state cdls; \ LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, &cdls); \ debug_req(&msgdata, level, &cdls, req, "@@@ "fmt" ", ## args);\ } else { \ diff --git a/drivers/staging/lustre/lustre/libcfs/tracefile.c b/drivers/staging/lustre/lustre/libcfs/tracefile.c index 357f400..f71a3cc 100644 --- a/drivers/staging/lustre/lustre/libcfs/tracefile.c +++ b/drivers/staging/lustre/lustre/libcfs/tracefile.c @@ -276,7 +276,7 @@ int libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata, int remain; int mask = msgdata->msg_mask; const char *file = kbasename(msgdata->msg_file); - cfs_debug_limit_state_t *cdls = msgdata->msg_cdls; + struct cfs_debug_limit_state *cdls = msgdata->msg_cdls; tcd = cfs_trace_get_tcd(); -- 1.8.1.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH V2] staging: r8188eu: Set device type to wlan
The latest version of NetworkManager does not recognize the device as wireless without this change. Signed-off-by: Larry Finger Cc: Stable a [3.12+] --- drivers/staging/rtl8188eu/os_dep/os_intfs.c | 5 + 1 file changed, 5 insertions(+) diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c b/drivers/staging/rtl8188eu/os_dep/os_intfs.c index da9f0d5..17659bb 100644 --- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c +++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c @@ -707,6 +707,10 @@ int rtw_init_netdev_name(struct net_device *pnetdev, const char *ifname) return 0; } +static const struct device_type wlan_type = { + .name = "wlan", +}; + struct net_device *rtw_init_netdev(struct adapter *old_padapter) { struct adapter *padapter; @@ -722,6 +726,7 @@ struct net_device *rtw_init_netdev(struct adapter *old_padapter) if (!pnetdev) return NULL; + pnetdev->dev.type = &wlan_type; padapter = rtw_netdev_priv(pnetdev); padapter->pnetdev = pnetdev; DBG_88E("register rtw_netdev_ops to netdev_ops\n"); -- 1.8.4 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 2/3] staging: lustre: lnet: Remove unnecessary () from return statements
Remove unnecessary parentheses from return statements in lib-lnet.h to meet kernel coding style. Signed-off-by: Lisa Nguyen --- drivers/staging/lustre/include/linux/lnet/lib-lnet.h | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h index 8869f10..0eb2e06 100644 --- a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h +++ b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h @@ -199,11 +199,11 @@ lnet_freelist_alloc(lnet_freelist_t *fl) lnet_freeobj_t *o; if (list_empty(&fl->fl_list)) - return (NULL); + return NULL; o = list_entry(fl->fl_list.next, lnet_freeobj_t, fo_list); list_del(&o->fo_list); - return ((void *)&o->fo_contents); + return (void *)&o->fo_contents; } static inline void @@ -369,7 +369,7 @@ lnet_eq_alloc(void) lnet_eq_t *eq; LIBCFS_ALLOC(eq, sizeof(*eq)); - return (eq); + return eq; } static inline void @@ -405,7 +405,7 @@ lnet_md_alloc(lnet_md_t *umd) INIT_LIST_HEAD(&md->md_list); } - return (md); + return md; } static inline void @@ -429,7 +429,7 @@ lnet_me_alloc(void) lnet_me_t *me; LIBCFS_ALLOC(me, sizeof(*me)); - return (me); + return me; } static inline void @@ -448,7 +448,7 @@ lnet_msg_alloc(void) LIBCFS_ALLOC(msg, sizeof(*msg)); /* no need to zero, LIBCFS_ALLOC does for us */ - return (msg); + return msg; } static inline void -- 1.8.1.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH 1/3] staging: lustre: lnet: Remove unnecessary spaces in lib-lnet.h
Remove spaces between function names and open parentheses to meet kernel coding style and eliminate extra space warnings generated by checkpatch.pl Signed-off-by: Lisa Nguyen --- .../staging/lustre/include/linux/lnet/lib-lnet.h | 78 +++--- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h index 59bff0b..8869f10 100644 --- a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h +++ b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h @@ -79,20 +79,20 @@ extern lnet_t the_lnet;/* THE network */ /** exclusive lock */ #define LNET_LOCK_EX CFS_PERCPT_LOCK_EX -static inline int lnet_is_wire_handle_none (lnet_handle_wire_t *wh) +static inline int lnet_is_wire_handle_none(lnet_handle_wire_t *wh) { return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE && wh->wh_object_cookie == LNET_WIRE_HANDLE_COOKIE_NONE); } -static inline int lnet_md_exhausted (lnet_libmd_t *md) +static inline int lnet_md_exhausted(lnet_libmd_t *md) { return (md->md_threshold == 0 || ((md->md_options & LNET_MD_MAX_SIZE) != 0 && md->md_offset + md->md_max_size > md->md_length)); } -static inline int lnet_md_unlinkable (lnet_libmd_t *md) +static inline int lnet_md_unlinkable(lnet_libmd_t *md) { /* Should unlink md when its refcount is 0 and either: * - md has been flagged for deletion (by auto unlink or LNetM[DE]Unlink, @@ -193,31 +193,31 @@ int lnet_freelist_init(lnet_freelist_t *fl, int n, int size); void lnet_freelist_fini(lnet_freelist_t *fl); static inline void * -lnet_freelist_alloc (lnet_freelist_t *fl) +lnet_freelist_alloc(lnet_freelist_t *fl) { /* ALWAYS called with liblock held */ lnet_freeobj_t *o; - if (list_empty (&fl->fl_list)) + if (list_empty(&fl->fl_list)) return (NULL); - o = list_entry (fl->fl_list.next, lnet_freeobj_t, fo_list); - list_del (&o->fo_list); + o = list_entry(fl->fl_list.next, lnet_freeobj_t, fo_list); + list_del(&o->fo_list); return ((void *)&o->fo_contents); } static inline void -lnet_freelist_free (lnet_freelist_t *fl, void *obj) +lnet_freelist_free(lnet_freelist_t *fl, void *obj) { /* ALWAYS called with liblock held */ - lnet_freeobj_t *o = list_entry (obj, lnet_freeobj_t, fo_contents); + lnet_freeobj_t *o = list_entry(obj, lnet_freeobj_t, fo_contents); - list_add (&o->fo_list, &fl->fl_list); + list_add(&o->fo_list, &fl->fl_list); } static inline lnet_eq_t * -lnet_eq_alloc (void) +lnet_eq_alloc(void) { /* NEVER called with resource lock held */ struct lnet_res_container *rec = &the_lnet.ln_eq_container; @@ -251,7 +251,7 @@ lnet_eq_free(lnet_eq_t *eq) } static inline lnet_libmd_t * -lnet_md_alloc (lnet_md_t *umd) +lnet_md_alloc(lnet_md_t *umd) { /* NEVER called with resource lock held */ struct lnet_res_container *rec = the_lnet.ln_md_containers[0]; @@ -322,7 +322,7 @@ lnet_me_free(lnet_me_t *me) } static inline lnet_msg_t * -lnet_msg_alloc (void) +lnet_msg_alloc(void) { /* NEVER called with network lock held */ struct lnet_msg_container *msc = the_lnet.ln_msg_containers[0]; @@ -353,7 +353,7 @@ lnet_msg_free_locked(lnet_msg_t *msg) } static inline void -lnet_msg_free (lnet_msg_t *msg) +lnet_msg_free(lnet_msg_t *msg) { lnet_net_lock(0); lnet_msg_free_locked(msg); @@ -363,7 +363,7 @@ lnet_msg_free (lnet_msg_t *msg) #else /* !LNET_USE_LIB_FREELIST */ static inline lnet_eq_t * -lnet_eq_alloc (void) +lnet_eq_alloc(void) { /* NEVER called with liblock held */ lnet_eq_t *eq; @@ -380,7 +380,7 @@ lnet_eq_free(lnet_eq_t *eq) } static inline lnet_libmd_t * -lnet_md_alloc (lnet_md_t *umd) +lnet_md_alloc(lnet_md_t *umd) { /* NEVER called with liblock held */ lnet_libmd_t *md; @@ -423,7 +423,7 @@ lnet_md_free(lnet_libmd_t *md) } static inline lnet_me_t * -lnet_me_alloc (void) +lnet_me_alloc(void) { /* NEVER called with liblock held */ lnet_me_t *me; @@ -479,7 +479,7 @@ lnet_res_lh_invalidate(lnet_libhandle_t *lh) } static inline void -lnet_eq2handle (lnet_handle_eq_t *handle, lnet_eq_t *eq) +lnet_eq2handle(lnet_handle_eq_t *handle, lnet_eq_t *eq) { if (eq == NULL) { LNetInvalidateHandle(handle); @@ -503,7 +503,7 @@ lnet_handle2eq(lnet_handle_eq_t *handle) } static inline void -lnet_md2handle (lnet_handle_md_t *handle, lnet_libmd_t *md) +lnet_md2handle(lnet_handle_md_t *handle, lnet_libmd_t *md) { handle->cookie = md->md_lh.lh_cookie; } @@ -544,7 +544,7 @@ lnet_wire_handle2md(lnet_handle_wire_t *wh) } static inline void -lnet_me2handle (lnet_handle_me_t *handle, lnet_me_t *me) +lnet_me2handle(lnet_handle_me_t *handle, lnet_me_t *me) {
[PATCH 3/3] staging: lustre: lnet: Reformat pointer variable in lib-lnet.h
Reformat a pointer variable in lib-lnet.h to meet kernel coding style and eliminate pointer format warning generated by checkpatch.pl Signed-off-by: Lisa Nguyen --- drivers/staging/lustre/include/linux/lnet/lib-lnet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h index 0eb2e06..bf30104 100644 --- a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h +++ b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h @@ -749,7 +749,7 @@ void lnet_msg_containers_destroy(void); int lnet_msg_containers_create(void); char *lnet_msgtyp2str(int type); -void lnet_print_hdr(lnet_hdr_t * hdr); +void lnet_print_hdr(lnet_hdr_t *hdr); int lnet_fail_nid(lnet_nid_t nid, unsigned int threshold); void lnet_counters_get(lnet_counters_t *counters); -- 1.8.1.2 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel