Skip to content

Commit

Permalink
Staging: Use kcalloc or kzalloc
Browse files Browse the repository at this point in the history
Use kcalloc or kzalloc rather than the combination of kmalloc and memset.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,y,flags;
statement S;
type T;
@@

x =
-   kmalloc
+   kcalloc
           (
-           y * sizeof(T),
+           y, sizeof(T),
                flags);
 if (x == NULL) S
-memset(x, 0, y * sizeof(T));

@@
expression x,size,flags;
statement S;
@@

-x = kmalloc(size,flags);
+x = kzalloc(size,flags);
 if (x == NULL) S
-memset(x, 0, size);
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
  • Loading branch information
Julia Lawall authored and Greg Kroah-Hartman committed May 14, 2010
1 parent b5a2104 commit 7a6cb0d
Show file tree
Hide file tree
Showing 49 changed files with 62 additions and 142 deletions.
4 changes: 1 addition & 3 deletions drivers/staging/comedi/drivers/addi-data/addi_amcc_s5933.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,10 @@ void v_pci_card_list_init(unsigned short pci_vendor, char display)
for (i_Count = 0; i_Count < 2; i_Count++) {
pci_vendor = i_ADDIDATADeviceID[i_Count];
if (pcidev->vendor == pci_vendor) {
amcc = kmalloc(sizeof(*amcc), GFP_KERNEL);
amcc = kzalloc(sizeof(*amcc), GFP_KERNEL);
if (amcc == NULL)
continue;

memset(amcc, 0, sizeof(*amcc));

amcc->pcidev = pcidev;
if (last)
last->next = amcc;
Expand Down
4 changes: 1 addition & 3 deletions drivers/staging/comedi/drivers/addi-data/amcc_s5933_58.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,10 @@ void v_pci_card_list_init(unsigned short pci_vendor, char display)

pci_for_each_dev(pcidev) {
if (pcidev->vendor == pci_vendor) {
amcc = kmalloc(sizeof(*amcc), GFP_KERNEL);
amcc = kzalloc(sizeof(*amcc), GFP_KERNEL);
if (amcc == NULL)
continue;

memset(amcc, 0, sizeof(*amcc));

amcc->pcidev = pcidev;
if (last) {
last->next = amcc;
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/comedi/drivers/icp_multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ static void pci_card_list_init(unsigned short pci_vendor, char display)
pcidev != NULL;
pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
if (pcidev->vendor == pci_vendor) {
inova = kmalloc(sizeof(*inova), GFP_KERNEL);
inova = kzalloc(sizeof(*inova), GFP_KERNEL);
if (!inova) {
printk
("icp_multi: pci_card_list_init: allocation failed\n");
pci_dev_put(pcidev);
break;
}
memset(inova, 0, sizeof(*inova));

inova->pcidev = pci_dev_get(pcidev);
if (last) {
Expand Down
5 changes: 1 addition & 4 deletions drivers/staging/dream/pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,14 +1245,11 @@ int pmem_setup(struct android_pmem_platform_data *pdata,
}
pmem[id].num_entries = pmem[id].size / PMEM_MIN_ALLOC;

pmem[id].bitmap = kmalloc(pmem[id].num_entries *
pmem[id].bitmap = kcalloc(pmem[id].num_entries,
sizeof(struct pmem_bits), GFP_KERNEL);
if (!pmem[id].bitmap)
goto err_no_mem_for_metadata;

memset(pmem[id].bitmap, 0, sizeof(struct pmem_bits) *
pmem[id].num_entries);

for (i = sizeof(pmem[id].num_entries) * 8 - 1; i >= 0; i--) {
if ((pmem[id].num_entries) & 1<<i) {
PMEM_ORDER(id, index) = i;
Expand Down
12 changes: 4 additions & 8 deletions drivers/staging/go7007/go7007-fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,12 @@ static int gen_mjpeghdr_to_package(struct go7007 *go, __le16 *code, int space)
unsigned int addr = 0x19;
int size = 0, i, off = 0, chunk;

buf = kmalloc(4096, GFP_KERNEL);
buf = kzalloc(4096, GFP_KERNEL);
if (buf == NULL) {
printk(KERN_ERR "go7007: unable to allocate 4096 bytes for "
"firmware construction\n");
return -1;
}
memset(buf, 0, 4096);

for (i = 1; i < 32; ++i) {
mjpeg_frame_header(go, buf + size, i);
Expand Down Expand Up @@ -651,13 +650,12 @@ static int gen_mpeg1hdr_to_package(struct go7007 *go,
unsigned int addr = 0x19;
int i, off = 0, chunk;

buf = kmalloc(5120, GFP_KERNEL);
buf = kzalloc(5120, GFP_KERNEL);
if (buf == NULL) {
printk(KERN_ERR "go7007: unable to allocate 5120 bytes for "
"firmware construction\n");
return -1;
}
memset(buf, 0, 5120);
framelen[0] = mpeg1_frame_header(go, buf, 0, 1, PFRAME);
if (go->interlace_coding)
framelen[0] += mpeg1_frame_header(go, buf + framelen[0] / 8,
Expand Down Expand Up @@ -839,13 +837,12 @@ static int gen_mpeg4hdr_to_package(struct go7007 *go,
unsigned int addr = 0x19;
int i, off = 0, chunk;

buf = kmalloc(5120, GFP_KERNEL);
buf = kzalloc(5120, GFP_KERNEL);
if (buf == NULL) {
printk(KERN_ERR "go7007: unable to allocate 5120 bytes for "
"firmware construction\n");
return -1;
}
memset(buf, 0, 5120);
framelen[0] = mpeg4_frame_header(go, buf, 0, PFRAME);
i = 368;
framelen[1] = mpeg4_frame_header(go, buf + i, 0, BFRAME_PRE);
Expand Down Expand Up @@ -1585,13 +1582,12 @@ int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen)
go->board_info->firmware);
return -1;
}
code = kmalloc(codespace * 2, GFP_KERNEL);
code = kzalloc(codespace * 2, GFP_KERNEL);
if (code == NULL) {
printk(KERN_ERR "go7007: unable to allocate %d bytes for "
"firmware construction\n", codespace * 2);
goto fw_failed;
}
memset(code, 0, codespace * 2);
src = (__le16 *)fw_entry->data;
srclen = fw_entry->size / 2;
while (srclen >= 2) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/go7007/go7007-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,9 @@ static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
"go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
#endif

tbuf = kmalloc(8, GFP_KERNEL);
tbuf = kzalloc(8, GFP_KERNEL);
if (tbuf == NULL)
return -ENOMEM;
memset(tbuf, 0, 8);
tbuf[0] = data & 0xff;
tbuf[1] = data >> 8;
tbuf[2] = addr & 0xff;
Expand Down
4 changes: 1 addition & 3 deletions drivers/staging/go7007/go7007-v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,16 +720,14 @@ static int vidioc_reqbufs(struct file *file, void *priv,
if (count > 32)
count = 32;

gofh->bufs = kmalloc(count * sizeof(struct go7007_buffer),
gofh->bufs = kcalloc(count, sizeof(struct go7007_buffer),
GFP_KERNEL);

if (!gofh->bufs) {
mutex_unlock(&go->hw_lock);
goto unlock_and_return;
}

memset(gofh->bufs, 0, count * sizeof(struct go7007_buffer));

for (i = 0; i < count; ++i) {
gofh->bufs[i].go = go;
gofh->bufs[i].index = i;
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/go7007/saa7134-go7007.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,9 @@ static int saa7134_go7007_init(struct saa7134_dev *dev)

printk(KERN_DEBUG "saa7134-go7007: probing new SAA713X board\n");

saa = kmalloc(sizeof(struct saa7134_go7007), GFP_KERNEL);
saa = kzalloc(sizeof(struct saa7134_go7007), GFP_KERNEL);
if (saa == NULL)
return -ENOMEM;
memset(saa, 0, sizeof(struct saa7134_go7007));

/* Allocate a couple pages for receiving the compressed stream */
saa->top = (u8 *)get_zeroed_page(GFP_KERNEL);
Expand Down
5 changes: 1 addition & 4 deletions drivers/staging/otus/zdusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,14 @@ static int zfLnxProbe(struct usb_interface *interface,
printk(KERN_NOTICE "USB 1.1 Host\n");
#endif

macp = kmalloc(sizeof(struct usbdrv_private), GFP_KERNEL);
macp = kzalloc(sizeof(struct usbdrv_private), GFP_KERNEL);
if (!macp)
{
printk(KERN_ERR "out of memory allocating device structure\n");
result = -ENOMEM;
goto fail;
}

/* Zero the memory */
memset(macp, 0, sizeof(struct usbdrv_private));

net = alloc_etherdev(0);

if (net == NULL)
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/panel/panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,12 +1906,11 @@ static struct logical_input *panel_bind_key(char *name, char *press,
{
struct logical_input *key;

key = kmalloc(sizeof(struct logical_input), GFP_KERNEL);
key = kzalloc(sizeof(struct logical_input), GFP_KERNEL);
if (!key) {
printk(KERN_ERR "panel: not enough memory\n");
return NULL;
}
memset(key, 0, sizeof(struct logical_input));
if (!input_name2mask(name, &key->mask, &key->value, &scan_mask_i,
&scan_mask_o))
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/pohmelfs/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,10 @@ static int pohmelfs_send_reply(int err, int msg_num, int action, struct cn_msg *
{
struct pohmelfs_cn_ack *ack;

ack = kmalloc(sizeof(struct pohmelfs_cn_ack), GFP_KERNEL);
ack = kzalloc(sizeof(struct pohmelfs_cn_ack), GFP_KERNEL);
if (!ack)
return -ENOMEM;

memset(ack, 0, sizeof(struct pohmelfs_cn_ack));
memcpy(&ack->msg, msg, sizeof(struct cn_msg));

if (action == POHMELFS_CTLINFO_ACK)
Expand Down
6 changes: 2 additions & 4 deletions drivers/staging/rtl8187se/ieee80211/ieee80211_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops)
if (hcrypt == NULL)
return -1;

alg = kmalloc(sizeof(*alg), GFP_KERNEL);
alg = kzalloc(sizeof(*alg), GFP_KERNEL);
if (alg == NULL)
return -ENOMEM;

memset(alg, 0, sizeof(*alg));
alg->ops = ops;

spin_lock_irqsave(&hcrypt->lock, flags);
Expand Down Expand Up @@ -207,11 +206,10 @@ int ieee80211_crypto_init(void)
{
int ret = -ENOMEM;

hcrypt = kmalloc(sizeof(*hcrypt), GFP_KERNEL);
hcrypt = kzalloc(sizeof(*hcrypt), GFP_KERNEL);
if (!hcrypt)
goto out;

memset(hcrypt, 0, sizeof(*hcrypt));
INIT_LIST_HEAD(&hcrypt->algs);
spin_lock_init(&hcrypt->lock);

Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_ccmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ static void * ieee80211_ccmp_init(int key_idx)
{
struct ieee80211_ccmp_data *priv;

priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL)
goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = key_idx;

priv->tfm = (void *)crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_tkip.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ static void * ieee80211_tkip_init(int key_idx)
{
struct ieee80211_tkip_data *priv;

priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL)
goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = key_idx;

priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/rtl8187se/ieee80211/ieee80211_crypt_wep.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ static void * prism2_wep_init(int keyidx)
{
struct prism2_wep_data *priv;

priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL)
goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = keyidx;
priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->tx_tfm)) {
Expand Down
7 changes: 2 additions & 5 deletions drivers/staging/rtl8187se/ieee80211/ieee80211_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,15 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
if (ieee->networks)
return 0;

ieee->networks = kmalloc(
MAX_NETWORK_COUNT * sizeof(struct ieee80211_network),
ieee->networks = kcalloc(
MAX_NETWORK_COUNT, sizeof(struct ieee80211_network),
GFP_KERNEL);
if (!ieee->networks) {
printk(KERN_WARNING "%s: Out of memory allocating beacons\n",
ieee->dev->name);
return -ENOMEM;
}

memset(ieee->networks, 0,
MAX_NETWORK_COUNT * sizeof(struct ieee80211_network));

return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,10 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
struct ieee80211_crypt_data *new_crypt;

/* take WEP into use */
new_crypt = kmalloc(sizeof(struct ieee80211_crypt_data),
new_crypt = kzalloc(sizeof(struct ieee80211_crypt_data),
GFP_KERNEL);
if (new_crypt == NULL)
return -ENOMEM;
memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
new_crypt->ops = ieee80211_get_crypto_ops("WEP");
if (!new_crypt->ops)
new_crypt->ops = ieee80211_get_crypto_ops("WEP");
Expand Down
6 changes: 2 additions & 4 deletions drivers/staging/rtl8192e/ieee80211/ieee80211_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops)
if (hcrypt == NULL)
return -1;

alg = kmalloc(sizeof(*alg), GFP_KERNEL);
alg = kzalloc(sizeof(*alg), GFP_KERNEL);
if (alg == NULL)
return -ENOMEM;

memset(alg, 0, sizeof(*alg));
alg->ops = ops;

spin_lock_irqsave(&hcrypt->lock, flags);
Expand Down Expand Up @@ -207,11 +206,10 @@ int __init ieee80211_crypto_init(void)
{
int ret = -ENOMEM;

hcrypt = kmalloc(sizeof(*hcrypt), GFP_KERNEL);
hcrypt = kzalloc(sizeof(*hcrypt), GFP_KERNEL);
if (!hcrypt)
goto out;

memset(hcrypt, 0, sizeof(*hcrypt));
INIT_LIST_HEAD(&hcrypt->algs);
spin_lock_init(&hcrypt->lock);

Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/rtl8192e/ieee80211/ieee80211_crypt_ccmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ static void * ieee80211_ccmp_init(int key_idx)
{
struct ieee80211_ccmp_data *priv;

priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL)
goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = key_idx;

#if((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)) && (!OPENSUSE_SLED))
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/rtl8192e/ieee80211/ieee80211_crypt_tkip.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ static void * ieee80211_tkip_init(int key_idx)
{
struct ieee80211_tkip_data *priv;

priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL)
goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = key_idx;
#if((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)) && (!OPENSUSE_SLED))
priv->tx_tfm_arc4 = crypto_alloc_tfm("arc4", 0);
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/rtl8192e/ieee80211/ieee80211_crypt_wep.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ static void * prism2_wep_init(int keyidx)
{
struct prism2_wep_data *priv;

priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
if (priv == NULL)
goto fail;
memset(priv, 0, sizeof(*priv));
priv->key_idx = keyidx;

#if((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)) && (!OPENSUSE_SLED))
Expand Down
7 changes: 2 additions & 5 deletions drivers/staging/rtl8192e/ieee80211/ieee80211_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
if (ieee->networks)
return 0;

ieee->networks = kmalloc(
MAX_NETWORK_COUNT * sizeof(struct ieee80211_network),
ieee->networks = kcalloc(
MAX_NETWORK_COUNT, sizeof(struct ieee80211_network),
GFP_KERNEL);
if (!ieee->networks) {
printk(KERN_WARNING "%s: Out of memory allocating beacons\n",
ieee->dev->name);
return -ENOMEM;
}

memset(ieee->networks, 0,
MAX_NETWORK_COUNT * sizeof(struct ieee80211_network));

return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/rtl8192e/ieee80211/ieee80211_softmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -3079,10 +3079,9 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
ieee->seq_ctrl[i] = 0;
}
#ifdef ENABLE_DOT11D
ieee->pDot11dInfo = kmalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC);
ieee->pDot11dInfo = kzalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC);
if (!ieee->pDot11dInfo)
IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for DOT11D\n");
memset(ieee->pDot11dInfo, 0, sizeof(RT_DOT11D_INFO));
#endif
//added for AP roaming
ieee->LinkDetectInfo.SlotNum = 2;
Expand Down
Loading

0 comments on commit 7a6cb0d

Please sign in to comment.