From patchwork Thu Feb 2 07:41:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 13125445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A575C61DA4 for ; Thu, 2 Feb 2023 07:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbjBBHlp (ORCPT ); Thu, 2 Feb 2023 02:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjBBHlp (ORCPT ); Thu, 2 Feb 2023 02:41:45 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9D2F757BC for ; Wed, 1 Feb 2023 23:41:43 -0800 (PST) Received: from dggpemm100007.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4P6rGH1d4PzJqdD; Thu, 2 Feb 2023 15:37:11 +0800 (CST) Received: from huawei.com (10.175.103.91) by dggpemm100007.china.huawei.com (7.185.36.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 2 Feb 2023 15:41:41 +0800 From: Yang Yingliang To: CC: , , , Subject: [PATCH -next] watchdog: diag288_wdt: use kmemdup() to allocate memory Date: Thu, 2 Feb 2023 15:41:27 +0800 Message-ID: <20230202074127.4108100-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100007.china.huawei.com (7.185.36.116) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org 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 --- drivers/watchdog/diag288_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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);