Skip to content
  • Li Zefan's avatar
    memdup_user(): introduce · 610a77e0
    Li Zefan authored
    
    
    I notice there are many places doing copy_from_user() which follows
    kmalloc():
    
            dst = kmalloc(len, GFP_KERNEL);
            if (!dst)
                    return -ENOMEM;
            if (copy_from_user(dst, src, len)) {
    		kfree(dst);
    		return -EFAULT
    	}
    
    memdup_user() is a wrapper of the above code.  With this new function, we
    don't have to write 'len' twice, which can lead to typos/mistakes.  It
    also produces smaller code and kernel text.
    
    A quick grep shows 250+ places where memdup_user() *may* be used.  I'll
    prepare a patchset to do this conversion.
    
    Signed-off-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
    Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
    Cc: Americo Wang <xiyou.wangcong@gmail.com>
    Cc: Alexey Dobriyan <adobriyan@gmail.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    610a77e0