some kmalloc/memset ->kzalloc (tree wide)

Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).

Here is a short excerpt of the semantic patch performing
this transformation:

@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@

 x =
- kmalloc
+ kzalloc
  (E1,E2)
  ...  when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);

@@
expression E1,E2,E3;
@@

- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)

[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Yoann Padioleau
2007-07-19 01:49:03 -07:00
committed by Linus Torvalds
parent 3b5ad0797c
commit dd00cc486a
136 changed files with 157 additions and 330 deletions
+1 -2
View File
@@ -124,9 +124,8 @@ static void cn_test_timer_func(unsigned long __data)
struct cn_msg *m; struct cn_msg *m;
char data[32]; char data[32];
m = kmalloc(sizeof(*m) + sizeof(data), GFP_ATOMIC); m = kzalloc(sizeof(*m) + sizeof(data), GFP_ATOMIC);
if (m) { if (m) {
memset(m, 0, sizeof(*m) + sizeof(data));
memcpy(&m->id, &cn_test_id, sizeof(m->id)); memcpy(&m->id, &cn_test_id, sizeof(m->id));
m->seq = cn_test_timer_counter; m->seq = cn_test_timer_counter;
@@ -277,11 +277,10 @@ static struct config_item *simple_children_make_item(struct config_group *group,
{ {
struct simple_child *simple_child; struct simple_child *simple_child;
simple_child = kmalloc(sizeof(struct simple_child), GFP_KERNEL); simple_child = kzalloc(sizeof(struct simple_child), GFP_KERNEL);
if (!simple_child) if (!simple_child)
return NULL; return NULL;
memset(simple_child, 0, sizeof(struct simple_child));
config_item_init_type_name(&simple_child->item, name, config_item_init_type_name(&simple_child->item, name,
&simple_child_type); &simple_child_type);
@@ -364,12 +363,11 @@ static struct config_group *group_children_make_group(struct config_group *group
{ {
struct simple_children *simple_children; struct simple_children *simple_children;
simple_children = kmalloc(sizeof(struct simple_children), simple_children = kzalloc(sizeof(struct simple_children),
GFP_KERNEL); GFP_KERNEL);
if (!simple_children) if (!simple_children)
return NULL; return NULL;
memset(simple_children, 0, sizeof(struct simple_children));
config_group_init_type_name(&simple_children->group, name, config_group_init_type_name(&simple_children->group, name,
&simple_children_type); &simple_children_type);
+1 -2
View File
@@ -119,8 +119,7 @@ module_frob_arch_sections(Elf64_Ehdr *hdr, Elf64_Shdr *sechdrs,
} }
nsyms = symtab->sh_size / sizeof(Elf64_Sym); nsyms = symtab->sh_size / sizeof(Elf64_Sym);
chains = kmalloc(nsyms * sizeof(struct got_entry), GFP_KERNEL); chains = kcalloc(nsyms, sizeof(struct got_entry), GFP_KERNEL);
memset(chains, 0, nsyms * sizeof(struct got_entry));
got->sh_size = 0; got->sh_size = 0;
got->sh_addralign = 8; got->sh_addralign = 8;
+1 -2
View File
@@ -1002,11 +1002,10 @@ int iop13xx_pci_setup(int nr, struct pci_sys_data *sys)
if (nr > 1) if (nr > 1)
return 0; return 0;
res = kmalloc(sizeof(struct resource) * 2, GFP_KERNEL); res = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
if (!res) if (!res)
panic("PCI: unable to alloc resources"); panic("PCI: unable to alloc resources");
memset(res, 0, sizeof(struct resource) * 2);
/* 'nr' assumptions: /* 'nr' assumptions:
* ATUX is always 0 * ATUX is always 0
+1 -2
View File
@@ -521,10 +521,9 @@ void *sram_alloc_with_lsl(size_t size, unsigned long flags)
struct sram_list_struct *lsl = NULL; struct sram_list_struct *lsl = NULL;
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
lsl = kmalloc(sizeof(struct sram_list_struct), GFP_KERNEL); lsl = kzalloc(sizeof(struct sram_list_struct), GFP_KERNEL);
if (!lsl) if (!lsl)
return NULL; return NULL;
memset(lsl, 0, sizeof(*lsl));
if (flags & L1_INST_SRAM) if (flags & L1_INST_SRAM)
addr = l1_inst_sram_alloc(size); addr = l1_inst_sram_alloc(size);
+2 -4
View File
@@ -91,14 +91,12 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
if (!mem_base) if (!mem_base)
goto out; goto out;
dev->dma_mem = kmalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL); dev->dma_mem = kzalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL);
if (!dev->dma_mem) if (!dev->dma_mem)
goto out; goto out;
memset(dev->dma_mem, 0, sizeof(struct dma_coherent_mem)); dev->dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
dev->dma_mem->bitmap = kmalloc(bitmap_size, GFP_KERNEL);
if (!dev->dma_mem->bitmap) if (!dev->dma_mem->bitmap)
goto free1_out; goto free1_out;
memset(dev->dma_mem->bitmap, 0, bitmap_size);
dev->dma_mem->virt_base = mem_base; dev->dma_mem->virt_base = mem_base;
dev->dma_mem->device_base = device_addr; dev->dma_mem->device_base = device_addr;
+1 -2
View File
@@ -248,7 +248,7 @@ static void parse_system_parameter_string(struct seq_file *m)
} else { } else {
int splpar_strlen; int splpar_strlen;
int idx, w_idx; int idx, w_idx;
char *workbuffer = kmalloc(SPLPAR_MAXLENGTH, GFP_KERNEL); char *workbuffer = kzalloc(SPLPAR_MAXLENGTH, GFP_KERNEL);
if (!workbuffer) { if (!workbuffer) {
printk(KERN_ERR "%s %s kmalloc failure at line %d \n", printk(KERN_ERR "%s %s kmalloc failure at line %d \n",
__FILE__, __FUNCTION__, __LINE__); __FILE__, __FUNCTION__, __LINE__);
@@ -261,7 +261,6 @@ static void parse_system_parameter_string(struct seq_file *m)
splpar_strlen = local_buffer[0] * 256 + local_buffer[1]; splpar_strlen = local_buffer[0] * 256 + local_buffer[1];
local_buffer += 2; /* step over strlen value */ local_buffer += 2; /* step over strlen value */
memset(workbuffer, 0, SPLPAR_MAXLENGTH);
w_idx = 0; w_idx = 0;
idx = 0; idx = 0;
while ((*local_buffer) && (idx < splpar_strlen)) { while ((*local_buffer) && (idx < splpar_strlen)) {
+1 -2
View File
@@ -222,10 +222,9 @@ struct of_device* of_platform_device_create(struct device_node *np,
{ {
struct of_device *dev; struct of_device *dev;
dev = kmalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return NULL; return NULL;
memset(dev, 0, sizeof(*dev));
dev->node = of_node_get(np); dev->node = of_node_get(np);
dev->dma_mask = 0xffffffffUL; dev->dma_mask = 0xffffffffUL;
+1 -2
View File
@@ -436,11 +436,10 @@ int sg_scsi_ioctl(struct file *file, struct request_queue *q,
bytes = max(in_len, out_len); bytes = max(in_len, out_len);
if (bytes) { if (bytes) {
buffer = kmalloc(bytes, q->bounce_gfp | GFP_USER| __GFP_NOWARN); buffer = kzalloc(bytes, q->bounce_gfp | GFP_USER| __GFP_NOWARN);
if (!buffer) if (!buffer)
return -ENOMEM; return -ENOMEM;
memset(buffer, 0, bytes);
} }
rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT); rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT);
+1 -2
View File
@@ -1608,7 +1608,7 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
} }
#endif #endif
host = kmalloc(sizeof(*host), GFP_KERNEL); host = kzalloc(sizeof(*host), GFP_KERNEL);
if (!host) { if (!host) {
printk(KERN_ERR DRV_NAME "(%s): memory alloc failure\n", printk(KERN_ERR DRV_NAME "(%s): memory alloc failure\n",
pci_name(pdev)); pci_name(pdev));
@@ -1616,7 +1616,6 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
goto err_out_regions; goto err_out_regions;
} }
memset(host, 0, sizeof(*host));
host->pdev = pdev; host->pdev = pdev;
host->flags = pci_dac ? FL_DAC : 0; host->flags = pci_dac ? FL_DAC : 0;
spin_lock_init(&host->lock); spin_lock_init(&host->lock);
+1 -2
View File
@@ -1721,12 +1721,11 @@ static int get_async_struct(int line, struct async_struct **ret_info)
*ret_info = sstate->info; *ret_info = sstate->info;
return 0; return 0;
} }
info = kmalloc(sizeof(struct async_struct), GFP_KERNEL); info = kzalloc(sizeof(struct async_struct), GFP_KERNEL);
if (!info) { if (!info) {
sstate->count--; sstate->count--;
return -ENOMEM; return -ENOMEM;
} }
memset(info, 0, sizeof(struct async_struct));
#ifdef DECLARE_WAITQUEUE #ifdef DECLARE_WAITQUEUE
init_waitqueue_head(&info->open_wait); init_waitqueue_head(&info->open_wait);
init_waitqueue_head(&info->close_wait); init_waitqueue_head(&info->close_wait);
+1 -2
View File
@@ -273,10 +273,9 @@ via_alloc_desc_pages(drm_via_sg_info_t *vsg)
vsg->num_desc_pages = (vsg->num_desc + vsg->descriptors_per_page - 1) / vsg->num_desc_pages = (vsg->num_desc + vsg->descriptors_per_page - 1) /
vsg->descriptors_per_page; vsg->descriptors_per_page;
if (NULL == (vsg->desc_pages = kmalloc(sizeof(void *) * vsg->num_desc_pages, GFP_KERNEL))) if (NULL == (vsg->desc_pages = kcalloc(vsg->num_desc_pages, sizeof(void *), GFP_KERNEL)))
return DRM_ERR(ENOMEM); return DRM_ERR(ENOMEM);
memset(vsg->desc_pages, 0, sizeof(void *) * vsg->num_desc_pages);
vsg->state = dr_via_desc_pages_alloc; vsg->state = dr_via_desc_pages_alloc;
for (i=0; i<vsg->num_desc_pages; ++i) { for (i=0; i<vsg->num_desc_pages; ++i) {
if (NULL == (vsg->desc_pages[i] = if (NULL == (vsg->desc_pages[i] =
+2 -4
View File
@@ -2459,7 +2459,7 @@ static int __init espserial_init(void)
return 1; return 1;
} }
info = kmalloc(sizeof(struct esp_struct), GFP_KERNEL); info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
if (!info) if (!info)
{ {
@@ -2469,7 +2469,6 @@ static int __init espserial_init(void)
return 1; return 1;
} }
memset((void *)info, 0, sizeof(struct esp_struct));
spin_lock_init(&info->lock); spin_lock_init(&info->lock);
/* rx_trigger, tx_trigger are needed by autoconfig */ /* rx_trigger, tx_trigger are needed by autoconfig */
info->config.rx_trigger = rx_trigger; info->config.rx_trigger = rx_trigger;
@@ -2527,7 +2526,7 @@ static int __init espserial_init(void)
if (!dma) if (!dma)
info->stat_flags |= ESP_STAT_NEVER_DMA; info->stat_flags |= ESP_STAT_NEVER_DMA;
info = kmalloc(sizeof(struct esp_struct), GFP_KERNEL); info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
if (!info) if (!info)
{ {
printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n"); printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
@@ -2536,7 +2535,6 @@ static int __init espserial_init(void)
return 0; return 0;
} }
memset((void *)info, 0, sizeof(struct esp_struct));
/* rx_trigger, tx_trigger are needed by autoconfig */ /* rx_trigger, tx_trigger are needed by autoconfig */
info->config.rx_trigger = rx_trigger; info->config.rx_trigger = rx_trigger;
info->config.tx_trigger = tx_trigger; info->config.tx_trigger = tx_trigger;
+1 -3
View File
@@ -784,12 +784,10 @@ static int __devinit hvcs_probe(
return -EFAULT; return -EFAULT;
} }
hvcsd = kmalloc(sizeof(*hvcsd), GFP_KERNEL); hvcsd = kzalloc(sizeof(*hvcsd), GFP_KERNEL);
if (!hvcsd) if (!hvcsd)
return -ENODEV; return -ENODEV;
/* hvcsd->tty is zeroed out with the memset */
memset(hvcsd, 0x00, sizeof(*hvcsd));
spin_lock_init(&hvcsd->lock); spin_lock_init(&hvcsd->lock);
/* Automatically incs the refcount the first time */ /* Automatically incs the refcount the first time */
+1 -2
View File
@@ -2639,10 +2639,9 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
return -ENODEV; return -ENODEV;
} }
intf = kmalloc(sizeof(*intf), GFP_KERNEL); intf = kzalloc(sizeof(*intf), GFP_KERNEL);
if (!intf) if (!intf)
return -ENOMEM; return -ENOMEM;
memset(intf, 0, sizeof(*intf));
intf->ipmi_version_major = ipmi_version_major(device_id); intf->ipmi_version_major = ipmi_version_major(device_id);
intf->ipmi_version_minor = ipmi_version_minor(device_id); intf->ipmi_version_minor = ipmi_version_minor(device_id);
+1 -2
View File
@@ -540,13 +540,12 @@ static int mgslpc_probe(struct pcmcia_device *link)
if (debug_level >= DEBUG_LEVEL_INFO) if (debug_level >= DEBUG_LEVEL_INFO)
printk("mgslpc_attach\n"); printk("mgslpc_attach\n");
info = kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); info = kzalloc(sizeof(MGSLPC_INFO), GFP_KERNEL);
if (!info) { if (!info) {
printk("Error can't allocate device instance data\n"); printk("Error can't allocate device instance data\n");
return -ENOMEM; return -ENOMEM;
} }
memset(info, 0, sizeof(MGSLPC_INFO));
info->magic = MGSLPC_MAGIC; info->magic = MGSLPC_MAGIC;
INIT_WORK(&info->task, bh_handler); INIT_WORK(&info->task, bh_handler);
info->max_frame_size = 4096; info->max_frame_size = 4096;
+1 -3
View File
@@ -803,9 +803,7 @@ static void *ckmalloc(int size)
{ {
void *p; void *p;
p = kmalloc(size, GFP_KERNEL); p = kzalloc(size, GFP_KERNEL);
if (p)
memset(p, 0, size);
return p; return p;
} }
+1 -3
View File
@@ -556,9 +556,7 @@ struct CmdBlk *RIOGetCmdBlk(void)
{ {
struct CmdBlk *CmdBlkP; struct CmdBlk *CmdBlkP;
CmdBlkP = kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC); CmdBlkP = kzalloc(sizeof(struct CmdBlk), GFP_ATOMIC);
if (CmdBlkP)
memset(CmdBlkP, 0, sizeof(struct CmdBlk));
return CmdBlkP; return CmdBlkP;
} }
+1 -2
View File
@@ -863,8 +863,7 @@ int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
if (PortP->TxRingBuffer) if (PortP->TxRingBuffer)
memset(PortP->TxRingBuffer, 0, p->RIOBufferSize); memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
else if (p->RIOBufferSize) { else if (p->RIOBufferSize) {
PortP->TxRingBuffer = kmalloc(p->RIOBufferSize, GFP_KERNEL); PortP->TxRingBuffer = kzalloc(p->RIOBufferSize, GFP_KERNEL);
memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
} }
PortP->TxBufferOut = 0; PortP->TxBufferOut = 0;
PortP->TxBufferIn = 0; PortP->TxBufferIn = 0;
+1 -2
View File
@@ -635,12 +635,11 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
ctlp = sCtlNumToCtlPtr(board); ctlp = sCtlNumToCtlPtr(board);
/* Get a r_port struct for the port, fill it in and save it globally, indexed by line number */ /* Get a r_port struct for the port, fill it in and save it globally, indexed by line number */
info = kmalloc(sizeof (struct r_port), GFP_KERNEL); info = kzalloc(sizeof (struct r_port), GFP_KERNEL);
if (!info) { if (!info) {
printk(KERN_INFO "Couldn't allocate info struct for line #%d\n", line); printk(KERN_INFO "Couldn't allocate info struct for line #%d\n", line);
return; return;
} }
memset(info, 0, sizeof (struct r_port));
info->magic = RPORT_MAGIC; info->magic = RPORT_MAGIC;
info->line = line; info->line = line;

Some files were not shown because too many files have changed in this diff Show More