Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd00cc48 authored by Yoann Padioleau's avatar Yoann Padioleau Committed by Linus Torvalds
Browse files

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: default avatarYoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: default avatarRussell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: default avatarJiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: default avatarRoland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: default avatarDmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: default avatarPierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: default avatarGreg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3b5ad079
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -124,9 +124,8 @@ static void cn_test_timer_func(unsigned long __data)
	struct cn_msg *m;
	char data[32];

	m = kmalloc(sizeof(*m) + sizeof(data), GFP_ATOMIC);
	m = kzalloc(sizeof(*m) + sizeof(data), GFP_ATOMIC);
	if (m) {
		memset(m, 0, sizeof(*m) + sizeof(data));

		memcpy(&m->id, &cn_test_id, sizeof(m->id));
		m->seq = cn_test_timer_counter;
+2 −4
Original line number Diff line number Diff line
@@ -277,11 +277,10 @@ static struct config_item *simple_children_make_item(struct config_group *group,
{
	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)
		return NULL;

	memset(simple_child, 0, sizeof(struct simple_child));

	config_item_init_type_name(&simple_child->item, name,
				   &simple_child_type);
@@ -364,12 +363,11 @@ static struct config_group *group_children_make_group(struct config_group *group
{
	struct simple_children *simple_children;

	simple_children = kmalloc(sizeof(struct simple_children),
	simple_children = kzalloc(sizeof(struct simple_children),
				  GFP_KERNEL);
	if (!simple_children)
		return NULL;

	memset(simple_children, 0, sizeof(struct simple_children));

	config_group_init_type_name(&simple_children->group, name,
				    &simple_children_type);
+1 −2
Original line number Diff line number Diff line
@@ -119,8 +119,7 @@ module_frob_arch_sections(Elf64_Ehdr *hdr, Elf64_Shdr *sechdrs,
	}

	nsyms = symtab->sh_size / sizeof(Elf64_Sym);
	chains = kmalloc(nsyms * sizeof(struct got_entry), GFP_KERNEL);
	memset(chains, 0, nsyms * sizeof(struct got_entry));
	chains = kcalloc(nsyms, sizeof(struct got_entry), GFP_KERNEL);

	got->sh_size = 0;
	got->sh_addralign = 8;
+1 −2
Original line number Diff line number Diff line
@@ -1002,11 +1002,10 @@ int iop13xx_pci_setup(int nr, struct pci_sys_data *sys)
	if (nr > 1)
		return 0;

	res = kmalloc(sizeof(struct resource) * 2, GFP_KERNEL);
	res = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
	if (!res)
		panic("PCI: unable to alloc resources");

	memset(res, 0, sizeof(struct resource) * 2);

	/* 'nr' assumptions:
	 * ATUX is always 0
+1 −2
Original line number Diff line number Diff line
@@ -521,10 +521,9 @@ void *sram_alloc_with_lsl(size_t size, unsigned long flags)
	struct sram_list_struct *lsl = NULL;
	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)
		return NULL;
	memset(lsl, 0, sizeof(*lsl));

	if (flags & L1_INST_SRAM)
		addr = l1_inst_sram_alloc(size);
Loading