Skip to content

Commit 8757543

Browse files
Julia Lawalltorvalds
authored andcommitted
drivers/char/ppdev.c: 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: Julia Lawall <julia@diku.dk> Cc: Michael Buesch <mb@bu3sch.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 56d611a commit 8757543

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

‎drivers/char/ppdev.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,10 @@ static int register_device (int minor, struct pp_struct *pp)
287287
char *name;
288288
int fl;
289289

290-
name = kmalloc (strlen (CHRDEV) + 3, GFP_KERNEL);
290+
name = kasprintf(GFP_KERNEL, CHRDEV "%x", minor);
291291
if (name == NULL)
292292
return -ENOMEM;
293293

294-
sprintf (name, CHRDEV "%x", minor);
295-
296294
port = parport_find_number (minor);
297295
if (!port) {
298296
printk (KERN_WARNING "%s: no associated port!\n", name);

0 commit comments

Comments
 (0)