2013-03-12 18:22:33

by Alexandru Gheorghiu

[permalink] [raw]
Subject: [PATCH] drivers: acpi: Replaced kmalloc and memcpy with kmemdup

Replaced calls to kmalloc followed by memcpy with a single call to kmemdup.
Patch found using coccinelle.

Signed-off-by: Alexandru Gheorghiu <[email protected]>
---
drivers/acpi/bus.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 01708a1..6c8380e 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -288,13 +288,12 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
}
out_success:
context->ret.length = out_obj->buffer.length;
- context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
+ context->ret.pointer = kmemdup(out_obj->buffer.pointer,
+ context->ret.length, GFP_KERNEL);
if (!context->ret.pointer) {
status = AE_NO_MEMORY;
goto out_kfree;
}
- memcpy(context->ret.pointer, out_obj->buffer.pointer,
- context->ret.length);
status = AE_OK;

out_kfree:
--
1.7.9.5


2013-03-26 13:20:54

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] drivers: acpi: Replaced kmalloc and memcpy with kmemdup

On Tuesday, March 12, 2013 10:22:21 AM Alexandru Gheorghiu wrote:
> Replaced calls to kmalloc followed by memcpy with a single call to kmemdup.
> Patch found using coccinelle.
>
> Signed-off-by: Alexandru Gheorghiu <[email protected]>

I have an analogous patch already in my tree.

Thanks,
Rafael


> ---
> drivers/acpi/bus.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index 01708a1..6c8380e 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -288,13 +288,12 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
> }
> out_success:
> context->ret.length = out_obj->buffer.length;
> - context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
> + context->ret.pointer = kmemdup(out_obj->buffer.pointer,
> + context->ret.length, GFP_KERNEL);
> if (!context->ret.pointer) {
> status = AE_NO_MEMORY;
> goto out_kfree;
> }
> - memcpy(context->ret.pointer, out_obj->buffer.pointer,
> - context->ret.length);
> status = AE_OK;
>
> out_kfree:
>
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.