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:

zatwierdzone przez
Linus Torvalds

rodzic
3b5ad0797c
commit
dd00cc486a
@@ -315,12 +315,11 @@ static int __init c101_run(unsigned long irq, unsigned long winbase)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
card = kmalloc(sizeof(card_t), GFP_KERNEL);
|
||||
card = kzalloc(sizeof(card_t), GFP_KERNEL);
|
||||
if (card == NULL) {
|
||||
printk(KERN_ERR "c101: unable to allocate memory\n");
|
||||
return -ENOBUFS;
|
||||
}
|
||||
memset(card, 0, sizeof(card_t));
|
||||
|
||||
card->dev = alloc_hdlcdev(card);
|
||||
if (!card->dev) {
|
||||
|
@@ -572,13 +572,11 @@ static int cosa_probe(int base, int irq, int dma)
|
||||
sprintf(cosa->name, "cosa%d", cosa->num);
|
||||
|
||||
/* Initialize the per-channel data */
|
||||
cosa->chan = kmalloc(sizeof(struct channel_data)*cosa->nchannels,
|
||||
GFP_KERNEL);
|
||||
cosa->chan = kcalloc(cosa->nchannels, sizeof(struct channel_data), GFP_KERNEL);
|
||||
if (!cosa->chan) {
|
||||
err = -ENOMEM;
|
||||
goto err_out3;
|
||||
}
|
||||
memset(cosa->chan, 0, sizeof(struct channel_data)*cosa->nchannels);
|
||||
for (i=0; i<cosa->nchannels; i++) {
|
||||
cosa->chan[i].cosa = cosa;
|
||||
cosa->chan[i].num = i;
|
||||
|
@@ -113,12 +113,10 @@ static int __init cycx_init(void)
|
||||
/* Verify number of cards and allocate adapter data space */
|
||||
cycx_ncards = min_t(int, cycx_ncards, CYCX_MAX_CARDS);
|
||||
cycx_ncards = max_t(int, cycx_ncards, 1);
|
||||
cycx_card_array = kmalloc(sizeof(struct cycx_device) * cycx_ncards,
|
||||
GFP_KERNEL);
|
||||
cycx_card_array = kcalloc(cycx_ncards, sizeof(struct cycx_device), GFP_KERNEL);
|
||||
if (!cycx_card_array)
|
||||
goto out;
|
||||
|
||||
memset(cycx_card_array, 0, sizeof(struct cycx_device) * cycx_ncards);
|
||||
|
||||
/* Register adapters with WAN router */
|
||||
for (cnt = 0; cnt < cycx_ncards; ++cnt) {
|
||||
|
@@ -376,11 +376,10 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev,
|
||||
}
|
||||
|
||||
/* allocate and initialize private data */
|
||||
chan = kmalloc(sizeof(struct cycx_x25_channel), GFP_KERNEL);
|
||||
chan = kzalloc(sizeof(struct cycx_x25_channel), GFP_KERNEL);
|
||||
if (!chan)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(chan, 0, sizeof(*chan));
|
||||
strcpy(chan->name, conf->name);
|
||||
chan->card = card;
|
||||
chan->link = conf->port;
|
||||
|
@@ -890,12 +890,11 @@ static int dscc4_found1(struct pci_dev *pdev, void __iomem *ioaddr)
|
||||
struct dscc4_dev_priv *root;
|
||||
int i, ret = -ENOMEM;
|
||||
|
||||
root = kmalloc(dev_per_card*sizeof(*root), GFP_KERNEL);
|
||||
root = kcalloc(dev_per_card, sizeof(*root), GFP_KERNEL);
|
||||
if (!root) {
|
||||
printk(KERN_ERR "%s: can't allocate data\n", DRV_NAME);
|
||||
goto err_out;
|
||||
}
|
||||
memset(root, 0, dev_per_card*sizeof(*root));
|
||||
|
||||
for (i = 0; i < dev_per_card; i++) {
|
||||
root[i].dev = alloc_hdlcdev(root + i);
|
||||
@@ -903,12 +902,11 @@ static int dscc4_found1(struct pci_dev *pdev, void __iomem *ioaddr)
|
||||
goto err_free_dev;
|
||||
}
|
||||
|
||||
ppriv = kmalloc(sizeof(*ppriv), GFP_KERNEL);
|
||||
ppriv = kzalloc(sizeof(*ppriv), GFP_KERNEL);
|
||||
if (!ppriv) {
|
||||
printk(KERN_ERR "%s: can't allocate private data\n", DRV_NAME);
|
||||
goto err_free_dev;
|
||||
}
|
||||
memset(ppriv, 0, sizeof(struct dscc4_pci_priv));
|
||||
|
||||
ppriv->root = root;
|
||||
spin_lock_init(&ppriv->lock);
|
||||
|
@@ -2476,13 +2476,12 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
}
|
||||
|
||||
/* Allocate driver private data */
|
||||
card = kmalloc(sizeof (struct fst_card_info), GFP_KERNEL);
|
||||
card = kzalloc(sizeof (struct fst_card_info), GFP_KERNEL);
|
||||
if (card == NULL) {
|
||||
printk_err("FarSync card found but insufficient memory for"
|
||||
" driver storage\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(card, 0, sizeof (struct fst_card_info));
|
||||
|
||||
/* Try to enable the device */
|
||||
if ((err = pci_enable_device(pdev)) != 0) {
|
||||
|
@@ -231,11 +231,10 @@ static struct sv11_device *sv11_init(int iobase, int irq)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sv = kmalloc(sizeof(struct sv11_device), GFP_KERNEL);
|
||||
sv = kzalloc(sizeof(struct sv11_device), GFP_KERNEL);
|
||||
if(!sv)
|
||||
goto fail3;
|
||||
|
||||
memset(sv, 0, sizeof(*sv));
|
||||
sv->if_ptr=&sv->netdev;
|
||||
|
||||
sv->netdev.dev = alloc_netdev(0, "hdlc%d", sv11_setup);
|
||||
|
@@ -351,12 +351,11 @@ static int __init n2_run(unsigned long io, unsigned long irq,
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
card = kmalloc(sizeof(card_t), GFP_KERNEL);
|
||||
card = kzalloc(sizeof(card_t), GFP_KERNEL);
|
||||
if (card == NULL) {
|
||||
printk(KERN_ERR "n2: unable to allocate memory\n");
|
||||
return -ENOBUFS;
|
||||
}
|
||||
memset(card, 0, sizeof(card_t));
|
||||
|
||||
card->ports[0].dev = alloc_hdlcdev(&card->ports[0]);
|
||||
card->ports[1].dev = alloc_hdlcdev(&card->ports[1]);
|
||||
|
@@ -3456,7 +3456,7 @@ cpc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
if ((err = pci_enable_device(pdev)) < 0)
|
||||
return err;
|
||||
|
||||
card = kmalloc(sizeof(pc300_t), GFP_KERNEL);
|
||||
card = kzalloc(sizeof(pc300_t), GFP_KERNEL);
|
||||
if (card == NULL) {
|
||||
printk("PC300 found at RAM 0x%016llx, "
|
||||
"but could not allocate card structure.\n",
|
||||
@@ -3464,7 +3464,6 @@ cpc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
err = -ENOMEM;
|
||||
goto err_disable_dev;
|
||||
}
|
||||
memset(card, 0, sizeof(pc300_t));
|
||||
|
||||
err = -ENODEV;
|
||||
|
||||
|
@@ -334,14 +334,13 @@ static int __devinit pc300_pci_init_one(struct pci_dev *pdev,
|
||||
return i;
|
||||
}
|
||||
|
||||
card = kmalloc(sizeof(card_t), GFP_KERNEL);
|
||||
card = kzalloc(sizeof(card_t), GFP_KERNEL);
|
||||
if (card == NULL) {
|
||||
printk(KERN_ERR "pc300: unable to allocate memory\n");
|
||||
pci_release_regions(pdev);
|
||||
pci_disable_device(pdev);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
memset(card, 0, sizeof(card_t));
|
||||
pci_set_drvdata(pdev, card);
|
||||
|
||||
if (pdev->device == PCI_DEVICE_ID_PC300_TE_1 ||
|
||||
|
@@ -312,14 +312,13 @@ static int __devinit pci200_pci_init_one(struct pci_dev *pdev,
|
||||
return i;
|
||||
}
|
||||
|
||||
card = kmalloc(sizeof(card_t), GFP_KERNEL);
|
||||
card = kzalloc(sizeof(card_t), GFP_KERNEL);
|
||||
if (card == NULL) {
|
||||
printk(KERN_ERR "pci200syn: unable to allocate memory\n");
|
||||
pci_release_regions(pdev);
|
||||
pci_disable_device(pdev);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
memset(card, 0, sizeof(card_t));
|
||||
pci_set_drvdata(pdev, card);
|
||||
card->ports[0].dev = alloc_hdlcdev(&card->ports[0]);
|
||||
card->ports[1].dev = alloc_hdlcdev(&card->ports[1]);
|
||||
|
@@ -1196,10 +1196,9 @@ static int sdla_xfer(struct net_device *dev, struct sdla_mem __user *info, int r
|
||||
|
||||
if (read)
|
||||
{
|
||||
temp = kmalloc(mem.len, GFP_KERNEL);
|
||||
temp = kzalloc(mem.len, GFP_KERNEL);
|
||||
if (!temp)
|
||||
return(-ENOMEM);
|
||||
memset(temp, 0, mem.len);
|
||||
sdla_read(dev, mem.addr, temp, mem.len);
|
||||
if(copy_to_user(mem.data, temp, mem.len))
|
||||
{
|
||||
|
@@ -270,11 +270,10 @@ static __init struct slvl_board *slvl_init(int iobase, int irq,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b = kmalloc(sizeof(struct slvl_board), GFP_KERNEL);
|
||||
b = kzalloc(sizeof(struct slvl_board), GFP_KERNEL);
|
||||
if(!b)
|
||||
goto fail3;
|
||||
|
||||
memset(b, 0, sizeof(*b));
|
||||
if (!(b->dev[0]= slvl_alloc(iobase, irq)))
|
||||
goto fail2;
|
||||
|
||||
|
@@ -599,7 +599,7 @@ static int __devinit wanxl_pci_init_one(struct pci_dev *pdev,
|
||||
}
|
||||
|
||||
alloc_size = sizeof(card_t) + ports * sizeof(port_t);
|
||||
card = kmalloc(alloc_size, GFP_KERNEL);
|
||||
card = kzalloc(alloc_size, GFP_KERNEL);
|
||||
if (card == NULL) {
|
||||
printk(KERN_ERR "wanXL %s: unable to allocate memory\n",
|
||||
pci_name(pdev));
|
||||
@@ -607,7 +607,6 @@ static int __devinit wanxl_pci_init_one(struct pci_dev *pdev,
|
||||
pci_disable_device(pdev);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
memset(card, 0, alloc_size);
|
||||
|
||||
pci_set_drvdata(pdev, card);
|
||||
card->pdev = pdev;
|
||||
|
@@ -786,14 +786,12 @@ static int __init init_x25_asy(void)
|
||||
printk(KERN_INFO "X.25 async: version 0.00 ALPHA "
|
||||
"(dynamic channels, max=%d).\n", x25_asy_maxdev );
|
||||
|
||||
x25_asy_devs = kmalloc(sizeof(struct net_device *)*x25_asy_maxdev,
|
||||
GFP_KERNEL);
|
||||
x25_asy_devs = kcalloc(x25_asy_maxdev, sizeof(struct net_device*), GFP_KERNEL);
|
||||
if (!x25_asy_devs) {
|
||||
printk(KERN_WARNING "X25 async: Can't allocate x25_asy_ctrls[] "
|
||||
"array! Uaargh! (-> No X.25 available)\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(x25_asy_devs, 0, sizeof(struct net_device *)*x25_asy_maxdev);
|
||||
|
||||
return tty_register_ldisc(N_X25, &x25_ldisc);
|
||||
}
|
||||
|
Reference in New Issue
Block a user