提交 87575437 编写于 作者: J Julia Lawall 提交者: Linus Torvalds

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: NJulia Lawall <julia@diku.dk>
Cc: Michael Buesch <mb@bu3sch.de>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 56d611a0
...@@ -287,12 +287,10 @@ static int register_device (int minor, struct pp_struct *pp) ...@@ -287,12 +287,10 @@ static int register_device (int minor, struct pp_struct *pp)
char *name; char *name;
int fl; int fl;
name = kmalloc (strlen (CHRDEV) + 3, GFP_KERNEL); name = kasprintf(GFP_KERNEL, CHRDEV "%x", minor);
if (name == NULL) if (name == NULL)
return -ENOMEM; return -ENOMEM;
sprintf (name, CHRDEV "%x", minor);
port = parport_find_number (minor); port = parport_find_number (minor);
if (!port) { if (!port) {
printk (KERN_WARNING "%s: no associated port!\n", name); printk (KERN_WARNING "%s: no associated port!\n", name);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册