diff mbox

[03/46,media] soc_camera: use kmemdup()

Message ID b7688fe7abdac43a645e7a69748a561cf9960009.1409775488.git.m.chehab@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mauro Carvalho Chehab Sept. 3, 2014, 8:32 p.m. UTC
Instead of calling kzalloc and then copying, use kmemdup(). That
avoids zeroing the data structure before copying.

Found by coccinelle.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>

Comments

Guennadi Liakhovetski Sept. 3, 2014, 8:44 p.m. UTC | #1
Hi Mauro,

On Wed, 3 Sep 2014, Mauro Carvalho Chehab wrote:

> Instead of calling kzalloc and then copying, use kmemdup(). That
> avoids zeroing the data structure before copying.
> 
> Found by coccinelle.
> 
> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> 
> diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
> index f4308fed5431..ee8cdc95a9f9 100644
> --- a/drivers/media/platform/soc_camera/soc_camera.c
> +++ b/drivers/media/platform/soc_camera/soc_camera.c
> @@ -1347,13 +1347,11 @@ static int soc_camera_i2c_init(struct soc_camera_device *icd,
>  		return -ENODEV;
>  	}
>  
> -	ssdd = kzalloc(sizeof(*ssdd), GFP_KERNEL);
> +	ssdd = kmemdup(&sdesc->subdev_desc, sizeof(*ssdd), GFP_KERNEL);
>  	if (!ssdd) {
>  		ret = -ENOMEM;
>  		goto ealloc;
>  	}
> -
> -	memcpy(ssdd, &sdesc->subdev_desc, sizeof(*ssdd));

Hm, wow... that seems  to be a particularly silly one... Even if not 
memdup, why did I use kZalloc() to immediately overwrite it completely?.. 
Thanks for catching! This and the other two (so far) patches - would you 
like me to pull-push them or just use my

Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

for all 3 of them?

Thanks
Guennadi

>  	/*
>  	 * In synchronous case we request regulators ourselves in
>  	 * soc_camera_pdrv_probe(), make sure the subdevice driver doesn't try
> -- 
> 1.9.3
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab Sept. 3, 2014, 8:54 p.m. UTC | #2
Em Wed, 3 Sep 2014 22:44:02 +0200 (CEST)
Guennadi Liakhovetski <g.liakhovetski@gmx.de> escreveu:

> Hi Mauro,
> 
> On Wed, 3 Sep 2014, Mauro Carvalho Chehab wrote:
> 
> > Instead of calling kzalloc and then copying, use kmemdup(). That
> > avoids zeroing the data structure before copying.
> > 
> > Found by coccinelle.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> > 
> > diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
> > index f4308fed5431..ee8cdc95a9f9 100644
> > --- a/drivers/media/platform/soc_camera/soc_camera.c
> > +++ b/drivers/media/platform/soc_camera/soc_camera.c
> > @@ -1347,13 +1347,11 @@ static int soc_camera_i2c_init(struct soc_camera_device *icd,
> >  		return -ENODEV;
> >  	}
> >  
> > -	ssdd = kzalloc(sizeof(*ssdd), GFP_KERNEL);
> > +	ssdd = kmemdup(&sdesc->subdev_desc, sizeof(*ssdd), GFP_KERNEL);
> >  	if (!ssdd) {
> >  		ret = -ENOMEM;
> >  		goto ealloc;
> >  	}
> > -
> > -	memcpy(ssdd, &sdesc->subdev_desc, sizeof(*ssdd));
> 
> Hm, wow... that seems  to be a particularly silly one... Even if not 
> memdup, why did I use kZalloc() to immediately overwrite it completely?.. 

Maybe this pattern happened due to some incremental change.

> Thanks for catching! This and the other two (so far) patches - would you 
> like me to pull-push them or just use my
> 
> Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> 
> for all 3 of them?

Just the acked-by is enough.

Thanks!
Mauro

> 
> Thanks
> Guennadi
> 
> >  	/*
> >  	 * In synchronous case we request regulators ourselves in
> >  	 * soc_camera_pdrv_probe(), make sure the subdevice driver doesn't try
> > -- 
> > 1.9.3
> > 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index f4308fed5431..ee8cdc95a9f9 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -1347,13 +1347,11 @@  static int soc_camera_i2c_init(struct soc_camera_device *icd,
 		return -ENODEV;
 	}
 
-	ssdd = kzalloc(sizeof(*ssdd), GFP_KERNEL);
+	ssdd = kmemdup(&sdesc->subdev_desc, sizeof(*ssdd), GFP_KERNEL);
 	if (!ssdd) {
 		ret = -ENOMEM;
 		goto ealloc;
 	}
-
-	memcpy(ssdd, &sdesc->subdev_desc, sizeof(*ssdd));
 	/*
 	 * In synchronous case we request regulators ourselves in
 	 * soc_camera_pdrv_probe(), make sure the subdevice driver doesn't try