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

Commit 4d682420 authored by Julia Lawall's avatar Julia Lawall Committed by David Woodhouse
Browse files

mtd: block2mtd: Use kasprintf

kasprintf combines kmalloc and sprintf, and takes care of the size
calculation itself.

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

)

// <smpl>
@@
expression a,flag;
expression list args;
statement S;
@@

  a =
-  \(kmalloc\|kzalloc\)(...,flag)
+  kasprintf(flag,args)
  <... when != a
  if (a == NULL || ...) S
  ...>
- sprintf(a,args);
// </smpl>

Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 42c25919
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -275,12 +275,10 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)


	/* Setup the MTD structure */
	/* Setup the MTD structure */
	/* make the name contain the block device in */
	/* make the name contain the block device in */
	name = kmalloc(sizeof("block2mtd: ") + strlen(devname) + 1,
	name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname);
			GFP_KERNEL);
	if (!name)
	if (!name)
		goto devinit_err;
		goto devinit_err;


	sprintf(name, "block2mtd: %s", devname);
	dev->mtd.name = name;
	dev->mtd.name = name;


	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;