Commit 7a6cb0d5 authored by Julia Lawall's avatar Julia Lawall Committed by Greg Kroah-Hartman
Browse files

Staging: Use kcalloc or kzalloc

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: default avatarJulia Lawall <julia@diku.dk>
parent b5a2104c
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -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;
+1 −3
Original line number Diff line number Diff line
@@ -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;
+1 −2
Original line number Diff line number Diff line
@@ -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) {
+1 −4
Original line number Diff line number Diff line
@@ -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;
+4 −8
Original line number Diff line number Diff line
@@ -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);
@@ -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,
@@ -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);
@@ -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) {
Loading