Skip to contentSkip to conversation

kmemdup() cleanup in drivers/acpi/

PATCH Applied Eric Sesterhenn 6 participants 21 messages Oct 23, 2006 – Nov 6, 2006

Subsystems (13)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/acpi/

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/acpi/scan.c renamed from drivers/acpi/scan.c.orig +2 -4
@@ -853,10 +853,8 @@ static void acpi_device_set_id(struct ac
 		device->flags.unique_id = 1;
 	}
 	if (cid_list) {
-		device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL);
-		if (device->pnp.cid_list)
-			memcpy(device->pnp.cid_list, cid_list, cid_list->size);
-		else
+		device->pnp.cid_list = kmemdup(cid_list, cid_list->size, GFP_KERNEL);
+		if (!device->pnp.cid_list)
 			printk(KERN_ERR "Memory allocation error\n");
 	}
 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/base

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/base/platform.c renamed from drivers/base/platform.c.orig +4 -6
@@ -192,9 +192,8 @@ int platform_device_add_resources(struct
 {
 	struct resource *r;
 
-	r = kmalloc(sizeof(struct resource) * num, GFP_KERNEL);
+	r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
 	if (r) {
-		memcpy(r, res, sizeof(struct resource) * num);
 		pdev->resource = r;
 		pdev->num_resources = num;
 	}
@@ -216,11 +215,10 @@ int platform_device_add_data(struct plat
 {
 	void *d;
 
-	d = kmalloc(size, GFP_KERNEL);
-	if (d) {
-		memcpy(d, data, size);
+	d = kmemdup(data, size, GFP_KERNEL);
+	if (d)
 		pdev->dev.platform_data = d;
-	}
+	
 	return d ? 0 : -ENOMEM;
 }
 EXPORT_SYMBOL_GPL(platform_device_add_data);

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#2 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/ieee1394

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/ieee1394/nodemgr.c renamed from drivers/ieee1394/nodemgr.c.orig +1 -2
@@ -976,10 +976,9 @@ static struct unit_directory *nodemgr_pr
 			/* Logical Unit Number */
 			if (kv->key.type = CSR1212_KV_TYPE_IMMEDIATE) {
 				if (ud->flags & UNIT_DIRECTORY_HAS_LUN) {
-					ud_child = kmalloc(sizeof(*ud_child), GFP_KERNEL);
+					ud_child = kmemdup(ud, sizeof(*ud_child), GFP_KERNEL);
 					if (!ud_child)
 						goto unit_directory_error;
-					memcpy(ud_child, ud, sizeof(*ud_child));
 					nodemgr_register_device(ne, ud_child, &ne->device);
 					ud_child = NULL;
 					
drivers/ieee1394/pcilynx.c renamed from drivers/ieee1394/pcilynx.c.orig +1 -2
@@ -1428,10 +1428,9 @@ static int __devinit add_card(struct pci
         	struct i2c_algo_bit_data i2c_adapter_data;
 
         	error = -ENOMEM;
-		i2c_ad = kmalloc(sizeof(*i2c_ad), SLAB_KERNEL);
+		i2c_ad = kmemdup(&bit_ops, sizeof(*i2c_ad), SLAB_KERNEL);
         	if (!i2c_ad) FAIL("failed to allocate I2C adapter memory");
 
-		memcpy(i2c_ad, &bit_ops, sizeof(struct i2c_adapter));
                 i2c_adapter_data = bit_data;
                 i2c_ad->algo_data = &i2c_adapter_data;
                 i2c_adapter_data.data = lynx;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#3 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/infiniband

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/infiniband/core/cm.c renamed from drivers/infiniband/core/cm.c.orig +1 -2
@@ -240,11 +240,10 @@ static void * cm_copy_private_data(const
 	if (!private_data || !private_data_len)
 		return NULL;
 
-	data = kmalloc(private_data_len, GFP_KERNEL);
+	data = kmemdup(private_data, private_data_len, GFP_KERNEL);
 	if (!data)
 		return ERR_PTR(-ENOMEM);
 
-	memcpy(data, private_data, private_data_len);
 	return data;
 }
 
drivers/infiniband/core/ucm.c renamed from drivers/infiniband/core/ucm.c.orig +2 -4
@@ -328,20 +328,18 @@ static int ib_ucm_event_process(struct i
 	}
 
 	if (uvt->data_len) {
-		uvt->data = kmalloc(uvt->data_len, GFP_KERNEL);
+		uvt->data = kmemdup(evt->private_data, uvt->data_len, GFP_KERNEL);
 		if (!uvt->data)
 			goto err1;
 
-		memcpy(uvt->data, evt->private_data, uvt->data_len);
 		uvt->resp.present |= IB_UCM_PRES_DATA;
 	}
 
 	if (uvt->info_len) {
-		uvt->info = kmalloc(uvt->info_len, GFP_KERNEL);
+		uvt->info = kmemdup(info, uvt->info_len, GFP_KERNEL);
 		if (!uvt->info)
 			goto err2;
 
-		memcpy(uvt->info, info, uvt->info_len);
 		uvt->resp.present |= IB_UCM_PRES_INFO;
 	}
 	return 0;
drivers/infiniband/core/iwcm.c renamed from drivers/infiniband/core/iwcm.c.orig +1 -2
@@ -140,10 +140,9 @@ static int copy_private_data(struct iwcm
 {
 	void *p;
 
-	p = kmalloc(event->private_data_len, GFP_ATOMIC);
+	p = kmemdup(event->private_data, event->private_data_len, GFP_ATOMIC);
 	if (!p)
 		return -ENOMEM;
-	memcpy(p, event->private_data, event->private_data_len);
 	event->private_data = p;
 	return 0;
 }
drivers/infiniband/hw/mthca/mthca_provider.c renamed from drivers/infiniband/hw/mthca/mthca_provider.c.orig +1 -2
@@ -1100,11 +1100,10 @@ static struct ib_fmr *mthca_alloc_fmr(st
 	struct mthca_fmr *fmr;
 	int err;
 
-	fmr = kmalloc(sizeof *fmr, GFP_KERNEL);
+	fmr = kmemdup(fmr_attr, sizeof *fmr, GFP_KERNEL);
 	if (!fmr)
 		return ERR_PTR(-ENOMEM);
 
-	memcpy(&fmr->attr, fmr_attr, sizeof *fmr_attr);
 	err = mthca_fmr_alloc(to_mdev(pd->device), to_mpd(pd)->pd_num,
 			     convert_access(mr_access_flags), fmr);
 

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#4 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/media/video

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/media/video/ovcamchip/ovcamchip_core.c renamed from drivers/media/video/ovcamchip/ovcamchip_core.c.orig +1 -2
@@ -307,12 +307,11 @@ static int ovcamchip_attach(struct i2c_a
 		return -ENODEV;
 	}
 
-	c = kmalloc(sizeof *c, GFP_KERNEL);
+	c = kmemdup(&client_template, sizeof *c, GFP_KERNEL);
 	if (!c) {
 		rc = -ENOMEM;
 		goto no_client;
 	}
-	memcpy(c, &client_template, sizeof *c);
 	c->adapter = adap;
 	strcpy(c->name, "OV????");
 
drivers/media/video/pvrusb2/pvrusb2-io.c renamed from drivers/media/video/pvrusb2/pvrusb2-io.c.orig +1 -2
@@ -351,9 +351,8 @@ static int pvr2_stream_buffer_count(stru
 		if (scnt < sp->buffer_slot_count) {
 			struct pvr2_buffer **nb = NULL;
 			if (scnt) {
-				nb = kmalloc(scnt * sizeof(*nb),GFP_KERNEL);
+				nb = kmemdup(sp->buffers, scnt * sizeof(*nb),GFP_KERNEL);
 				if (!nb) return -ENOMEM;
-				memcpy(nb,sp->buffers,scnt * sizeof(*nb));
 			}
 			kfree(sp->buffers);
 			sp->buffers = nb;
drivers/media/video/saa5246a.c renamed from drivers/media/video/saa5246a.c.orig +1 -2
@@ -80,12 +80,11 @@ static int saa5246a_attach(struct i2c_ad
 	struct saa5246a_device *t;
 
 	printk(KERN_INFO "saa5246a: teletext chip found.\n");
-	client=kmalloc(sizeof(*client), GFP_KERNEL);
+	client=kmemdup(&client_template, sizeof(*client), GFP_KERNEL);
 	if(client=NULL)
 		return -ENOMEM;
 	client_template.adapter = adap;
 	client_template.addr = addr;
-	memcpy(client, &client_template, sizeof(*client));
 	t = kzalloc(sizeof(*t), GFP_KERNEL);
 	if(t=NULL)
 	{
drivers/media/video/tuner-3036.c renamed from drivers/media/video/tuner-3036.c.orig +1 -2
@@ -121,10 +121,9 @@ tuner_attach(struct i2c_adapter *adap, i
 	client_template.adapter = adap;
 	client_template.addr = addr;
 
-	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	client = kmemdup(&client_template, sizeof(struct i2c_client), GFP_KERNEL);
 	if (client = NULL)
 		return -ENOMEM;
-	memcpy(client, &client_template, sizeof(struct i2c_client));
 
 	printk("tuner: SAB3036 found, status %02x\n", tuner_getstatus(client));
 
drivers/media/video/tvp5150.c renamed from drivers/media/video/tvp5150.c.orig +1 -2
@@ -1066,10 +1066,9 @@ static int tvp5150_detect_client(struct 
 	     I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
 		return 0;
 
-	c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
+	c = kmemdup(&client_template, sizeof(struct i2c_client), GFP_KERNEL);
 	if (c = 0)
 		return -ENOMEM;
-	memcpy(c, &client_template, sizeof(struct i2c_client));
 
 	core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
 	if (core = 0) {

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#5 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/message

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/message/fusion/mptbase.c renamed from drivers/message/fusion/mptbase.c.orig +1 -2
@@ -4846,9 +4846,8 @@ mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
 	cfg.physAddr = ioc3_dma;
 	cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
 	if (mpt_config(ioc, &cfg) = 0) {
-		mem = kmalloc(iocpage3sz, GFP_ATOMIC);
+		mem = kmemdup((u8 *) pIoc3, iocpage3sz, GFP_ATOMIC);
 		if (mem) {
-			memcpy(mem, (u8 *)pIoc3, iocpage3sz);
 			ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;
 		}
 	}

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#6 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/net

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/net/tulip/de2104x.c renamed from drivers/net/tulip/de2104x.c.orig +1 -3
@@ -1906,9 +1906,7 @@ fill_defaults:
 			de->media[i].csr15 = t21041_csr15[i];
 	}
 
-	de->ee_data = kmalloc(DE_EEPROM_SIZE, GFP_KERNEL);
-	if (de->ee_data)
-		memcpy(de->ee_data, &ee_data[0], DE_EEPROM_SIZE);
+	de->ee_data = kmemdup(&ee_data[0], DE_EEPROM_SIZE, GFP_KERNEL);
 
 	return;
 
drivers/net/wireless/ipw2100.c renamed from drivers/net/wireless/ipw2100.c.orig +1 -2
@@ -7568,11 +7568,10 @@ static int ipw2100_wx_set_genie(struct n
 		return -EINVAL;
 
 	if (wrqu->data.length) {
-		buf = kmalloc(wrqu->data.length, GFP_KERNEL);
+		buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
 		if (buf = NULL)
 			return -ENOMEM;
 
-		memcpy(buf, extra, wrqu->data.length);
 		kfree(ieee->wpa_ie);
 		ieee->wpa_ie = buf;
 		ieee->wpa_ie_len = wrqu->data.length;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#7 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/parport

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/parport/parport_sunbpp.c renamed from drivers/parport/parport_sunbpp.c.orig +1 -3
@@ -309,12 +309,10 @@ static int __devinit init_one_port(struc
 	size = sdev->reg_addrs[0].reg_size;
 	dma = PARPORT_DMA_NONE;
 
-	ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);
+	ops = kmemdup(&parport_sunbpp_ops, sizeof(struct parport_operations), GFP_KERNEL);
         if (!ops)
 		goto out_unmap;
 
-        memcpy (ops, &parport_sunbpp_ops, sizeof (struct parport_operations));
-
 	dprintk(("register_port\n"));
 	if (!(p = parport_register_port((unsigned long)base, irq, dma, ops)))
 		goto out_free_ops;
drivers/parport/procfs.c renamed from drivers/parport/procfs.c.orig +2 -4
@@ -381,10 +381,9 @@ int parport_proc_register(struct parport
 	struct parport_sysctl_table *t;
 	int i;
 
-	t = kmalloc(sizeof(*t), GFP_KERNEL);
+	t = kmemdup(&parport_sysctl_template, sizeof(*t), GFP_KERNEL);
 	if (t = NULL)
 		return -ENOMEM;
-	memcpy(t, &parport_sysctl_template, sizeof(*t));
 
 	t->device_dir[0].extra1 = port;
 
@@ -429,10 +428,9 @@ int parport_device_proc_register(struct 
 	struct parport_device_sysctl_table *t;
 	struct parport * port = device->port;
 	
-	t = kmalloc(sizeof(*t), GFP_KERNEL);
+	t = kmemdup(&parport_device_sysctl_template, sizeof(*t), GFP_KERNEL);
 	if (t = NULL)
 		return -ENOMEM;
-	memcpy(t, &parport_device_sysctl_template, sizeof(*t));
 
 	t->dev_dir[0].child = t->parport_dir;
 	t->parport_dir[0].child = t->port_dir;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#8 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/pci/

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/pci/hotplug/acpiphp_ibm.c renamed from drivers/pci/hotplug/acpiphp_ibm.c.orig +2 -4
@@ -160,10 +160,8 @@ static union apci_descriptor *ibm_slot_f
 		ret = des;
 
 ibm_slot_done:
-	if (ret) {
-		ret = kmalloc(sizeof(union apci_descriptor), GFP_KERNEL);
-		memcpy(ret, des, sizeof(union apci_descriptor));
-	}
+	if (ret)
+		ret = kmemdup(des, sizeof(union apci_descriptor), GFP_KERNEL);
 	kfree(table);
 	return ret;
 }

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#9 lore raw

Re: [KJ] [Patch] kmemdup() cleanup in drivers/message

In reply to Eric Sesterhenn

Review

Quoted 6 lines · Eric Sesterhenn
(quoted diff) +1 -2
 	if (mpt_config(ioc, &cfg) = 0) {
-		mem = kmalloc(iocpage3sz, GFP_ATOMIC);
+		mem = kmemdup((u8 *) pIoc3, iocpage3sz, GFP_ATOMIC);
 		if (mem) {
-			memcpy(mem, (u8 *)pIoc3, iocpage3sz);
 			ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;

I don't think the cast is really needed
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#12 lore raw

Re: [KJ] [Patch] kmemdup() cleanup in drivers/pci/

In reply to Eric Sesterhenn
Quoted 5 lines · * Alexey Dobriyan ([email protected]) wrote:
Quoted 2 lines · Eric Sesterhenn

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

Patches are OK, btw what inlining/non inlining you are referring too?

the -O3 -Os compiler flags, where gcc might make the inlining decission accordingly.

Greetings, Eric

Signature · 5 lines
 www.cobra-basket.de -- just my stuff
_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors
#13 lore raw

Re: [KJ] [Patch] kmemdup() cleanup in drivers/pci/

In reply to Eric Sesterhenn

Hi eric,
to add some cream you may like to use (i did not check the types):
ret = kmemdup(des, sizeof(*des), GFP_KERNEL);
that make it independet of the type.

re,
wh

Quoted 24 lines · Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/pci/hotplug/acpiphp_ibm.c renamed from drivers/pci/hotplug/acpiphp_ibm.c.orig +2 -4
@@ -160,10 +160,8 @@ static union apci_descriptor *ibm_slot_f
 		ret = des;
 
 ibm_slot_done:
-	if (ret) {
-		ret = kmalloc(sizeof(union apci_descriptor), GFP_KERNEL);
-		memcpy(ret, des, sizeof(union apci_descriptor));
-	}
+	if (ret)
+		ret = kmemdup(des, sizeof(union apci_descriptor), GFP_KERNEL);
 	kfree(table);
 	return ret;
 }
Quoted 7 lines

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#14 lore raw

Re: [KJ] [Patch] kmemdup() cleanup in drivers/pci/

In reply to Eric Sesterhenn
Quoted 3 lines · walter harms

to add some cream you may like to use (i did not check the types):
ret = kmemdup(des, sizeof(*des), GFP_KERNEL);
that make it independet of the type.

When this was last discussed on l-k, it was shown that some prefer

	sizeof(*p)

some
sizeof(struct foo)

so patches to make one style dominant are not welcome.

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#15 lore raw

Re: [KJ] [Patch] kmemdup() cleanup in drivers/pci/

In reply to Eric Sesterhenn
Quoted 5 lines · Alexey Dobriyan
Quoted 3 lines · walter harms

to add some cream you may like to use (i did not check the types):
ret = kmemdup(des, sizeof(*des), GFP_KERNEL);
that make it independet of the type.

Quoted 8 lines

When this was last discussed on l-k, it was shown that some prefer

	sizeof(*p)

some
sizeof(struct foo)

so patches to make one style dominant are not welcome.

Chapter 14 of CodingStyle says those other people are wrong.
_______________________________________________
Kernel-janitors mailing list [email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#16 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/scsi

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/scsi/megaraid.c renamed from drivers/scsi/megaraid.c.orig +1 -3
@@ -2087,12 +2087,10 @@ megaraid_abort_and_reset(adapter_t *adap
 static inline int
 make_local_pdev(adapter_t *adapter, struct pci_dev **pdev)
 {
-	*pdev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
+	*pdev = kmemdup(adapter->dev, sizeof(struct pci_dev), GFP_KERNEL);
 
 	if( *pdev = NULL ) return -1;
 
-	memcpy(*pdev, adapter->dev, sizeof(struct pci_dev));
-
 	if( pci_set_dma_mask(*pdev, DMA_32BIT_MASK) != 0 ) {
 		kfree(*pdev);
 		return -1;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#17 lore raw

PATCH 1/1 kmemdup() cleanup in drivers/video/

In reply to Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/video/aty/radeon_monitor.c renamed from drivers/video/aty/radeon_monitor.c.orig +1 -2
@@ -104,10 +104,9 @@ static int __devinit radeon_parse_montyp
 	if (pedid = NULL)
 		return mt;
 
-	tmp = (u8 *)kmalloc(EDID_LENGTH, GFP_KERNEL);
+	tmp = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
 	if (!tmp)
 		return mt;
-	memcpy(tmp, pedid, EDID_LENGTH);
 	*out_EDID = tmp;
 	return mt;
 }
drivers/video/i810/i810-i2c.c renamed from drivers/video/i810/i810-i2c.c.orig +1 -3
@@ -162,9 +162,7 @@ int i810_probe_i2c_connector(struct fb_i
 
 		if (e != NULL) {
 			DPRINTK("i810-i2c: Getting EDID from BIOS\n");
-			edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
-			if (edid)
-				memcpy(edid, e, EDID_LENGTH);
+			edid = kmemdup(e, EDID_LENGTH, GFP_KERNEL);
 		}
 	}
 
drivers/video/intelfb/intelfbdrv.c renamed from drivers/video/intelfb/intelfbdrv.c.orig +1 -2
@@ -1058,10 +1058,9 @@ intelfb_init_var(struct intelfb_info *di
 		u8 *edid_d = NULL;
 
 		if (edid_s) {
-			edid_d = kmalloc(EDID_LENGTH, GFP_KERNEL);
+			edid_d = kmemdup(edid_s, EDID_LENGTH, GFP_KERNEL);
 
 			if (edid_d) {
-				memcpy(edid_d, edid_s, EDID_LENGTH);
 				fb_edid_to_monspecs(edid_d,
 						    &dinfo->info->monspecs);
 				kfree(edid_d);
drivers/video/nvidia/nv_i2c.c renamed from drivers/video/nvidia/nv_i2c.c.orig +2 -5
@@ -210,11 +210,8 @@ int nvidia_probe_i2c_connector(struct fb
 		/* try to get from firmware */
 		const u8 *e = fb_firmware_edid(info->device);
 
-		if (e != NULL) {
-			edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
-			if (edid)
-				memcpy(edid, e, EDID_LENGTH);
-		}
+		if (e != NULL)
+			edid = kmemdup(e, EDID_LENGTH, GFP_KERNEL);
 	}
 
 	*out_edid = edid;
drivers/video/nvidia/nv_of.c renamed from drivers/video/nvidia/nv_of.c.orig +1 -2
@@ -72,10 +72,9 @@ int nvidia_probe_of_connector(struct fb_
 		}
 	}
 	if (pedid) {
-		*out_edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
+		*out_edid = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
 		if (*out_edid = NULL)
 			return -1;
-		memcpy(*out_edid, pedid, EDID_LENGTH);
 		printk(KERN_DEBUG "nvidiafb: Found OF EDID for head %d\n", conn);
 		return 0;
 	}
drivers/video/savage/savagefb-i2c.c renamed from drivers/video/savage/savagefb-i2c.c.orig +2 -5
@@ -227,11 +227,8 @@ int savagefb_probe_i2c_connector(struct 
 		/* try to get from firmware */
 		const u8 *e = fb_firmware_edid(info->device);
 
-		if (e) {
-			edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
-			if (edid)
-				memcpy(edid, e, EDID_LENGTH);
-		}
+		if (e)
+			edid = kmemdup(e, EDID_LENGTH, GFP_KERNEL);
 	}
 
 	*out_edid = edid;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#18 lore raw

Re: [KJ] [Patch] kmemdup() cleanup in drivers/media/video

In reply to Eric Sesterhenn

drivers/media/video/saa5246a.c static int saa5246a_attach(struct i2c_ad · line 88

Quoted 13 lines · Eric Sesterhenn
drivers/media/video/saa5246a.c renamed from drivers/media/video/saa5246a.c.orig +1 -2
@@ -80,12 +80,11 @@ static int saa5246a_attach(struct i2c_ad
 	struct saa5246a_device *t;
 
 	printk(KERN_INFO "saa5246a: teletext chip found.\n");
-	client=kmalloc(sizeof(*client), GFP_KERNEL);
+	client=kmemdup(&client_template, sizeof(*client), GFP_KERNEL);
 	if(client=NULL)
 		return -ENOMEM;
 	client_template.adapter = adap;
 	client_template.addr = addr;
-	memcpy(client, &client_template, sizeof(*client));

I've dropped this chunk. Transformation is not identical. OTOH, some other driver does assignments before kmalloc().

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#19 lore raw

Re: [KJ] [Patch] kmemdup() cleanup in drivers/message

In reply to Eric Sesterhenn
Quoted 9 lines · Matthew Wilcox

Review

Quoted 6 lines · Eric Sesterhenn
(quoted diff) +1 -2
 	if (mpt_config(ioc, &cfg) = 0) {
-		mem = kmalloc(iocpage3sz, GFP_ATOMIC);
+		mem = kmemdup((u8 *) pIoc3, iocpage3sz, GFP_ATOMIC);
 		if (mem) {
-			memcpy(mem, (u8 *)pIoc3, iocpage3sz);
 			ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;

I don't think the cast is really needed

Agree. {} also became unneeded. Fixed locally.

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

Applied
#20 lore raw

Re: [KJ] [Patch] kmemdup() cleanup in drivers/net

In reply to Eric Sesterhenn

drivers/net/wireless/ipw2100.c

Quoted 12 lines · Eric Sesterhenn

hi,

replace open coded kmemdup() to save some screen space, and allow inlining/not inlining to be triggered by gcc.

drivers/net/tulip/de2104x.c renamed from drivers/net/tulip/de2104x.c.orig +0 -0
drivers/net/wireless/ipw2100.c renamed from drivers/net/wireless/ipw2100.c.orig +0 -0

applied

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors