Skip to contentSkip to conversation

ia64: Remove unnecessary cast of allocation return value in sn_hwperf_enum_objects()

PATCH Applied Jesper Juhl 22 participants 65 messages Aug 23, 2007 – Aug 31, 2007 3 messages not in the archive

Subsystems (19)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): Message-Id: <[email protected]

#1 lore raw

PATCH 1/30 ia64: Remove unnecessary cast of allocation return value in sn_hwperf_enum_objects()

vmalloc() returns a void pointer - no need to cast it.

---
 arch/ia64/sn/kernel/sn2/sn_hwperf.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/ia64/sn/kernel/sn2/sn_hwperf.c +2 -1
index df8d5be..1a8e496 100644
@@ -66,7 +66,8 @@ static int sn_hwperf_enum_objects(int *nobj, struct sn_hwperf_object_info **ret)
 	}
 
 	sz = sn_hwperf_obj_cnt * sizeof(struct sn_hwperf_object_info);
-	if ((objbuf = (struct sn_hwperf_object_info *) vmalloc(sz)) = NULL) {
+	objbuf = vmalloc(sz);
+	if (objbuf = NULL) {
 		printk("sn_hwperf_enum_objects: vmalloc(%d) failed\n", (int)sz);
 		e = -ENOMEM;
 		goto out;
Signature · 1 line
1.5.2.2
#2 lore raw

PATCH 2/30 cris: Remove unnecessary cast of allocation return value in intmem.c

kmalloc() returns a void pointer so there's no need to cast the return value.

---
 arch/cris/arch-v32/mm/intmem.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
arch/cris/arch-v32/mm/intmem.c +4 -6
index 41ee7f7..691cf3b 100644
@@ -27,8 +27,8 @@ static void crisv32_intmem_init(void)
 {
 	static int initiated = 0;
 	if (!initiated) {
-		struct intmem_allocation* alloc =
-		  (struct intmem_allocation*)kmalloc(sizeof *alloc, GFP_KERNEL);
+		struct intmem_allocation *alloc =
+			kmalloc(sizeof *alloc, GFP_KERNEL);
 		INIT_LIST_HEAD(&intmem_allocations);
 		intmem_virtual = ioremap(MEM_INTMEM_START, MEM_INTMEM_SIZE);
 		initiated = 1;
@@ -55,8 +55,7 @@ void* crisv32_intmem_alloc(unsigned size, unsigned align)
 		if (allocation->status == STATUS_FREE &&
 		    allocation->size >= size + alignment) {
 			if (allocation->size > size + alignment) {
-				struct intmem_allocation* alloc =
-					(struct intmem_allocation*)
+				struct intmem_allocation *alloc =
 					kmalloc(sizeof *alloc, GFP_ATOMIC);
 				alloc->status = STATUS_FREE;
 				alloc->size = allocation->size - size - alignment;
@@ -64,8 +63,7 @@ void* crisv32_intmem_alloc(unsigned size, unsigned align)
 				list_add(&alloc->entry, &allocation->entry);
 
 				if (alignment) {
-					struct intmem_allocation* tmp;
-					tmp = (struct intmem_allocation*)
+					struct intmem_allocation *tmp =
 						kmalloc(sizeof *tmp, GFP_ATOMIC);
 					tmp->offset = allocation->offset;
 					tmp->size = alignment;
Signature · 1 line
1.5.2.2
#3 lore raw

PATCH 3/30 um: Don't unnecessarily cast allocation return value in ubd_kern.c

In reply to Jesper Juhl

vmalloc() returns a void pointer, so casting to (void *) is pretty pointless.

---
 arch/um/drivers/ubd_kern.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/um/drivers/ubd_kern.c +1 -1
index 0eabe73..25b248a 100644
@@ -615,7 +615,7 @@ static int ubd_open_dev(struct ubd *ubd_dev)
 		blk_queue_max_sectors(ubd_dev->queue, 8 * sizeof(long));
 
 		err = -ENOMEM;
-		ubd_dev->cow.bitmap = (void *) vmalloc(ubd_dev->cow.bitmap_len);
+		ubd_dev->cow.bitmap = vmalloc(ubd_dev->cow.bitmap_len);
 		if(ubd_dev->cow.bitmap == NULL){
 			printk(KERN_ERR "Failed to vmalloc COW bitmap\n");
 			goto error;
Signature · 12 lines
1.5.2.2


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#4 lore raw

Re: [PATCH 03/30] um: Don't unnecessarily cast allocation return value in ubd_kern.c

Quoted 1 line · Jesper Juhl

vmalloc() returns a void pointer, so casting to (void *) is pretty pointless.

Righto, I'll take care of this.

Jeff

Signature · 11 lines
Work email - jdike at linux dot intel dot com

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#5 lore raw

PATCH 4/30 powerpc: Don't cast kmalloc return value in ibmebus.c

In reply to Jesper Juhl

kmalloc() returns a void pointer so there is absolutely no need to cast it in ibmebus_chomp().

---
 arch/powerpc/kernel/ibmebus.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/powerpc/kernel/ibmebus.c +2 -1
index 9a8c9af..9514e66 100644
@@ -383,7 +383,8 @@ static int ibmebus_match_path(struct device *dev, void *data)
 
 static char *ibmebus_chomp(const char *in, size_t count)
 {
-	char *out = (char*)kmalloc(count + 1, GFP_KERNEL);
+	char *out = kmalloc(count + 1, GFP_KERNEL);
+
 	if (!out)
 		return NULL;
 
Signature · 1 line
1.5.2.2
#7 lore raw

PATCH 5/30 atm: No need to cast vmalloc() return value

In reply to Jesper Juhl

vmalloc() returns void*, no need to cast it in drivers/atm/lanai.c

---
 drivers/atm/lanai.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/atm/lanai.c +1 -1
index 144a49f..59e7dde 100644
@@ -1459,7 +1459,7 @@ static int __devinit vcc_table_allocate(struct lanai_dev *lanai)
 	return (lanai->vccs == NULL) ? -ENOMEM : 0;
 #else
 	int bytes = (lanai->num_vci) * sizeof(struct lanai_vcc *);
-	lanai->vccs = (struct lanai_vcc **) vmalloc(bytes);
+	lanai->vccs = vmalloc(bytes);
 	if (unlikely(lanai->vccs == NULL))
 		return -ENOMEM;
 	memset(lanai->vccs, 0, bytes);
Signature · 1 line
1.5.2.2
#8 lore raw

PATCH 6/30 i2o: No need to cast kmalloc() return value in cfg_open()

In reply to Jesper Juhl

In drivers/message/i2o/i2o_config.c::cfg_open() there's a completely pointless cast of kmalloc()'s return value. This patch removes it.

---
 drivers/message/i2o/i2o_config.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/message/i2o/i2o_config.c +2 -3
index 84e046e..fb8c668 100644
@@ -1053,10 +1053,9 @@ static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd,
 
 static int cfg_open(struct inode *inode, struct file *file)
 {
-	struct i2o_cfg_info *tmp =
-	    (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
-					   GFP_KERNEL);
 	unsigned long flags;
+	struct i2o_cfg_info *tmp =
+		kmalloc(sizeof(struct i2o_cfg_info), GFP_KERNEL);
 
 	if (!tmp)
 		return -ENOMEM;
Signature · 1 line
1.5.2.2
#9 lore raw

PATCH 7/30 mtd: Get rid of pointless cast of kzalloc() return value in AT26xxx driver

In reply to Jesper Juhl

kzalloc() returns a void pointer - no need to cast it in
drivers/mtd/devices/at91_dataflash26.c::add_dataflash()

---
 drivers/mtd/devices/at91_dataflash26.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/mtd/devices/at91_dataflash26.c +1 -2
index 64ce37f..9c4aac4 100644
@@ -360,8 +360,7 @@ static int __init add_dataflash(int channel, char *name, int nr_pages,
 	device->read = at91_dataflash26_read;
 	device->write = at91_dataflash26_write;
 
-	priv = (struct dataflash_local *)kzalloc(sizeof(struct dataflash_local),
-		GFP_KERNEL);
+	priv = kzalloc(sizeof(struct dataflash_local), GFP_KERNEL);
 	if (!priv) {
 		kfree(device);
 		return -ENOMEM;
Signature · 1 line
1.5.2.2
#10 lore raw

PATCH 8/30 mtd: Avoid a pointless kmalloc() return value cast in TQM8xxL mapping handling code

In reply to Jesper Juhl

In drivers/mtd/maps/tqm8xxl.c::init_tqm_mtd() it is pointless casting the return value of kmalloc() since it returns void*.

---
 drivers/mtd/maps/tqm8xxl.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/mtd/maps/tqm8xxl.c +1 -2
index 37e4ded..1d75ce4 100644
@@ -141,8 +141,7 @@ int __init init_tqm_mtd(void)
 			goto error_mem;
 		}
 
-		map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
-
+		map_banks[idx]->name = kmalloc(16, GFP_KERNEL);
 		if (!map_banks[idx]->name) {
 			ret = -ENOMEM;
 			/* FIXME: What if some MTD devices were probed already? */
Signature · 1 line
1.5.2.2
#11 lore raw

PATCH 9/30 mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

In reply to Jesper Juhl

kmalloc() returns a void pointer.
No need to cast it.

---
 drivers/mtd/maps/pmcmsp-flash.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
drivers/mtd/maps/pmcmsp-flash.c +5 -8
index 7e0377e..dfdb120 100644
@@ -73,12 +73,9 @@ int __init init_msp_flash(void)
 		return -ENXIO;
 
 	printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt);
-	msp_flash = (struct mtd_info **)kmalloc(
-			fcnt * sizeof(struct map_info *), GFP_KERNEL);
-	msp_parts = (struct mtd_partition **)kmalloc(
-			fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
-	msp_maps = (struct map_info *)kmalloc(
-			fcnt * sizeof(struct mtd_info), GFP_KERNEL);
+	msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
+	msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
+	msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
 	memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));
 
 	/* loop over the flash devices, initializing each */
@@ -95,8 +92,8 @@ int __init init_msp_flash(void)
 			continue;
 		}
 
-		msp_parts[i] = (struct mtd_partition *)kmalloc(
-			pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
+		msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
+			GFP_KERNEL);
 		memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
 
 		/* now initialize the devices proper */
Signature · 1 line
1.5.2.2
#12 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

drivers/mtd/maps/pmcmsp-flash.c int __init init_msp_flash(void) · line 79

Quoted 13 lines · Jesper Juhl

kmalloc() returns a void pointer.
No need to cast it.

drivers/mtd/maps/pmcmsp-flash.c +3 -6
-	msp_flash = (struct mtd_info **)kmalloc(
-			fcnt * sizeof(struct map_info *), GFP_KERNEL);
-	msp_parts = (struct mtd_partition **)kmalloc(
-			fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
-	msp_maps = (struct map_info *)kmalloc(
-			fcnt * sizeof(struct mtd_info), GFP_KERNEL);
+	msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
+	msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
+	msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
 	memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));

This one wants kzalloc.

drivers/mtd/maps/pmcmsp-flash.c int __init init_msp_flash(void) · line 99

Quoted 7 lines
drivers/mtd/maps/pmcmsp-flash.c +2 -2
-		msp_parts[i] = (struct mtd_partition *)kmalloc(
-			pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
+		msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
+			GFP_KERNEL);
 		memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
 
 		/* now initialize the devices proper */

Same
--
vda

#13 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 23 lines · Denys Vlasenko

drivers/mtd/maps/pmcmsp-flash.c int __init init_msp_flash(void) · line 79

Quoted 13 lines · Jesper Juhl

kmalloc() returns a void pointer.
No need to cast it.

drivers/mtd/maps/pmcmsp-flash.c +3 -6
-     msp_flash = (struct mtd_info **)kmalloc(
-                     fcnt * sizeof(struct map_info *), GFP_KERNEL);
-     msp_parts = (struct mtd_partition **)kmalloc(
-                     fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
-     msp_maps = (struct map_info *)kmalloc(
-                     fcnt * sizeof(struct mtd_info), GFP_KERNEL);
+     msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
+     msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
+     msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
      memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));

This one wants kzalloc.

Quoted 6 lines
drivers/mtd/maps/pmcmsp-flash.c +2 -2
-             msp_parts[i] = (struct mtd_partition *)kmalloc(
-                     pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
+             msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
+                     GFP_KERNEL);
              memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
Quoted 3 lines
Quoted 1 line
              /* now initialize the devices proper */

Same

Ok, thank you for that feedback.
I'll respin the patch with that change when I resubmit all the ones
that don't get picked up (probably next week).

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#14 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

In reply to Denys Vlasenko
Quoted 23 lines · Denys Vlasenko

drivers/mtd/maps/pmcmsp-flash.c int __init init_msp_flash(void) · line 79

Quoted 13 lines · Jesper Juhl

kmalloc() returns a void pointer.
No need to cast it.

drivers/mtd/maps/pmcmsp-flash.c +3 -6
-	msp_flash = (struct mtd_info **)kmalloc(
-			fcnt * sizeof(struct map_info *), GFP_KERNEL);
-	msp_parts = (struct mtd_partition **)kmalloc(
-			fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
-	msp_maps = (struct map_info *)kmalloc(
-			fcnt * sizeof(struct mtd_info), GFP_KERNEL);
+	msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
+	msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
+	msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
 	memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));

This one wants kzalloc.

Quoted 6 lines
drivers/mtd/maps/pmcmsp-flash.c +2 -2
-		msp_parts[i] = (struct mtd_partition *)kmalloc(
-			pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
+		msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
+			GFP_KERNEL);
 		memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
Quoted 3 lines
Quoted 1 line

/* now initialize the devices proper */

Same

actually, i would think kcalloc would be more appropriate here, no?

rday

Signature · 7 lines
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================
#15 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 25 lines · Robert P. J. Day
Quoted 23 lines · Denys Vlasenko

drivers/mtd/maps/pmcmsp-flash.c int __init init_msp_flash(void) · line 79

Quoted 13 lines · Jesper Juhl

kmalloc() returns a void pointer.
No need to cast it.

drivers/mtd/maps/pmcmsp-flash.c +3 -6
-   msp_flash = (struct mtd_info **)kmalloc(
-                   fcnt * sizeof(struct map_info *), GFP_KERNEL);
-   msp_parts = (struct mtd_partition **)kmalloc(
-                   fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
-   msp_maps = (struct map_info *)kmalloc(
-                   fcnt * sizeof(struct mtd_info), GFP_KERNEL);
+   msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
+   msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
+   msp_maps = kmalloc(fcnt * sizeof(struct mtd_info), GFP_KERNEL);
    memset(msp_maps, 0, fcnt * sizeof(struct mtd_info));

This one wants kzalloc.

Quoted 6 lines
drivers/mtd/maps/pmcmsp-flash.c +2 -2
-           msp_parts[i] = (struct mtd_partition *)kmalloc(
-                   pcnt * sizeof(struct mtd_partition), GFP_KERNEL);
+           msp_parts[i] = kmalloc(pcnt * sizeof(struct mtd_partition),
+                   GFP_KERNEL);
            memset(msp_parts[i], 0, pcnt * sizeof(struct mtd_partition));
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
            /* now initialize the devices proper */

Same

actually, i would think kcalloc would be more appropriate here, no?

Why?

msp_parts[i] = kzalloc(pcnt * sizeof(struct mtd_partition), GFP_KERNEL);

seems better to me than

msp_parts[i] = kcalloc(1, pcnt * sizeof(struct mtd_partition), GFP_KERNEL);

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#16 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 5 lines · Jesper Juhl
Quoted 2 lines · Robert P. J. Day

actually, i would think kcalloc would be more appropriate here, no?

Quoted 7 lines

Why?

msp_parts[i] = kzalloc(pcnt * sizeof(struct mtd_partition), GFP_KERNEL);

seems better to me than

msp_parts[i] = kcalloc(1, pcnt * sizeof(struct mtd_partition), GFP_KERNEL);

i was thinking more along the lines of

msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);

which was kind of the obvious implication, no? unless there's a reason kcalloc() wouldn't work here, this is pretty much what kcalloc() was designed for.

rday

Signature · 7 lines
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================
#17 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 13 lines · Robert P. J. Day
Quoted 11 lines · Jesper Juhl
Quoted 2 lines · Robert P. J. Day

actually, i would think kcalloc would be more appropriate here, no?

Why?

msp_parts[i] = kzalloc(pcnt * sizeof(struct mtd_partition), GFP_KERNEL);

seems better to me than

Quoted 7 lines
Quoted 1 line

msp_parts[i] = kcalloc(1, pcnt * sizeof(struct mtd_partition), GFP_KERNEL);

i was thinking more along the lines of

msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);

which was kind of the obvious implication, no?

I guess

Quoted 4 lines

unless there's a
reason kcalloc() wouldn't work here, this is pretty much what kcalloc() was designed for.

When Denys brought up the zeroing thing and mentioned kzalloc() I did consider kcalloc() instead, but kzalloc() makes this allocation nicely look like the preceding ones visually and I couldn't convince myself that kcalloc() would give us any real benefit here.

What exactely would using kcalloc() over kzalloc() here buy us?

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#18 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 13 lines · Jesper Juhl
Quoted 5 lines · Robert P. J. Day

i was thinking more along the lines of

msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);

which was kind of the obvious implication, no?

I guess

Quoted 3 lines

unless there's a reason kcalloc() wouldn't work here, this is pretty much what kcalloc() was designed for.

Quoted 6 lines

When Denys brought up the zeroing thing and mentioned kzalloc() I did consider kcalloc() instead, but kzalloc() makes this allocation nicely look like the preceding ones visually and I couldn't convince myself that kcalloc() would give us any real benefit here.

What exactely would using kcalloc() over kzalloc() here buy us?

technically, nothing. but if you're not going to use kcalloc() when you're explicitly allocating an array of identical objects (that you want zero-filled, as a bonus), then what's the point of ever having defined a kcalloc() routine in the first place?

rday

Signature · 7 lines
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================
#19 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 20 lines · Robert P. J. Day
Quoted 18 lines · Jesper Juhl
Quoted 5 lines · Robert P. J. Day

i was thinking more along the lines of

msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);

which was kind of the obvious implication, no?

I guess

Quoted 3 lines

unless there's a reason kcalloc() wouldn't work here, this is pretty much what kcalloc() was designed for.

When Denys brought up the zeroing thing and mentioned kzalloc() I did consider kcalloc() instead, but kzalloc() makes this allocation nicely look like the preceding ones visually and I couldn't convince myself that kcalloc() would give us any real benefit here.

Quoted 7 lines
Quoted 1 line

What exactely would using kcalloc() over kzalloc() here buy us?

technically, nothing. but if you're not going to use kcalloc() when you're explicitly allocating an array of identical objects (that you want zero-filled, as a bonus), then what's the point of ever having defined a kcalloc() routine in the first place?

I wonder a bit about that myself...

I have found some other issues in that function that I want to fix, so I'll be respinning the patch as a patch series instead - and why not; I'll just go with kcalloc() and see what the maintainers have to say, it's not like I personally care much one way or the other.

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#20 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 6 lines · Jesper Juhl
Quoted 2 lines · Robert P. J. Day

technically, nothing. but if you're not going to use kcalloc() when you're explicitly allocating an array of identical objects (that you want zero-filled, as a bonus), then what's the point of ever having defined a kcalloc() routine in the first place?

I wonder a bit about that myself...

I have found some other issues in that function that I want to fix, so I'll be respinning the patch as a patch series instead - and why not; I'll just go with kcalloc() and see what the maintainers have to say, it's not like I personally care much one way or the other.

I think the original reasoning behind kcalloc() was that it did some extra input checking, so that if the product of the two numbers overflowed, it would fail with NULL instead of allocating insufficient space. In the kernel it doesn't matter in practice since you MUST have additional checking on the size of allocated memory anyways, not even considering the fact that >PAGE_SIZE allocations are probably going to fail with decent frequency regardless.

Cheers,
Kyle Moffett

#21 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

In reply to Robert P. J. Day
Quoted 13 lines · Robert P. J. Day
Quoted 12 lines · Jesper Juhl
Quoted 5 lines · Robert P. J. Day

i was thinking more along the lines of

msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), GFP_KERNEL);

which was kind of the obvious implication, no?

I guess

Quoted 2 lines

unless there's a reason kcalloc() wouldn't work here, this is pretty much what kcalloc() was designed for.

Quoted 8 lines
Quoted 6 lines

When Denys brought up the zeroing thing and mentioned kzalloc() I did consider kcalloc() instead, but kzalloc() makes this allocation nicely look like the preceding ones visually and I couldn't convince myself that kcalloc() would give us any real benefit here.

What exactely would using kcalloc() over kzalloc() here buy us?

technically, nothing.

The idea of calloc is that it can check for underflow in parameter.

calloc(-1, 10000000) => easy to detect
malloc(-1 * 10000000) => malloc(-10000000) => not so trivial --
vda

#22 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 6 lines · Denys Vlasenko
Quoted 4 lines
Quoted 2 lines

What exactely would using kcalloc() over kzalloc() here buy us?

technically, nothing.

The idea of calloc is that it can check for underflow in parameter.

Actually, overflow.

calloc(0xFFFF0000, 0x1000) => will return NULL malloc(0xFFFF0000 * 0x1000) => silent 32 bit multiplication/truncation, will allocate less than requested.

Quoted 2 lines

calloc(-1, 10000000) => easy to detect
malloc(-1 * 10000000) => malloc(-10000000) => not so trivial

Jan

#23 lore raw

Re: [PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c

Quoted 7 lines · Jan Engelhardt
Quoted 5 lines · Denys Vlasenko
Quoted 4 lines
Quoted 2 lines

What exactely would using kcalloc() over kzalloc() here buy us?

technically, nothing.

Quoted 11 lines
Quoted 1 line

The idea of calloc is that it can check for underflow in parameter.

Actually, overflow.

calloc(0xFFFF0000, 0x1000) => will return NULL malloc(0xFFFF0000 * 0x1000) => silent 32 bit multiplication/truncation, will allocate less than requested.

Quoted 2 lines

calloc(-1, 10000000) => easy to detect
malloc(-1 * 10000000) => malloc(-10000000) => not so trivial

Ok, that makes a bit of sense. Thank you.

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#24 lore raw

PATCH 10/30 irda: Do not do pointless kmalloc return value cast in KingSun driver

In reply to Jesper Juhl

kmalloc() returns a void pointer, so there is no need to cast it in
drivers/net/irda/kingsun-sir.c::kingsun_probe().

---
 drivers/net/irda/kingsun-sir.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/irda/kingsun-sir.c +2 -2
index bdd5c97..4e5101a 100644
@@ -509,12 +509,12 @@ static int kingsun_probe(struct usb_interface *intf,
 	spin_lock_init(&kingsun->lock);
 
 	/* Allocate input buffer */
-	kingsun->in_buf = (__u8 *)kmalloc(kingsun->max_rx, GFP_KERNEL);
+	kingsun->in_buf = kmalloc(kingsun->max_rx, GFP_KERNEL);
 	if (!kingsun->in_buf)
 		goto free_mem;
 
 	/* Allocate output buffer */
-	kingsun->out_buf = (__u8 *)kmalloc(KINGSUN_FIFO_SIZE, GFP_KERNEL);
+	kingsun->out_buf = kmalloc(KINGSUN_FIFO_SIZE, GFP_KERNEL);
 	if (!kingsun->out_buf)
 		goto free_mem;
 
Signature · 1 line
1.5.2.2
maintainer Applied
#25 lore raw

Re: [PATCH 10/30] irda: Do not do pointless kmalloc return value cast in KingSun driver

From: Jesper Juhl <[email protected]>
Date: Fri, 24 Aug 2007 01:54:23 +0200

Quoted 4 lines

kmalloc() returns a void pointer, so there is no need to cast it in
drivers/net/irda/kingsun-sir.c::kingsun_probe().

Applied.

#26 lore raw

PATCH 14/30 net: Kill some unneeded allocation return value casts in libertas

In reply to Jesper Juhl

kmalloc() and friends return void*, no need to cast it.

---
 drivers/net/wireless/libertas/debugfs.c |    2 +-
 drivers/net/wireless/libertas/ethtool.c |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/wireless/libertas/debugfs.c +1 -1
index 715cbda..6ade63e 100644
@@ -1839,7 +1839,7 @@ static ssize_t wlan_debugfs_write(struct file *f, const char __user *buf,
 	char *p2;
 	struct debug_data *d = (struct debug_data *)f->private_data;
 
-	pdata = (char *)kmalloc(cnt, GFP_KERNEL);
+	pdata = kmalloc(cnt, GFP_KERNEL);
 	if (pdata == NULL)
 		return 0;
 
drivers/net/wireless/libertas/ethtool.c +1 -2
index 96f1974..7dad493 100644
@@ -60,8 +60,7 @@ static int libertas_ethtool_get_eeprom(struct net_device *dev,
 
 //      mutex_lock(&priv->mutex);
 
-	adapter->prdeeprom =
-		    (char *)kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
+	adapter->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
 	if (!adapter->prdeeprom)
 		return -ENOMEM;
 	memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));
Signature · 1 line
1.5.2.2
Applied
#27 lore raw

Re: [PATCH 14/30] net: Kill some unneeded allocation return value casts in libertas

Quoted 1 line · Jesper Juhl

kmalloc() and friends return void*, no need to cast it.

Applied to libertas-2.6 'for-linville' branch, thanks.

Dan

Quoted 33 lines
---
 drivers/net/wireless/libertas/debugfs.c |    2 +-
 drivers/net/wireless/libertas/ethtool.c |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/wireless/libertas/debugfs.c +1 -1
index 715cbda..6ade63e 100644
@@ -1839,7 +1839,7 @@ static ssize_t wlan_debugfs_write(struct file *f, const char __user *buf,
 	char *p2;
 	struct debug_data *d = (struct debug_data *)f->private_data;
 
-	pdata = (char *)kmalloc(cnt, GFP_KERNEL);
+	pdata = kmalloc(cnt, GFP_KERNEL);
 	if (pdata == NULL)
 		return 0;
 
drivers/net/wireless/libertas/ethtool.c +1 -2
index 96f1974..7dad493 100644
@@ -60,8 +60,7 @@ static int libertas_ethtool_get_eeprom(struct net_device *dev,
 
 //      mutex_lock(&priv->mutex);
 
-	adapter->prdeeprom =
-		    (char *)kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
+	adapter->prdeeprom = kmalloc(eeprom->len+sizeof(regctrl), GFP_KERNEL);
 	if (!adapter->prdeeprom)
 		return -ENOMEM;
 	memcpy(adapter->prdeeprom, &regctrl, sizeof(regctrl));
#28 lore raw

PATCH 16/30 net: Avoid pointless allocation casts in BSD compression module

In reply to Jesper Juhl

The general kernel memory allocation functions return void pointers and there is no need to cast their return values.

---
 drivers/net/bsd_comp.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/bsd_comp.c +2 -4
index 202d4a4..88edb98 100644
@@ -406,8 +406,7 @@ static void *bsd_alloc (unsigned char *options, int opt_len, int decomp)
  * Allocate space for the dictionary. This may be more than one page in
  * length.
  */
-    db->dict = (struct bsd_dict *) vmalloc (hsize *
-					    sizeof (struct bsd_dict));
+    db->dict = vmalloc(hsize * sizeof(struct bsd_dict));
     if (!db->dict)
       {
 	bsd_free (db);
@@ -426,8 +425,7 @@ static void *bsd_alloc (unsigned char *options, int opt_len, int decomp)
  */
     else
       {
-        db->lens = (unsigned short *) vmalloc ((maxmaxcode + 1) *
-					       sizeof (db->lens[0]));
+        db->lens = vmalloc((maxmaxcode + 1) * sizeof(db->lens[0]));
 	if (!db->lens)
 	  {
 	    bsd_free (db);
Signature · 1 line
1.5.2.2
maintainer Applied
#29 lore raw

Re: [PATCH 16/30] net: Avoid pointless allocation casts in BSD compression module

From: Jesper Juhl <[email protected]>
Date: Fri, 24 Aug 2007 02:06:58 +0200

Quoted 4 lines

The general kernel memory allocation functions return void pointers and there is no need to cast their return values.

Applied.

#30 lore raw

PATCH 17/30 isdn: Get rid of some pointless allocation casts in common and bsd comp.

In reply to Jesper Juhl

vmalloc() returns a void pointer - no need to cast the return value.

---
 drivers/isdn/i4l/isdn_bsdcomp.c |    5 ++---
 drivers/isdn/i4l/isdn_common.c  |    2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/isdn/i4l/isdn_bsdcomp.c +2 -3
index 90a2379..02d9918 100644
@@ -341,7 +341,7 @@ static void *bsd_alloc (struct isdn_ppp_comp_data *data)
 	 * Allocate space for the dictionary. This may be more than one page in
 	 * length.
 	 */
-	db->dict = (struct bsd_dict *) vmalloc (hsize * sizeof (struct bsd_dict));
+	db->dict = vmalloc(hsize * sizeof(struct bsd_dict));
 	if (!db->dict) {
 		bsd_free (db);
 		return NULL;
@@ -354,8 +354,7 @@ static void *bsd_alloc (struct isdn_ppp_comp_data *data)
 	if (!decomp)
 		db->lens = NULL;
 	else {
-		db->lens = (unsigned short *) vmalloc ((maxmaxcode + 1) *
-			sizeof (db->lens[0]));
+		db->lens = vmalloc((maxmaxcode + 1) * sizeof(db->lens[0]));
 		if (!db->lens) {
 			bsd_free (db);
 			return (NULL);
drivers/isdn/i4l/isdn_common.c +1 -1
index c97330b..ec5f404 100644
@@ -2291,7 +2291,7 @@ static int __init isdn_init(void)
 	int i;
 	char tmprev[50];
 
-	if (!(dev = (isdn_dev *) vmalloc(sizeof(isdn_dev)))) {
+	if (!(dev = vmalloc(sizeof(isdn_dev)))) {
 		printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
 		return -EIO;
 	}
Signature · 1 line
1.5.2.2
Acked-by on v1 17/30
#31 lore raw

Re: [PATCH 17/30] isdn: Get rid of some pointless allocation casts in common and bsd comp.

Quoted 3 lines · Jesper Juhl

vmalloc() returns a void pointer - no need to cast the return value.

Quoted 5 lines
---
 drivers/isdn/i4l/isdn_bsdcomp.c |    5 ++---
 drivers/isdn/i4l/isdn_common.c  |    2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

...

Signature · 4 lines
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)
#33 lore raw

PATCH 18/30 isdn: eicon - get rid of a pointless vmalloc() return value cast

In reply to Jesper Juhl

vmalloc() returns void*.
No need to cast in drivers/isdn/hardware/eicon/platform.h::diva_os_malloc()

---
 drivers/isdn/hardware/eicon/platform.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/isdn/hardware/eicon/platform.h +1 -1
index 15d4942..8756ef1 100644
@@ -167,7 +167,7 @@ static __inline__ void* diva_os_malloc (unsigned long flags, unsigned long size)
 	void *ret = NULL;
 
 	if (size) {
-		ret = (void *) vmalloc((unsigned int) size);
+		ret = vmalloc((unsigned int)size);
 	}
 	return (ret);
 }
Signature · 1 line
1.5.2.2
Acked-by on v1 18/30
#34 lore raw

Re: [PATCH 18/30] isdn: eicon - get rid of a pointless vmalloc() return value cast

vmalloc() returns void*.
No need to cast in drivers/isdn/hardware/eicon/platform.h::diva_os_malloc()

---
 drivers/isdn/hardware/eicon/platform.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/isdn/hardware/eicon/platform.h +1 -1
index 15d4942..8756ef1 100644
@@ -167,7 +167,7 @@ static __inline__ void* diva_os_malloc (unsigned long flags, unsigned long size)
 	void *ret = NULL;
 
 	if (size) {
-		ret = (void *) vmalloc((unsigned int) size);
+		ret = vmalloc((unsigned int)size);
 	}
 	return (ret);
 }
Signature · 1 line
1.5.2.2
#35 lore raw

PATCH 19/30 scsi: Remove explicit casts of [kv]alloc return values in osst driver

In reply to Jesper Juhl

[kv]alloc() return void *. No need to cast the return value.

---
 drivers/scsi/osst.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/osst.c +4 -4
index 08060fb..3ad9d49 100644
@@ -1404,7 +1404,7 @@ static int osst_read_back_buffer_and_rewrite(struct osst_tape * STp, struct osst
 	int			dbg              = debugging;
 #endif
 
-	if ((buffer = (unsigned char *)vmalloc((nframes + 1) * OS_DATA_SIZE)) == NULL)
+	if ((buffer = vmalloc((nframes + 1) * OS_DATA_SIZE)) == NULL)
 		return (-EIO);
 
 	printk(KERN_INFO "%s:I: Reading back %d frames from drive buffer%s\n",
@@ -2216,7 +2216,7 @@ static int osst_write_header(struct osst_tape * STp, struct osst_request ** aSRp
 	if (STp->raw) return 0;
 
 	if (STp->header_cache == NULL) {
-		if ((STp->header_cache = (os_header_t *)vmalloc(sizeof(os_header_t))) == NULL) {
+		if ((STp->header_cache = vmalloc(sizeof(os_header_t))) == NULL) {
 			printk(KERN_ERR "%s:E: Failed to allocate header cache\n", name);
 			return (-ENOMEM);
 		}
@@ -2404,7 +2404,7 @@ static int __osst_analyze_headers(struct osst_tape * STp, struct osst_request **
 				   name, ppos, update_frame_cntr);
 #endif
 		if (STp->header_cache == NULL) {
-			if ((STp->header_cache = (os_header_t *)vmalloc(sizeof(os_header_t))) == NULL) {
+			if ((STp->header_cache = vmalloc(sizeof(os_header_t))) == NULL) {
 				printk(KERN_ERR "%s:E: Failed to allocate header cache\n", name);
 				return 0;
 			}
@@ -5756,7 +5756,7 @@ static int osst_probe(struct device *dev)
 	write_lock(&os_scsi_tapes_lock);
 	if (os_scsi_tapes == NULL) {
 		os_scsi_tapes =
-			(struct osst_tape **)kmalloc(osst_max_dev * sizeof(struct osst_tape *),
+			kmalloc(osst_max_dev * sizeof(struct osst_tape *),
 				   GFP_ATOMIC);
 		if (os_scsi_tapes == NULL) {
 			write_unlock(&os_scsi_tapes_lock);
Signature · 1 line
1.5.2.2
#36 lore raw

Re: [PATCH 19/30] scsi: Remove explicit casts of [kv]alloc return values in osst driver

drivers/scsi/osst.c static int osst_probe(struct device *dev) · line 5762

Quoted 11 lines · Jesper Juhl

[kv]alloc() return void *. No need to cast the return value.

drivers/scsi/osst.c +1 -1
@@ -5756,7 +5756,7 @@ static int osst_probe(struct device *dev)
 	write_lock(&os_scsi_tapes_lock);
 	if (os_scsi_tapes == NULL) {
 		os_scsi_tapes =
-			(struct osst_tape **)kmalloc(osst_max_dev * sizeof(struct osst_tape *),
+			kmalloc(osst_max_dev * sizeof(struct osst_tape *),
 				   GFP_ATOMIC);
 		if (os_scsi_tapes == NULL) {
 			write_unlock(&os_scsi_tapes_lock);

Three lines later:

		for (i=0; i < osst_max_dev; ++i) os_scsi_tapes[i] = NULL;

This wants to be

os_scsi_tapes = kcalloc(osst_max_dev, sizeof(struct osst_tape *), GFP_ATOMIC);

Eike

#37 lore raw

Re: [PATCH 19/30] scsi: Remove explicit casts of [kv]alloc return values in osst driver

Quoted 15 lines · Rolf Eike Beer

drivers/scsi/osst.c static int osst_probe(struct device *dev) · line 5762

Quoted 11 lines · Jesper Juhl

[kv]alloc() return void *. No need to cast the return value.

drivers/scsi/osst.c +1 -1
@@ -5756,7 +5756,7 @@ static int osst_probe(struct device *dev)
      write_lock(&os_scsi_tapes_lock);
      if (os_scsi_tapes == NULL) {
              os_scsi_tapes =
-                     (struct osst_tape **)kmalloc(osst_max_dev * sizeof(struct osst_tape *),
+                     kmalloc(osst_max_dev * sizeof(struct osst_tape *),
                                 GFP_ATOMIC);
              if (os_scsi_tapes == NULL) {
                      write_unlock(&os_scsi_tapes_lock);

Three lines later:

Quoted 6 lines
                for (i=0; i < osst_max_dev; ++i) os_scsi_tapes[i] = NULL;

This wants to be

os_scsi_tapes = kcalloc(osst_max_dev, sizeof(struct osst_tape *), GFP_ATOMIC);

Thank you for pointing that out.

I plan to resend those patches that don't get picked up in about a week or so. I'll address this issue then (or if it does get picked up in its current form I'll submit a follow-on patch to address this).

Quoted 1 line

Eike

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#38 lore raw

PATCH 20/30 scsi: In the Advansys driver, do not cast allocation function return values

In reply to Jesper Juhl

There's no reason to cast void pointers returned by the generic memory allocation functions.

---
 drivers/scsi/advansys.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
drivers/scsi/advansys.c +3 -6
index 79c0b6e..b28729c 100644
@@ -18513,7 +18513,7 @@ advansys_board_found(int iop, struct device *dev, int bus_type)
 		 * Allocate buffer carrier structures. The total size
 		 * is about 4 KB, so allocate all at once.
 		 */
-		carrp = (ADV_CARR_T *) kmalloc(ADV_CARRIER_BUFSIZE, GFP_ATOMIC);
+		carrp = kmalloc(ADV_CARRIER_BUFSIZE, GFP_ATOMIC);
 		ASC_DBG1(1, "advansys_board_found: carrp 0x%lx\n", (ulong)carrp);
 
 		if (carrp == NULL) {
@@ -18529,8 +18529,7 @@ advansys_board_found(int iop, struct device *dev, int bus_type)
 		for (req_cnt = adv_dvc_varp->max_host_qng;
 		     req_cnt > 0; req_cnt--) {
 
-			reqp = (adv_req_t *)
-			    kmalloc(sizeof(adv_req_t) * req_cnt, GFP_ATOMIC);
+			reqp = kmalloc(sizeof(adv_req_t) * req_cnt, GFP_ATOMIC);
 
 			ASC_DBG3(1,
 				 "advansys_board_found: reqp 0x%lx, req_cnt %d, bytes %lu\n",
@@ -18552,9 +18551,7 @@ advansys_board_found(int iop, struct device *dev, int bus_type)
 		boardp->adv_sgblkp = NULL;
 		for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
 
-			sgp = (adv_sgblk_t *)
-			    kmalloc(sizeof(adv_sgblk_t), GFP_ATOMIC);
-
+			sgp = kmalloc(sizeof(adv_sgblk_t), GFP_ATOMIC);
 			if (sgp == NULL) {
 				break;
 			}
Signature · 1 line
1.5.2.2
#39 lore raw

Re: [PATCH 20/30] scsi: In the Advansys driver, do not cast allocation function return values

Quoted 2 lines · Jesper Juhl

There's no reason to cast void pointers returned by the generic memory allocation functions.

I think I fixed all these already; please check scsi-misc.

Signature · 3 lines
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#40 lore raw

Re: [PATCH 20/30] scsi: In the Advansys driver, do not cast allocation function return values

Quoted 6 lines · Matthew Wilcox
Quoted 2 lines · Jesper Juhl

There's no reason to cast void pointers returned by the generic memory allocation functions.

I think I fixed all these already; please check scsi-misc.

I just checked out the latest scsi-misc-2.6 tree and it does indeed look like these have already been dealt with.
Sorry about the noise.

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#41 lore raw

PATCH 21/30 oss: Remove unneeded vmalloc() return value casts in OSS

In reply to Jesper Juhl

vmalloc() returns a void pointer that we don't need to cast. This patch should clean this up in sound/oss/.

---
 sound/oss/midibuf.c   |    4 ++--
 sound/oss/pss.c       |    6 +++---
 sound/oss/sequencer.c |    4 ++--
 sound/oss/sscape.c    |    2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)
sound/oss/midibuf.c +2 -2
index a40be0c..66f8a7f 100644
@@ -177,7 +177,7 @@ int MIDIbuf_open(int dev, struct file *file)
 		return err;
 
 	parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT;
-	midi_in_buf[dev] = (struct midi_buf *) vmalloc(sizeof(struct midi_buf));
+	midi_in_buf[dev] = vmalloc(sizeof(struct midi_buf));
 
 	if (midi_in_buf[dev] == NULL)
 	{
@@ -187,7 +187,7 @@ int MIDIbuf_open(int dev, struct file *file)
 	}
 	midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0;
 
-	midi_out_buf[dev] = (struct midi_buf *) vmalloc(sizeof(struct midi_buf));
+	midi_out_buf[dev] = vmalloc(sizeof(struct midi_buf));
 
 	if (midi_out_buf[dev] == NULL)
 	{
sound/oss/pss.c +3 -3
index ece428b..b140584 100644
@@ -872,7 +872,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg,
 			return 0;
 
 		case SNDCTL_COPR_LOAD:
-			buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
+			buf = vmalloc(sizeof(copr_buffer));
 			if (buf == NULL)
 				return -ENOSPC;
 			if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
@@ -884,7 +884,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg,
 			return err;
 		
 		case SNDCTL_COPR_SENDMSG:
-			mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
+			mbuf = vmalloc(sizeof(copr_msg));
 			if (mbuf == NULL)
 				return -ENOSPC;
 			if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
@@ -908,7 +908,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg,
 
 		case SNDCTL_COPR_RCVMSG:
 			err = 0;
-			mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
+			mbuf = vmalloc(sizeof(copr_msg));
 			if (mbuf == NULL)
 				return -ENOSPC;
 			data = (unsigned short *)mbuf->data;
sound/oss/sequencer.c +2 -2
index 5c215f7..cfe3dd0 100644
@@ -1649,13 +1649,13 @@ void sequencer_init(void)
 {
 	if (sequencer_ok)
 		return;
-	queue = (unsigned char *)vmalloc(SEQ_MAX_QUEUE * EV_SZ);
+	queue = vmalloc(SEQ_MAX_QUEUE * EV_SZ);
 	if (queue == NULL)
 	{
 		printk(KERN_ERR "sequencer: Can't allocate memory for sequencer output queue\n");
 		return;
 	}
-	iqueue = (unsigned char *)vmalloc(SEQ_MAX_QUEUE * IEV_SZ);
+	iqueue = vmalloc(SEQ_MAX_QUEUE * IEV_SZ);
 	if (iqueue == NULL)
 	{
 		printk(KERN_ERR "sequencer: Can't allocate memory for sequencer input queue\n");
sound/oss/sscape.c +1 -1
index 30c36d1..9d6b9b0 100644
@@ -573,7 +573,7 @@ static int sscape_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *ar
 			return 0;
 
 		case SNDCTL_COPR_LOAD:
-			buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
+			buf = vmalloc(sizeof(copr_buffer));
 			if (buf == NULL)
 				return -ENOSPC;
 			if (copy_from_user(buf, arg, sizeof(copr_buffer))) 
Signature · 1 line
1.5.2.2
#42 lore raw

PATCH 22/30 ivtv: kzalloc() returns void pointer, no need to cast

In reply to Jesper Juhl

Since kzalloc() returns a void pointer, we don't need to cast the return value in drivers/media/video/ivtv/ivtv-queue.c

---
 drivers/media/video/ivtv/ivtv-queue.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/video/ivtv/ivtv-queue.c +2 -2
index a04f938..45825b8 100644
@@ -196,7 +196,7 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
 		s->name, s->buffers, s->buf_size, s->buffers * s->buf_size / 1024);
 
 	if (ivtv_might_use_pio(s)) {
-		s->PIOarray = (struct ivtv_SG_element *)kzalloc(SGsize, GFP_KERNEL);
+		s->PIOarray = kzalloc(SGsize, GFP_KERNEL);
 		if (s->PIOarray == NULL) {
 			IVTV_ERR("Could not allocate PIOarray for %s stream\n", s->name);
 			return -ENOMEM;
@@ -204,7 +204,7 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
 	}
 
 	/* Allocate DMA SG Arrays */
-	s->SGarray = (struct ivtv_SG_element *)kzalloc(SGsize, GFP_KERNEL);
+	s->SGarray = kzalloc(SGsize, GFP_KERNEL);
 	if (s->SGarray == NULL) {
 		IVTV_ERR("Could not allocate SGarray for %s stream\n", s->name);
 		if (ivtv_might_use_pio(s)) {
Signature · 1 line
1.5.2.2
#43 lore raw

Re: [PATCH 22/30] ivtv: kzalloc() returns void pointer, no need to cast

Quoted 4 lines · On Friday 24 August 2007 02:20:04 Jesper Juhl wrote:

Since kzalloc() returns a void pointer, we don't need to cast the return value in drivers/media/video/ivtv/ivtv-queue.c

Jesper,

Thanks for the patch. I've applied it to my latest tree and will ask Mauro to pull from it. The latest source is a bit different and has in fact a third cast which I've also removed.

Thanks,

Hans

Quoted 27 lines
---
 drivers/media/video/ivtv/ivtv-queue.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/media/video/ivtv/ivtv-queue.c index a04f938..45825b8 100644

drivers/media/video/ivtv/ivtv-queue.c +1 -2
@@ -196,7 +196,7 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
 		s->name, s->buffers, s->buf_size, s->buffers * s->buf_size /
 1024);
 
 	if (ivtv_might_use_pio(s)) {
-		s->PIOarray = (struct ivtv_SG_element *)kzalloc(SGsize,
 GFP_KERNEL); +		s->PIOarray = kzalloc(SGsize, GFP_KERNEL);
 		if (s->PIOarray == NULL) {
 			IVTV_ERR("Could not allocate PIOarray for %s stream\n", s->name);
 			return -ENOMEM;
@@ -204,7 +204,7 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
 	}
 
 	/* Allocate DMA SG Arrays */
-	s->SGarray = (struct ivtv_SG_element *)kzalloc(SGsize, GFP_KERNEL);
+	s->SGarray = kzalloc(SGsize, GFP_KERNEL);
 	if (s->SGarray == NULL) {
 		IVTV_ERR("Could not allocate SGarray for %s stream\n", s->name);
 		if (ivtv_might_use_pio(s)) {
#44 lore raw

Re: [PATCH 22/30] ivtv: kzalloc() returns void pointer, no need to cast

Quoted 4 lines · Hans Verkuil
Quoted 3 lines · On Friday 24 August 2007 02:20:04 Jesper Juhl wrote:

Since kzalloc() returns a void pointer, we don't need to cast the return value in drivers/media/video/ivtv/ivtv-queue.c

Quoted 8 lines
Quoted 1 line

Jesper,

Thanks for the patch. I've applied it to my latest tree and will ask Mauro to pull from it. The latest source is a bit different and has in fact a third cast which I've also removed.

Perfect, thanks.

Quoted 3 lines

Thanks,

Hans

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#45 lore raw

PATCH 23/30 video: Remove pointless kmalloc() return value cast in Zoran PCI controller driver

In reply to Jesper Juhl

No need to cast the void pointer returned by kmalloc() in drivers/media/video/zoran_driver.c::v4l_fbuffer_alloc().

---
 drivers/media/video/zoran_driver.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
drivers/media/video/zoran_driver.c +1 -4
index 72a037b..bc2e5b3 100644
@@ -347,10 +347,7 @@ v4l_fbuffer_alloc (struct file *file)
 		if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) {
 			/* Use kmalloc */
 
-			mem =
-			    (unsigned char *) kmalloc(fh->v4l_buffers.
-						      buffer_size,
-						      GFP_KERNEL);
+			mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL);
 			if (mem == 0) {
 				dprintk(1,
 					KERN_ERR
Signature · 1 line
1.5.2.2
#46 lore raw

PATCH 24/30 dvb: remove some unneeded vmalloc() return value casts from av7110

In reply to Jesper Juhl

vmalloc() returns void * - no need to cast it.

---
 drivers/media/dvb/ttpci/av7110.c    |    2 +-
 drivers/media/dvb/ttpci/av7110_ir.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/dvb/ttpci/av7110.c +1 -1
index 8178832..27fa5f8 100644
@@ -1543,7 +1543,7 @@ static int get_firmware(struct av7110* av7110)
 	}
 
 	/* check if the firmware is available */
-	av7110->bin_fw = (unsigned char *) vmalloc(fw->size);
+	av7110->bin_fw = vmalloc(fw->size);
 	if (NULL == av7110->bin_fw) {
 		dprintk(1, "out of memory\n");
 		release_firmware(fw);
drivers/media/dvb/ttpci/av7110_ir.c +1 -1
index 6322800..651863b 100644
@@ -280,7 +280,7 @@ static int av7110_ir_write_proc(struct file *file, const char __user *buffer,
 	if (count < size)
 		return -EINVAL;
 
-	page = (char *) vmalloc(size);
+	page = vmalloc(size);
 	if (!page)
 		return -ENOMEM;
 
Signature · 1 line
1.5.2.2
#47 lore raw

PATCH 25/30 tty: dont needlessly cast kmalloc() return value

In reply to Jesper Juhl

kmalloc() hands us a void pointer, we don't need to cast it.

---
 drivers/char/tty_io.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/char/tty_io.c +2 -4
index 51ea93c..9c867cf 100644
@@ -2063,8 +2063,7 @@ static int init_dev(struct tty_driver *driver, int idx,
 	}
 
 	if (!*tp_loc) {
-		tp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						GFP_KERNEL);
+		tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 		if (!tp)
 			goto free_mem_out;
 		*tp = driver->init_termios;
@@ -2094,8 +2093,7 @@ static int init_dev(struct tty_driver *driver, int idx,
 		}
 
 		if (!*o_tp_loc) {
-			o_tp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_tp)
 				goto free_mem_out;
 			*o_tp = driver->other->init_termios;
Signature · 1 line
1.5.2.2
#48 lore raw

PATCH 26/30 md: vmalloc() returns void pointer so we don't need to cast it in dm-ioctl

In reply to Jesper Juhl

In drivers/md/dm-ioctl.c::copy_params() there's a call to vmalloc() where we currently cast the return value, but that's pretty pointles given that vmalloc() returns "void *".

---
 drivers/md/dm-ioctl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/md/dm-ioctl.c +1 -1
index b441d82..efbf9b6 100644
@@ -1358,7 +1358,7 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl **param)
 	if (tmp.data_size < sizeof(tmp))
 		return -EINVAL;
 
-	dmi = (struct dm_ioctl *) vmalloc(tmp.data_size);
+	dmi = vmalloc(tmp.data_size);
 	if (!dmi)
 		return -ENOMEM;
 
Signature · 1 line
1.5.2.2
#49 lore raw

PATCH 27/30 usb: avoid redundant cast of kmalloc() return value in OTi-6858 driver

In reply to Jesper Juhl

In drivers/usb/serial/oti6858.c::pl2303_buf_alloc() the return value of kmalloc() is being cast to "struct pl2303_buf *", but that need not be done here since kmalloc() returns "void *".

---
 drivers/usb/serial/oti6858.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/usb/serial/oti6858.c +1 -1
index d7db71e..fc5e808 100644
@@ -1161,7 +1161,7 @@ static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
 	if (size == 0)
 		return NULL;
 
-	pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
+	pb = kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
 	if (pb == NULL)
 		return NULL;
 
Signature · 1 line
1.5.2.2
#50 lore raw

patch usb-avoid-redundant-cast-of-kmalloc-return-value-in-oti-6858-driver.patch added to gregkh-2.6 tree

This is a note to let you know that I've just added the patch titled

Subject: usb: avoid redundant cast of kmalloc() return value in OTi-6858 driver

to my gregkh-2.6 tree. Its filename is

usb-avoid-redundant-cast-of-kmalloc-return-value-in-oti-6858-driver.patch

This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/

Quoted 1 line

From [email protected] Thu Aug 23 17:38:13 2007

From: Jesper Juhl <[email protected]>
Date: Fri, 24 Aug 2007 02:35:14 +0200
Subject: usb: avoid redundant cast of kmalloc() return value in OTi-6858 driver
To: Linux Kernel Mailing List <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>, Jesper Juhl <[email protected]>
Message-ID: <e71841eb1d00e260fea44d94a4c8a0f950debcfd.1187912217.git.jesper.juhl@gmail.com>
Content-Disposition: inline

In drivers/usb/serial/oti6858.c::pl2303_buf_alloc() the return value of kmalloc() is being cast to "struct pl2303_buf *", but that need not be done here since kmalloc() returns "void *".

---
 drivers/usb/serial/oti6858.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/serial/oti6858.c +1 -1
@@ -1144,7 +1144,7 @@ static struct pl2303_buf *pl2303_buf_all
 	if (size == 0)
 		return NULL;
 
-	pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
+	pb = kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
 	if (pb == NULL)
 		return NULL;
 

Patches currently in gregkh-2.6 which might be from [email protected] are

bad/speakup-kconfig-fix.patch usb/usb-clean-up-duplicate-includes-in-drivers-usb.patch usb/usb-avoid-redundant-cast-of-kmalloc-return-value-in-oti-6858-driver.patch

#51 lore raw

PATCH 28/30 jfs: avoid pointless casts of kmalloc() return val

In reply to Jesper Juhl

There's no need to cast the, void *, return value of kmalloc() when assigning to a pointer variable.

---
 fs/jfs/jfs_dtree.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
fs/jfs/jfs_dtree.c +2 -6
index c14ba3c..3f15b36 100644
@@ -592,9 +592,7 @@ int dtSearch(struct inode *ip, struct component_name * key, ino_t * data,
 	struct component_name ciKey;
 	struct super_block *sb = ip->i_sb;
 
-	ciKey.name =
-	    (wchar_t *) kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
-				GFP_NOFS);
+	ciKey.name = kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t), GFP_NOFS);
 	if (ciKey.name == 0) {
 		rc = -ENOMEM;
 		goto dtSearch_Exit2;
@@ -957,9 +955,7 @@ static int dtSplitUp(tid_t tid,
 	smp = split->mp;
 	sp = DT_PAGE(ip, smp);
 
-	key.name =
-	    (wchar_t *) kmalloc((JFS_NAME_MAX + 2) * sizeof(wchar_t),
-				GFP_NOFS);
+	key.name = kmalloc((JFS_NAME_MAX + 2) * sizeof(wchar_t), GFP_NOFS);
 	if (key.name == 0) {
 		DT_PUTPAGE(smp);
 		rc = -ENOMEM;
Signature · 1 line
1.5.2.2
#52 lore raw

Re: [PATCH 28/30] jfs: avoid pointless casts of kmalloc() return val

Thanks, but Jack Stone submitted the same patch a few weeks ago. It's already in the jfs git tree and the -mm kernel.

Shaggy

Quoted 34 lines · Jesper Juhl

There's no need to cast the, void *, return value of kmalloc() when assigning to a pointer variable.

---
 fs/jfs/jfs_dtree.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
fs/jfs/jfs_dtree.c +2 -6
index c14ba3c..3f15b36 100644
@@ -592,9 +592,7 @@ int dtSearch(struct inode *ip, struct component_name * key, ino_t * data,
 	struct component_name ciKey;
 	struct super_block *sb = ip->i_sb;
 
-	ciKey.name =
-	    (wchar_t *) kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
-				GFP_NOFS);
+	ciKey.name = kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t), GFP_NOFS);
 	if (ciKey.name == 0) {
 		rc = -ENOMEM;
 		goto dtSearch_Exit2;
@@ -957,9 +955,7 @@ static int dtSplitUp(tid_t tid,
 	smp = split->mp;
 	sp = DT_PAGE(ip, smp);
 
-	key.name =
-	    (wchar_t *) kmalloc((JFS_NAME_MAX + 2) * sizeof(wchar_t),
-				GFP_NOFS);
+	key.name = kmalloc((JFS_NAME_MAX + 2) * sizeof(wchar_t), GFP_NOFS);
 	if (key.name == 0) {
 		DT_PUTPAGE(smp);
 		rc = -ENOMEM;
Signature · 2 lines
David Kleikamp
IBM Linux Technology Center
#53 lore raw

Re: [PATCH 28/30] jfs: avoid pointless casts of kmalloc() return val

Quoted 3 lines · Dave Kleikamp

Thanks, but Jack Stone submitted the same patch a few weeks ago. It's already in the jfs git tree and the -mm kernel.

Ok, I wasn't aware of that, but that's perfect.
Sorry for the noise.

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#54 lore raw

PATCH 29/30 mm: No need to cast vmalloc() return value in zone_wait_table_init()

In reply to Jesper Juhl

vmalloc() returns a void pointer, so there's no need to cast its return value in mm/page_alloc.c::zone_wait_table_init().

---
 mm/page_alloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 6427653..a8615c2 100644
@@ -2442,7 +2442,7 @@ int zone_wait_table_init(struct zone *zone, unsigned long zone_size_pages)
 		 * To use this new node's memory, further consideration will be
 		 * necessary.
 		 */
-		zone->wait_table = (wait_queue_head_t *)vmalloc(alloc_size);
+		zone->wait_table = vmalloc(alloc_size);
 	}
 	if (!zone->wait_table)
 		return -ENOMEM;
Signature · 7 lines
1.5.2.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#55 lore raw

PATCH 30/30 emu10k1: There's no need to cast vmalloc() return value in snd_emu10k1_create()

In reply to Jesper Juhl

vmalloc() returns void *. no need to cast.

---
 sound/pci/emu10k1/emu10k1_main.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
sound/pci/emu10k1/emu10k1_main.c +2 -2
index 404ae1b..91d986b 100644
@@ -1722,8 +1722,8 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
 		goto error;
 	}
 
-	emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));
-	emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
+	emu->page_ptr_table = vmalloc(emu->max_cache_pages * sizeof(void *));
+	emu->page_addr_table = vmalloc(emu->max_cache_pages * sizeof(unsigned long));
 	if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
 		err = -ENOMEM;
 		goto error;
Signature · 1 line
1.5.2.2
Applied
#56 lore raw

Re: [PATCH 30/30] emu10k1: There's no need to cast vmalloc() return value in snd_emu10k1_create()

At Fri, 24 Aug 2007 02:41:04 +0200,

Quoted 7 lines · Jesper Juhl

vmalloc() returns void *. no need to cast.

---
 sound/pci/emu10k1/emu10k1_main.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Thanks, applied to ALSA tree.

Takashi

A message that is not in the archive (sent off-list or not yet received): c4e095af9df5ab47e7d1c8e4f3d256d74576a0c9.1187912217.git.jesper.juhl@gmail.com

A message that is not in the archive (sent off-list or not yet received): d551047daed1cb4d9de1eff956268a468c9837f6.1187912217.git.jesper.juhl@gmail.com

#60 lore raw

Re: [PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver

Quoted 3 lines · Jesper Juhl

Since kmalloc() returns a void pointer there is no reason to cast its return value.
This patch also removes a pointless initialization of a variable.

NAK: adds a sparse warning
zd_chip.c:116:15: warning: implicit cast to nocast type

Quoted 29 lines
---
 drivers/net/wireless/zd1211rw/zd_chip.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/wireless/zd1211rw/zd_chip.c +2 -3
index c39f198..4942e5c 100644
@@ -106,8 +106,8 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr
 {
 	int r;
 	int i;
-	zd_addr_t *a16 = (zd_addr_t *)NULL;
 	u16 *v16;
+	zd_addr_t *a16;
 	unsigned int count16;
 
 	if (count > USB_MAX_IOREAD32_COUNT)
@@ -115,8 +115,7 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr
 
 	/* Allocate a single memory block for values and addresses. */
 	count16 = 2*count;
-	a16 = (zd_addr_t *) kmalloc(count16 * (sizeof(zd_addr_t) + sizeof(u16)),
-		                   GFP_KERNEL);
+	a16 = kmalloc(count16 * (sizeof(zd_addr_t) + sizeof(u16)), GFP_KERNEL);
 	if (!a16) {
 		dev_dbg_f(zd_chip_dev(chip),
 			  "error ENOMEM in allocation of a16\n");
#61 lore raw

Re: [PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver

Quoted 8 lines · Daniel Drake
Quoted 3 lines · Jesper Juhl

Since kmalloc() returns a void pointer there is no reason to cast its return value.
This patch also removes a pointless initialization of a variable.

NAK: adds a sparse warning
zd_chip.c:116:15: warning: implicit cast to nocast type

Ok, I must admit I didn't check with sparse since it seemed pointless
- we usually never cast void pointers to other pointer types, specifically because the C language nicely guarantees that the right thing will happen without the cast. Sometimes we have to cast them to
integer types, su sure we need the cast there. But what on earth
makes a "zd_addr_t *" so special that we have to explicitly cast a "void *" to that type?

I see it's defined as
typedef u32 __nocast zd_addr_t;
in drivers/net/wireless/zd1211rw/zd_types.h , but why the __nocast ?

What would be wrong in applying my patch that removes the cast of the kmalloc() return value and then also remove the "__nocast" here?

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#62 lore raw

Re: [PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver

Quoted 7 lines · Jesper Juhl

Ok, I must admit I didn't check with sparse since it seemed pointless
- we usually never cast void pointers to other pointer types, specifically because the C language nicely guarantees that the right thing will happen without the cast. Sometimes we have to cast them to
integer types, su sure we need the cast there. But what on earth
makes a "zd_addr_t *" so special that we have to explicitly cast a "void *" to that type?

http://marc.info/?l=linux-netdev&m=117113743902549&w=1

#63 lore raw

PATCH 1/1 Don't needlessly initialize variable to NULL in zd_chip (was: Re: [PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver)

Quoted 11 lines · On Friday 31 August 2007 00:19:53 Joe Perches wrote:
Quoted 7 lines · Jesper Juhl

Ok, I must admit I didn't check with sparse since it seemed pointless
- we usually never cast void pointers to other pointer types, specifically because the C language nicely guarantees that the right thing will happen without the cast. Sometimes we have to cast them to
integer types, su sure we need the cast there. But what on earth
makes a "zd_addr_t *" so special that we have to explicitly cast a "void *" to that type?

http://marc.info/?l=linux-netdev&m=117113743902549&w=1

Thank you for that link Joe.

I'm not sure I agree with the __nocast, but I respect that this is the maintainers choice.

But, I still think the first chunk of the patch that removes the initial variable initialization makes sense. Initializing the variable to NULL is pointless since it'll never be used before the kmalloc() call. So here's a revised patch that just gets rid of that little detail.

No need to initialize to NULL when variable is never used before it's assigned the return value of a kmalloc() call.

---

drivers/net/wireless/zd1211rw/zd_chip.c +1 -1
index c39f198..30872fe 100644
@@ -106,7 +106,7 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr
 {
 	int r;
 	int i;
-	zd_addr_t *a16 = (zd_addr_t *)NULL;
+	zd_addr_t *a16;
 	u16 *v16;
 	unsigned int count16;
 
#64 lore raw

Re: [PATCH] Don't needlessly initialize variable to NULL in zd_chip (was: Re: [PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver)

Quoted 15 lines · On Fri, 31 Aug 2007 00:30:31 +0200 Jesper Juhl wrote:
Quoted 11 lines · On Friday 31 August 2007 00:19:53 Joe Perches wrote:
Quoted 7 lines · Jesper Juhl

Ok, I must admit I didn't check with sparse since it seemed pointless
- we usually never cast void pointers to other pointer types, specifically because the C language nicely guarantees that the right thing will happen without the cast. Sometimes we have to cast them to
integer types, su sure we need the cast there. But what on earth
makes a "zd_addr_t *" so special that we have to explicitly cast a "void *" to that type?

http://marc.info/?l=linux-netdev&m=117113743902549&w=1

Thank you for that link Joe.

Quoted 8 lines

I'm not sure I agree with the __nocast, but I respect that this is the maintainers choice.

But, I still think the first chunk of the patch that removes the initial variable initialization makes sense. Initializing the variable to NULL is pointless since it'll never be used before the kmalloc() call. So here's a revised patch that just gets rid of that little detail.

BTW: http://marc.info/?l=linux-wireless&m=118831813500769&w=2

Quoted 11 lines

No need to initialize to NULL when variable is never used before it's assigned the return value of a kmalloc() call.

---

drivers/net/wireless/zd1211rw/zd_chip.c +0 -0
index c39f198..30872fe 100644

drivers/net/wireless/zd1211rw/zd_chip.c int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr · line 111

Quoted 7 lines
drivers/net/wireless/zd1211rw/zd_chip.c +1 -1
@@ -106,7 +106,7 @@ int zd_ioread32v_locked(struct zd_chip *chip, u32 *values, const zd_addr_t *addr
 {
 	int r;
 	int i;
-	zd_addr_t *a16 = (zd_addr_t *)NULL;
+	zd_addr_t *a16;
 	u16 *v16;
 	unsigned int count16;

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

#65 lore raw

Re: [PATCH] Don't needlessly initialize variable to NULL in zd_chip (was: Re: [PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver)

On 31/08/2007, Randy Dunlap <[email protected]> wrote:
...

Quoted 3 lines

BTW: http://marc.info/?l=linux-wireless&m=118831813500769&w=2

...

Heh, thanks Randy.

All too often patches get missed since I don't happen to include the right magic person to Cc. So I generally take a "better to have one Cc too many than miss one" approach when sending patches - otherwise I just end up resending it several times and eventually have to bother Andrew to move it through -mm.

I see the point of people not getting things twice, but too many patches slip through the cracks already (and not just my patches, that's a general problem) so I'd rather inconvenience a few people with one extra email than missing the proper maintainer by not Cc'ing
the right list. Picking the right list/set of people to Cc is hard!

(whoops, mistakenly didn't do a reply-to-all initially; sorry Randy, now you'll get this mail twice ;)

--
Jesper Juhl <[email protected]> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html

#66 lore raw

Re: [PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver

In reply to Jesper Juhl
Quoted 2 lines · Jesper Juhl

What would be wrong in applying my patch that removes the cast of the kmalloc() return value and then also remove the "__nocast" here?

We use it as a safety measure when coding. For example the write register function takes an address and a value. We got one of these the wrong way round once, and had a non-obvious bug.

nocast and sparse helps us prevent this.

Daniel

#67 lore raw

Re: [PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver

In reply to Jesper Juhl
Quoted 17 lines · Jesper Juhl
Quoted 8 lines · Daniel Drake
Quoted 3 lines · Jesper Juhl

Since kmalloc() returns a void pointer there is no reason to cast its return value.
This patch also removes a pointless initialization of a variable.

NAK: adds a sparse warning
zd_chip.c:116:15: warning: implicit cast to nocast type

Ok, I must admit I didn't check with sparse since it seemed pointless
- we usually never cast void pointers to other pointer types, specifically because the C language nicely guarantees that the right thing will happen without the cast. Sometimes we have to cast them to
integer types, su sure we need the cast there. But what on earth
makes a "zd_addr_t *" so special that we have to explicitly cast a "void *" to that type?

Quoted 3 lines

I see it's defined as
typedef u32 __nocast zd_addr_t;
in drivers/net/wireless/zd1211rw/zd_types.h , but why the __nocast ?

Nevermind the __nocast, this looks like a bug in sparse. Just because a base type is __nocast, sparse shouldn't infer that a pointer to it should also be __nocast.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt