Message ID | 20230202074127.4108100-1-yangyingliang@huawei.com |
---|---|
State | New |
Headers | show |
Series | [-next] watchdog: diag288_wdt: use kmemdup() to allocate memory | expand |
diff --git a/drivers/watchdog/diag288_wdt.c b/drivers/watchdog/diag288_wdt.c index 6ca5d9515d85..8c2832308284 100644 --- a/drivers/watchdog/diag288_wdt.c +++ b/drivers/watchdog/diag288_wdt.c @@ -273,12 +273,11 @@ static int __init diag288_init(void) watchdog_set_nowayout(&wdt_dev, nowayout_info); if (MACHINE_IS_VM) { - ebc_cmd = kmalloc(sizeof(ebc_begin), GFP_KERNEL); + ebc_cmd = kmemdup(ebc_begin, sizeof(ebc_begin), GFP_KERNEL); if (!ebc_cmd) { pr_err("The watchdog cannot be initialized\n"); return -ENOMEM; } - memcpy(ebc_cmd, ebc_begin, sizeof(ebc_begin)); ret = __diag288_vm(WDT_FUNC_INIT, 15, ebc_cmd, sizeof(ebc_begin)); kfree(ebc_cmd);
Use kmemdup() helper instead of open-coding to simplify the code when allocating ebc_cmd. Generated by: scripts/coccinelle/api/memdup.cocci Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- drivers/watchdog/diag288_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)