linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/18] Use kmemdup instead of kmalloc + memcpy
@ 2014-05-26 15:21 Benoit Taine
  2014-05-26 15:21 ` [PATCH 15/18] Drivers: media: " Benoit Taine
  2014-05-26 15:21 ` [PATCH 17/18] drx-j: " Benoit Taine
  0 siblings, 2 replies; 3+ messages in thread
From: Benoit Taine @ 2014-05-26 15:21 UTC (permalink / raw)
  To: linux-media
  Cc: benoit.taine, dri-devel, devel, netdev, linux-wireless, wcn36xx,
	linux-kernel, linux-usb, usb-storage, linux-scsi,
	DL-MPTFusionLinux, linux-input, kernel-janitors

These patches enhance kernel style usage, and allows smaller code while
preventing accidental code edits to produce overflows.

The semantic patch at scripts/coccinelle/api/memdup.cocci was used to
detect and edit this situation.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 15/18] Drivers: media: Use kmemdup instead of kmalloc + memcpy
  2014-05-26 15:21 [PATCH 0/18] Use kmemdup instead of kmalloc + memcpy Benoit Taine
@ 2014-05-26 15:21 ` Benoit Taine
  2014-05-26 15:21 ` [PATCH 17/18] drx-j: " Benoit Taine
  1 sibling, 0 replies; 3+ messages in thread
From: Benoit Taine @ 2014-05-26 15:21 UTC (permalink / raw)
  To: Guennadi Liakhovetski
  Cc: benoit.taine, Mauro Carvalho Chehab, linux-media, linux-kernel,
	kernel-janitors

This issue was reported by coccicheck using the semantic patch 
at scripts/coccinelle/api/memdup.cocci

Signed-off-by: Benoit Taine <benoit.taine@lip6.fr>
---
Tested by compilation without errors.

 drivers/media/platform/soc_camera/soc_camera.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index c8549bf..8646c11 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -1346,13 +1346,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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 17/18] drx-j: Use kmemdup instead of kmalloc + memcpy
  2014-05-26 15:21 [PATCH 0/18] Use kmemdup instead of kmalloc + memcpy Benoit Taine
  2014-05-26 15:21 ` [PATCH 15/18] Drivers: media: " Benoit Taine
@ 2014-05-26 15:21 ` Benoit Taine
  1 sibling, 0 replies; 3+ messages in thread
From: Benoit Taine @ 2014-05-26 15:21 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: benoit.taine, linux-media, linux-kernel, kernel-janitors

This issue was reported by coccicheck using the semantic patch 
at scripts/coccinelle/api/memdup.cocci

Signed-off-by: Benoit Taine <benoit.taine@lip6.fr>
---
Not compile tested.

 drivers/media/dvb-frontends/drx39xyj/drxj.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/media/dvb-frontends/drx39xyj/drxj.c b/drivers/media/dvb-frontends/drx39xyj/drxj.c
index 9482954..3795f65 100644
--- a/drivers/media/dvb-frontends/drx39xyj/drxj.c
+++ b/drivers/media/dvb-frontends/drx39xyj/drxj.c
@@ -12272,22 +12272,20 @@ struct dvb_frontend *drx39xxj_attach(struct i2c_adapter *i2c)
 	if (demod == NULL)
 		goto error;
 
-	demod_addr = kmalloc(sizeof(struct i2c_device_addr), GFP_KERNEL);
+	demod_addr = kmemdup(&drxj_default_addr_g,
+			     sizeof(struct i2c_device_addr), GFP_KERNEL);
 	if (demod_addr == NULL)
 		goto error;
-	memcpy(demod_addr, &drxj_default_addr_g,
-	       sizeof(struct i2c_device_addr));
 
-	demod_comm_attr = kmalloc(sizeof(struct drx_common_attr), GFP_KERNEL);
+	demod_comm_attr = kmemdup(&drxj_default_comm_attr_g,
+				  sizeof(struct drx_common_attr), GFP_KERNEL);
 	if (demod_comm_attr == NULL)
 		goto error;
-	memcpy(demod_comm_attr, &drxj_default_comm_attr_g,
-	       sizeof(struct drx_common_attr));
 
-	demod_ext_attr = kmalloc(sizeof(struct drxj_data), GFP_KERNEL);
+	demod_ext_attr = kmemdup(&drxj_data_g, sizeof(struct drxj_data),
+				 GFP_KERNEL);
 	if (demod_ext_attr == NULL)
 		goto error;
-	memcpy(demod_ext_attr, &drxj_data_g, sizeof(struct drxj_data));
 
 	/* setup the state */
 	state->i2c = i2c;


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-26 15:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-26 15:21 [PATCH 0/18] Use kmemdup instead of kmalloc + memcpy Benoit Taine
2014-05-26 15:21 ` [PATCH 15/18] Drivers: media: " Benoit Taine
2014-05-26 15:21 ` [PATCH 17/18] drx-j: " Benoit Taine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).