]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
platform/x86: asus-wmi: Use kmemdup rather than duplicating its implementation
authorFuqian Huang <huangfq.daxian@gmail.com>
Wed, 3 Jul 2019 16:29:51 +0000 (00:29 +0800)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 29 Jul 2019 15:31:48 +0000 (18:31 +0300)
kmemdup is introduced to duplicate a region of memory in a neat way.
Rather than kmalloc/kzalloc + memcpy, which the programmer needs to
write the size twice (sometimes lead to mistakes), kmemdup improves
readability, leads to smaller code and also reduce the chances of mistakes.
Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy.

Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/platform/x86/asus-wmi.c

index ca28d27dae63dd13d21f0e5a3886d166598d699c..0c6a810fcb72ef48dbd273b59c023c87dbe96320 100644 (file)
@@ -292,12 +292,11 @@ static int asus_wmi_evaluate_method_agfn(const struct acpi_buffer args)
         * Copy to dma capable address otherwise memory corruption occurs as
         * bios has to be able to access it.
         */
-       input.pointer = kzalloc(args.length, GFP_DMA | GFP_KERNEL);
+       input.pointer = kmemdup(args.pointer, args.length, GFP_DMA | GFP_KERNEL);
        input.length = args.length;
        if (!input.pointer)
                return -ENOMEM;
        phys_addr = virt_to_phys(input.pointer);
-       memcpy(input.pointer, args.pointer, args.length);
 
        status = asus_wmi_evaluate_method(ASUS_WMI_METHODID_AGFN,
                                        phys_addr, 0, &retval);