[PATCH v2] Staging: zram: Fix variable dereferenced before check

Greg KH gregkh at linuxfoundation.org
Sat Oct 19 20:59:05 UTC 2013


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 <rashika.kheria at gmail.com>

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?

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+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.


More information about the devel mailing list