From patchwork Mon May 15 09:26:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Li X-Patchwork-Id: 13241044 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 CB13FC77B75 for ; Mon, 15 May 2023 09:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233666AbjEOJ11 (ORCPT ); Mon, 15 May 2023 05:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238806AbjEOJ1C (ORCPT ); Mon, 15 May 2023 05:27:02 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DDFA1730; Mon, 15 May 2023 02:26:09 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=yang.lee@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VigIxMm_1684142765; Received: from localhost(mailfrom:yang.lee@linux.alibaba.com fp:SMTPD_---0VigIxMm_1684142765) by smtp.aliyun-inc.com; Mon, 15 May 2023 17:26:06 +0800 From: Yang Li To: srinivas.kandagatla@linaro.org Cc: amahesh@qti.qualcomm.com, arnd@arndb.de, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Li , Abaci Robot Subject: [PATCH -next] fastrpc: Use memdup_user instead of kmalloc/copy_from_user Date: Mon, 15 May 2023 17:26:04 +0800 Message-Id: <20230515092604.79990-1-yang.lee@linux.alibaba.com> X-Mailer: git-send-email 2.20.1.7.g153144c MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Use memdup_user rather than duplicating its implementation, which makes code simple and easy to understand, and silence the following warning: ./drivers/misc/fastrpc.c:1259:8-15: WARNING opportunity for memdup_user Reported-by: Abaci Robot Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4949 Signed-off-by: Yang Li --- drivers/misc/fastrpc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index f60bbf99485c..a897dab13c61 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1256,16 +1256,9 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, goto err; } - name = kzalloc(init.namelen, GFP_KERNEL); - if (!name) { - err = -ENOMEM; - goto err; - } - - if (copy_from_user(name, (void __user *)(uintptr_t)init.name, init.namelen)) { - err = -EFAULT; - goto err_name; - } + name = memdup_user((void __user *)(uintptr_t)init.name, init.namelen); + if (IS_ERR(name)) + return PTR_ERR(name); if (!fl->cctx->remote_heap) { err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen,