2007-08-23 23:39:00

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 0/30] Remove unneeded casts of [kv][mzc]alloc() return values

Hi,

The [kv][mzc]alloc() functions return a void pointer, so when
assigning to a pointer type variable there is no need to cast
the return value.

This is something that is already commonly being cleaned up when
people change nearby code and it's also something people are
usually asked not to do when submitting new code.

I took a look at how many such casts are currently left and didn't
find that many, so I cleaned them up.
I've probably missed some, but this patch series should clean up
the majority of the remaining ones at least.

The patches in this series are

[PATCH 1/30] ia64: Remove unnecessary cast of allocation return value in sn_hwperf_enum_objects()
[PATCH 1/30] cris: Remove unnecessary cast of allocation return value in intmem.c
[PATCH 1/30] um: Don't unnecessarily cast allocation return value in ubd_kern.c
[PATCH 1/30] powerpc: Don't cast kmalloc return value in ibmebus.c
[PATCH 1/30] atm: No need to cast vmalloc() return value
[PATCH 1/30] i2o: No need to cast kmalloc() return value in cfg_open()
[PATCH 1/30] mtd: Get rid of pointless cast of kzalloc() return value in AT26xxx driver
[PATCH 1/30] mtd: Avoid a pointless kmalloc() return value cast in TQM8xxL mapping handling code
[PATCH 1/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
[PATCH 1/30] irda: Do not do pointless kmalloc return value cast in KingSun driver
[PATCH 1/30] net: No need to cast vmalloc() return values in NetXen NIC driver
[PATCH 1/30] net: No point in casting kmalloc return values in Gianfar Ethernet Driver
[PATCH 1/30] net: Don't do pointless kmalloc return value casts in zd1211 driver
[PATCH 1/30] net: Kill some unneeded allocation return value casts in libertas
[PATCH 1/30] net: No need to cast kmalloc() return value in ipw2100 driver
[PATCH 1/30] net: Avoid pointless allocation casts in BSD compression module
[PATCH 1/30] isdn: Get rid of some pointless allocation casts in common and bsd comp.
[PATCH 1/30] isdn: eicon - get rid of a pointless vmalloc() return value cast
[PATCH 1/30] scsi: Remove explicit casts of [kv]alloc return values in osst driver
[PATCH 1/30] scsi: In the Advansys driver, do not cast allocation function return values
[PATCH 1/30] oss: Remove unneeded vmalloc() return value casts in OSS
[PATCH 1/30] ivtv: kzalloc() returns void pointer, no need to cast
[PATCH 1/30] video: Remove pointless kmalloc() return value cast in Zoran PCI controller driver
[PATCH 1/30] dvb: remove some unneeded vmalloc() return value casts from av7110
[PATCH 1/30] tty: dont needlessly cast kmalloc() return value
[PATCH 1/30] md: vmalloc() returns void pointer so we don't need to cast it in dm-ioctl
[PATCH 1/30] usb: avoid redundant cast of kmalloc() return value in OTi-6858 driver
[PATCH 1/30] jfs: avoid pointless casts of kmalloc() return val
[PATCH 1/30] mm: No need to cast vmalloc() return value in zone_wait_table_init()
[PATCH 1/30] emu10k1: There's no need to cast vmalloc() return value in snd_emu10k1_create()

I'll send them all as replies to this email, to LKML and maintainers.


Kind regards,
Jesper


2007-08-23 23:43:29

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 01/30] ia64: Remove unnecessary cast of allocation return value in sn_hwperf_enum_objects()

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

Signed-off-by: Jesper Juhl <[email protected]>
---
arch/ia64/sn/kernel/sn2/sn_hwperf.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/ia64/sn/kernel/sn2/sn_hwperf.c b/arch/ia64/sn/kernel/sn2/sn_hwperf.c
index df8d5be..1a8e496 100644
--- a/arch/ia64/sn/kernel/sn2/sn_hwperf.c
+++ b/arch/ia64/sn/kernel/sn2/sn_hwperf.c
@@ -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;
--
1.5.2.2

2007-08-23 23:45:22

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 02/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.

Signed-off-by: Jesper Juhl <[email protected]>
---
arch/cris/arch-v32/mm/intmem.c | 10 ++++------
1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/cris/arch-v32/mm/intmem.c b/arch/cris/arch-v32/mm/intmem.c
index 41ee7f7..691cf3b 100644
--- a/arch/cris/arch-v32/mm/intmem.c
+++ b/arch/cris/arch-v32/mm/intmem.c
@@ -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;
--
1.5.2.2

2007-08-23 23:46:50

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
arch/um/drivers/ubd_kern.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 0eabe73..25b248a 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -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;
--
1.5.2.2

2007-08-23 23:48:16

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 04/30] powerpc: Don't cast kmalloc return value in ibmebus.c

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

Signed-off-by: Jesper Juhl <[email protected]>
---
arch/powerpc/kernel/ibmebus.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
index 9a8c9af..9514e66 100644
--- a/arch/powerpc/kernel/ibmebus.c
+++ b/arch/powerpc/kernel/ibmebus.c
@@ -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;

--
1.5.2.2

2007-08-23 23:49:47

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 05/30] atm: No need to cast vmalloc() return value

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/atm/lanai.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
index 144a49f..59e7dde 100644
--- a/drivers/atm/lanai.c
+++ b/drivers/atm/lanai.c
@@ -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);
--
1.5.2.2

2007-08-23 23:51:39

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 06/30] i2o: No need to cast kmalloc() return value in cfg_open()

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/message/i2o/i2o_config.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index 84e046e..fb8c668 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -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;
--
1.5.2.2

2007-08-23 23:53:42

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 07/30] mtd: Get rid of pointless cast of kzalloc() return value in AT26xxx driver

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/mtd/devices/at91_dataflash26.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/devices/at91_dataflash26.c b/drivers/mtd/devices/at91_dataflash26.c
index 64ce37f..9c4aac4 100644
--- a/drivers/mtd/devices/at91_dataflash26.c
+++ b/drivers/mtd/devices/at91_dataflash26.c
@@ -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;
--
1.5.2.2

2007-08-23 23:54:47

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 08/30] mtd: Avoid a pointless kmalloc() return value cast in TQM8xxL mapping handling code

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/mtd/maps/tqm8xxl.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 37e4ded..1d75ce4 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -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? */
--
1.5.2.2

2007-08-23 23:55:59

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/mtd/maps/pmcmsp-flash.c | 13 +++++--------
1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c
index 7e0377e..dfdb120 100644
--- a/drivers/mtd/maps/pmcmsp-flash.c
+++ b/drivers/mtd/maps/pmcmsp-flash.c
@@ -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 */
--
1.5.2.2

2007-08-23 23:57:27

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/net/irda/kingsun-sir.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/irda/kingsun-sir.c b/drivers/net/irda/kingsun-sir.c
index bdd5c97..4e5101a 100644
--- a/drivers/net/irda/kingsun-sir.c
+++ b/drivers/net/irda/kingsun-sir.c
@@ -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;

--
1.5.2.2

2007-08-24 00:06:54

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/net/wireless/libertas/debugfs.c | 2 +-
drivers/net/wireless/libertas/ethtool.c | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
index 715cbda..6ade63e 100644
--- a/drivers/net/wireless/libertas/debugfs.c
+++ b/drivers/net/wireless/libertas/debugfs.c
@@ -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;

diff --git a/drivers/net/wireless/libertas/ethtool.c b/drivers/net/wireless/libertas/ethtool.c
index 96f1974..7dad493 100644
--- a/drivers/net/wireless/libertas/ethtool.c
+++ b/drivers/net/wireless/libertas/ethtool.c
@@ -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));
--
1.5.2.2

2007-08-24 00:10:06

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/net/bsd_comp.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bsd_comp.c b/drivers/net/bsd_comp.c
index 202d4a4..88edb98 100644
--- a/drivers/net/bsd_comp.c
+++ b/drivers/net/bsd_comp.c
@@ -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);
--
1.5.2.2

2007-08-24 00:12:45

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/isdn/i4l/isdn_bsdcomp.c | 5 ++---
drivers/isdn/i4l/isdn_common.c | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/isdn/i4l/isdn_bsdcomp.c b/drivers/isdn/i4l/isdn_bsdcomp.c
index 90a2379..02d9918 100644
--- a/drivers/isdn/i4l/isdn_bsdcomp.c
+++ b/drivers/isdn/i4l/isdn_bsdcomp.c
@@ -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);
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index c97330b..ec5f404 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -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;
}
--
1.5.2.2

2007-08-24 00:14:15

by Jesper Juhl

[permalink] [raw]
Subject: [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()

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/isdn/hardware/eicon/platform.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/isdn/hardware/eicon/platform.h b/drivers/isdn/hardware/eicon/platform.h
index 15d4942..8756ef1 100644
--- a/drivers/isdn/hardware/eicon/platform.h
+++ b/drivers/isdn/hardware/eicon/platform.h
@@ -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);
}
--
1.5.2.2

2007-08-24 00:19:30

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/scsi/osst.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 08060fb..3ad9d49 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -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);
--
1.5.2.2

2007-08-24 00:19:53

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/scsi/advansys.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 79c0b6e..b28729c 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -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;
}
--
1.5.2.2

2007-08-24 00:21:32

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 21/30] oss: Remove unneeded vmalloc() return value casts in OSS

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

Signed-off-by: Jesper Juhl <[email protected]>
---
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(-)

diff --git a/sound/oss/midibuf.c b/sound/oss/midibuf.c
index a40be0c..66f8a7f 100644
--- a/sound/oss/midibuf.c
+++ b/sound/oss/midibuf.c
@@ -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)
{
diff --git a/sound/oss/pss.c b/sound/oss/pss.c
index ece428b..b140584 100644
--- a/sound/oss/pss.c
+++ b/sound/oss/pss.c
@@ -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;
diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c
index 5c215f7..cfe3dd0 100644
--- a/sound/oss/sequencer.c
+++ b/sound/oss/sequencer.c
@@ -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");
diff --git a/sound/oss/sscape.c b/sound/oss/sscape.c
index 30c36d1..9d6b9b0 100644
--- a/sound/oss/sscape.c
+++ b/sound/oss/sscape.c
@@ -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)))
--
1.5.2.2

2007-08-24 00:22:44

by Jeff Dike

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

On Fri, Aug 24, 2007 at 01:43:49AM +0200, Jesper Juhl wrote:
> vmalloc() returns a void pointer, so casting to (void *) is pretty pointless.

Righto, I'll take care of this.

Jeff

--
Work email - jdike at linux dot intel dot com

2007-08-24 00:23:31

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/media/video/ivtv/ivtv-queue.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/video/ivtv/ivtv-queue.c b/drivers/media/video/ivtv/ivtv-queue.c
index a04f938..45825b8 100644
--- a/drivers/media/video/ivtv/ivtv-queue.c
+++ b/drivers/media/video/ivtv/ivtv-queue.c
@@ -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)) {
--
1.5.2.2

2007-08-24 00:25:23

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 23/30] video: Remove pointless kmalloc() return value cast in Zoran PCI controller driver

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/media/video/zoran_driver.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 72a037b..bc2e5b3 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -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
--
1.5.2.2

2007-08-24 00:28:42

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 24/30] dvb: remove some unneeded vmalloc() return value casts from av7110

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/media/dvb/ttpci/av7110.c | 2 +-
drivers/media/dvb/ttpci/av7110_ir.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 8178832..27fa5f8 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -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);
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index 6322800..651863b 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -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;

--
1.5.2.2

2007-08-24 00:31:43

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 25/30] tty: dont needlessly cast kmalloc() return value

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

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/char/tty_io.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 51ea93c..9c867cf 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -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;
--
1.5.2.2

2007-08-24 00:33:46

by Jesper Juhl

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

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 *".

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/md/dm-ioctl.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index b441d82..efbf9b6 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -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;

--
1.5.2.2

2007-08-24 00:38:16

by Joachim Fenkes

[permalink] [raw]
Subject: Re: [PATCH 04/30] powerpc: Don't cast kmalloc return value in ibmebus.c

> kmalloc() returns a void pointer so there is absolutely no need to
> cast it in ibmebus_chomp().
>
> Signed-off-by: Jesper Juhl <[email protected]>

Acked-By: Joachim Fenkes <[email protected]>

2007-08-24 00:38:36

by Jesper Juhl

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

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 *".

Signed-off-by: Jesper Juhl <[email protected]>
---
drivers/usb/serial/oti6858.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index d7db71e..fc5e808 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -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;

--
1.5.2.2

2007-08-24 00:39:46

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
fs/jfs/jfs_dtree.c | 8 ++------
1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index c14ba3c..3f15b36 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -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;
--
1.5.2.2

2007-08-24 00:42:38

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH 29/30] mm: No need to cast vmalloc() return value in zone_wait_table_init()

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

Signed-off-by: Jesper Juhl <[email protected]>
---
mm/page_alloc.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6427653..a8615c2 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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;
--
1.5.2.2

2007-08-24 00:44:17

by Jesper Juhl

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

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

Signed-off-by: Jesper Juhl <[email protected]>
---
sound/pci/emu10k1/emu10k1_main.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 404ae1b..91d986b 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -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;
--
1.5.2.2

2007-08-24 00:56:57

by Jesper Juhl

[permalink] [raw]
Subject: Re: [PATCH 0/30] Remove unneeded casts of [kv][mzc]alloc() return values

On 24/08/07, Jesper Juhl <[email protected]> wrote:
[snip]
> The patches in this series are
>
Damn, I managed to mess up that list. Here's how it should have looked :

[PATCH 01/30] ia64: Remove unnecessary cast of allocation return value in sn_hwperf_enum_objects()
[PATCH 02/30] cris: Remove unnecessary cast of allocation return value in intmem.c
[PATCH 03/30] um: Don't unnecessarily cast allocation return value in ubd_kern.c
[PATCH 04/30] powerpc: Don't cast kmalloc return value in ibmebus.c
[PATCH 05/30] atm: No need to cast vmalloc() return value
[PATCH 06/30] i2o: No need to cast kmalloc() return value in cfg_open()
[PATCH 07/30] mtd: Get rid of pointless cast of kzalloc() return value in AT26xxx driver
[PATCH 08/30] mtd: Avoid a pointless kmalloc() return value cast in TQM8xxL mapping handling code
[PATCH 09/30] mtd: Don't cast kmalloc() return value in drivers/mtd/maps/pmcmsp-flash.c
[PATCH 10/30] irda: Do not do pointless kmalloc return value cast in KingSun driver
[PATCH 11/30] net: No need to cast vmalloc() return values in NetXen NIC driver
[PATCH 12/30] net: No point in casting kmalloc return values in Gianfar Ethernet Driver
[PATCH 13/30] net: Don't do pointless kmalloc return value casts in zd1211 driver
[PATCH 14/30] net: Kill some unneeded allocation return value casts in libertas
[PATCH 15/30] net: No need to cast kmalloc() return value in ipw2100 driver
[PATCH 16/30] net: Avoid pointless allocation casts in BSD compression module
[PATCH 17/30] isdn: Get rid of some pointless allocation casts in common and bsd comp.
[PATCH 18/30] isdn: eicon - get rid of a pointless vmalloc() return value cast
[PATCH 19/30] scsi: Remove explicit casts of [kv]alloc return values in osst driver
[PATCH 20/30] scsi: In the Advansys driver, do not cast allocation function return values
[PATCH 21/30] oss: Remove unneeded vmalloc() return value casts in OSS
[PATCH 22/30] ivtv: kzalloc() returns void pointer, no need to cast
[PATCH 23/30] video: Remove pointless kmalloc() return value cast in Zoran PCI controller driver
[PATCH 24/30] dvb: remove some unneeded vmalloc() return value casts from av7110
[PATCH 25/30] tty: dont needlessly cast kmalloc() return value
[PATCH 26/30] md: vmalloc() returns void pointer so we don't need to cast it in dm-ioctl
[PATCH 27/30] usb: avoid redundant cast of kmalloc() return value in OTi-6858 driver
[PATCH 28/30] jfs: avoid pointless casts of kmalloc() return val
[PATCH 29/30] mm: No need to cast vmalloc() return value in zone_wait_table_init()
[PATCH 30/30] emu10k1: There's no need to cast vmalloc() return value in snd_emu10k1_create()

Kind regards,
Jesper

2007-08-24 02:04:03

by Matthew Wilcox

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

On Fri, Aug 24, 2007 at 02:16:12AM +0200, Jesper Juhl wrote:
> 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.

--
"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."

2007-08-24 04:20:03

by Dave Kleikamp

[permalink] [raw]
Subject: 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

On Fri, 2007-08-24 at 02:36 +0200, Jesper Juhl wrote:
> There's no need to cast the, void *, return value of kmalloc() when
> assigning to a pointer variable.
>
> Signed-off-by: Jesper Juhl <[email protected]>
> ---
> fs/jfs/jfs_dtree.c | 8 ++------
> 1 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
> index c14ba3c..3f15b36 100644
> --- a/fs/jfs/jfs_dtree.c
> +++ b/fs/jfs/jfs_dtree.c
> @@ -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;
--
David Kleikamp
IBM Linux Technology Center

2007-08-24 07:11:59

by Rolf Eike Beer

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

Jesper Juhl wrote:
> [kv]alloc() return void *. No need to cast the return value.

> @@ -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


Attachments:
(No filename) (658.00 B)
signature.asc (189.00 B)
This is a digitally signed message part.
Download all attachments

2007-08-24 07:21:57

by Armin Schindler

[permalink] [raw]
Subject: 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()

Signed-off-by: Jesper Juhl <[email protected]>
Acked-by: Armin Schindler <[email protected]>
---
drivers/isdn/hardware/eicon/platform.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/isdn/hardware/eicon/platform.h b/drivers/isdn/hardware/eicon/platform.h
index 15d4942..8756ef1 100644
--- a/drivers/isdn/hardware/eicon/platform.h
+++ b/drivers/isdn/hardware/eicon/platform.h
@@ -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);
}
--
1.5.2.2

2007-08-24 08:32:29

by Hans Verkuil

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

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
>
> Signed-off-by: Jesper Juhl <[email protected]>

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

> ---
> drivers/media/video/ivtv/ivtv-queue.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/video/ivtv/ivtv-queue.c
> b/drivers/media/video/ivtv/ivtv-queue.c index a04f938..45825b8 100644
> --- a/drivers/media/video/ivtv/ivtv-queue.c
> +++ b/drivers/media/video/ivtv/ivtv-queue.c
> @@ -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)) {


2007-08-24 08:45:26

by Jesper Juhl

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

On 24/08/07, Hans Verkuil <[email protected]> wrote:
> 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
> >
> > Signed-off-by: Jesper Juhl <[email protected]>
>
> 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.

> Thanks,
>
> Hans

--
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

2007-08-24 08:47:18

by Jesper Juhl

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

On 24/08/07, Rolf Eike Beer <[email protected]> wrote:
> Jesper Juhl wrote:
> > [kv]alloc() return void *. No need to cast the return value.
>
> > @@ -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);
>

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).


> Eike

--
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

2007-08-24 08:49:18

by Jesper Juhl

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

On 24/08/07, Dave Kleikamp <[email protected]> wrote:
> 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.


--
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

2007-08-24 09:00:55

by Jesper Juhl

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

On 24/08/07, Matthew Wilcox <[email protected]> wrote:
> On Fri, Aug 24, 2007 at 02:16:12AM +0200, Jesper Juhl wrote:
> > 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.

--
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

2007-08-24 09:23:17

by Karsten Keil

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

On Fri, Aug 24, 2007 at 02:09:34AM +0200, Jesper Juhl wrote:
> vmalloc() returns a void pointer - no need to cast the return value.
>
> Signed-off-by: Jesper Juhl <[email protected]>

Acked-by: Karsten Keil <[email protected]>
> ---
> drivers/isdn/i4l/isdn_bsdcomp.c | 5 ++---
> drivers/isdn/i4l/isdn_common.c | 2 +-
> 2 files changed, 3 insertions(+), 4 deletions(-)
>
...
--
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)

2007-08-24 10:41:25

by Denys Vlasenko

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

On Friday 24 August 2007 00:52, Jesper Juhl wrote:
> kmalloc() returns a void pointer.
> No need to cast it.

> - 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.

> - 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

2007-08-24 10:49:09

by Jesper Juhl

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

On 24/08/07, Denys Vlasenko <[email protected]> wrote:
> On Friday 24 August 2007 00:52, Jesper Juhl wrote:
> > kmalloc() returns a void pointer.
> > No need to cast it.
>
> > - 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.
>
> > - 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

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).

--
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

2007-08-24 10:53:36

by Robert P. J. Day

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

On Fri, 24 Aug 2007, Denys Vlasenko wrote:

> On Friday 24 August 2007 00:52, Jesper Juhl wrote:
> > kmalloc() returns a void pointer.
> > No need to cast it.
>
> > - 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.
>
> > - 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

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

rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

2007-08-24 15:55:32

by Dan Williams

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

On Fri, 2007-08-24 at 02:03 +0200, Jesper Juhl wrote:
> kmalloc() and friends return void*, no need to cast it.

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

Dan

> Signed-off-by: Jesper Juhl <[email protected]>
> ---
> drivers/net/wireless/libertas/debugfs.c | 2 +-
> drivers/net/wireless/libertas/ethtool.c | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
> index 715cbda..6ade63e 100644
> --- a/drivers/net/wireless/libertas/debugfs.c
> +++ b/drivers/net/wireless/libertas/debugfs.c
> @@ -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;
>
> diff --git a/drivers/net/wireless/libertas/ethtool.c b/drivers/net/wireless/libertas/ethtool.c
> index 96f1974..7dad493 100644
> --- a/drivers/net/wireless/libertas/ethtool.c
> +++ b/drivers/net/wireless/libertas/ethtool.c
> @@ -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));

2007-08-25 04:45:37

by Greg KH

[permalink] [raw]
Subject: 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/


>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 *".

Signed-off-by: Jesper Juhl <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
drivers/usb/serial/oti6858.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -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

2007-08-25 06:24:09

by David Miller

[permalink] [raw]
Subject: 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

> kmalloc() returns a void pointer, so there is no need to cast it in
> drivers/net/irda/kingsun-sir.c::kingsun_probe().
>
> Signed-off-by: Jesper Juhl <[email protected]>

Applied.

2007-08-25 06:25:18

by David Miller

[permalink] [raw]
Subject: 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

> The general kernel memory allocation functions return void pointers
> and there is no need to cast their return values.
>
> Signed-off-by: Jesper Juhl <[email protected]>

Applied.

2007-08-25 06:25:59

by David Miller

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

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

> vmalloc() returns a void pointer - no need to cast the return value.
>
> Signed-off-by: Jesper Juhl <[email protected]>

Applied, thanks.

2007-08-25 22:27:36

by Jesper Juhl

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

On 24/08/07, Robert P. J. Day <[email protected]> wrote:
> On Fri, 24 Aug 2007, Denys Vlasenko wrote:
>
> > On Friday 24 August 2007 00:52, Jesper Juhl wrote:
> > > kmalloc() returns a void pointer.
> > > No need to cast it.
> >
> > > - 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.
> >
> > > - 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
>
> 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);


--
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

2007-08-26 00:10:13

by Robert P. J. Day

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

On Sun, 26 Aug 2007, Jesper Juhl wrote:

> On 24/08/07, Robert P. J. Day <[email protected]> wrote:

> > 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);

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

--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

2007-08-26 00:28:53

by Jesper Juhl

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

On 26/08/07, Robert P. J. Day <[email protected]> wrote:
> On Sun, 26 Aug 2007, Jesper Juhl wrote:
>
> > On 24/08/07, Robert P. J. Day <[email protected]> wrote:
>
> > > 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);
>
> 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

> 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?

--
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

2007-08-26 00:33:31

by Robert P. J. Day

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

On Sun, 26 Aug 2007, Jesper Juhl wrote:

> On 26/08/07, Robert P. J. Day <[email protected]> wrote:

> > 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
>
> > 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?

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
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

2007-08-26 00:36:41

by Jesper Juhl

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

On 26/08/07, Robert P. J. Day <[email protected]> wrote:
> On Sun, 26 Aug 2007, Jesper Juhl wrote:
>
> > On 26/08/07, Robert P. J. Day <[email protected]> wrote:
>
> > > 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
> >
> > > 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?
>
> 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.

--
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

2007-08-26 01:53:57

by Kyle Moffett

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

On Aug 25, 2007, at 20:36:32, Jesper Juhl wrote:
> On 26/08/07, Robert P. J. Day <[email protected]> wrote:
>> 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


2007-08-26 14:29:19

by Denys Vlasenko

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

On Sunday 26 August 2007 01:23, Robert P. J. Day wrote:
> On Sun, 26 Aug 2007, Jesper Juhl wrote:
> > On 26/08/07, Robert P. J. Day <[email protected]> wrote:
> > > 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
> >
> > > 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?
>
> 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

2007-08-26 14:37:26

by Jan Engelhardt

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


On Aug 26 2007 15:28, Denys Vlasenko wrote:
>> >
>> > 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.

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


Jan
--

2007-08-26 22:10:30

by Jesper Juhl

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

On 26/08/07, Jan Engelhardt <[email protected]> wrote:
>
> On Aug 26 2007 15:28, Denys Vlasenko wrote:
> >> >
> >> > 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.
>
> >calloc(-1, 10000000) => easy to detect
> >malloc(-1 * 10000000) => malloc(-10000000) => not so trivial
>
Ok, that makes a bit of sense. Thank you.


--
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

2007-08-28 13:23:01

by Takashi Iwai

[permalink] [raw]
Subject: 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,
Jesper Juhl wrote:
>
> vmalloc() returns void *. no need to cast.
>
> Signed-off-by: Jesper Juhl <[email protected]>
> ---
> sound/pci/emu10k1/emu10k1_main.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)

Thanks, applied to ALSA tree.


Takashi