Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4219988pxj; Wed, 12 May 2021 00:10:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrmXUkc1WU/wzAO7XvbNJ7eqvBru9J6amTrz2ZNxP/UizzSwCKD+V0/GyBl6Sm6FA2OTzT X-Received: by 2002:aa7:d41a:: with SMTP id z26mr42885750edq.54.1620803457842; Wed, 12 May 2021 00:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620803457; cv=none; d=google.com; s=arc-20160816; b=yKo43Gx4vjteYhm0JQ37G9Dw/BToNfIwX2luouz+PDcDhX5zlVWtSu4lr+DAMUpb9Q LbZmAOmyAEmqadlyIuV221n/mZyUdaStHokSLB3q/KQ8mVOWkzvIQKvJlR3L/ncZcxyR 6ey97NcJf9H+zcCTlSUX+DWZZyH0cHsCSn7oxU3xpXqfZXKMks80vg23udv6g66hHDvK ZUg0bjYeH4lCcbDbFN5Nug6j+/mx9dBfL2l57T0jV9mCSqGLYXDpARdVsFqpC+E8uC0z lZyOiBfKBnhJwieDLcvDJ472jojZrgaVlDUEc0FkZdcwbY4XXiwvQvOR0+fh9ASB6ZQN PLJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=NfWlELRK1LUBCBEz+1X1rPuocMQYdJTT7u6Xx5jy/tY=; b=nPQ6NqSR+p/BRXDXH2WoTGUMz3dPpuv2dIWvgc9ejfh8t+Y0hxZ7Vp3XfmKg9etWXI N9TYuURd88RQxJDBDwpYjfaYTKhZ++GUzolQw+V9ymWCJ8tpwDOu9nX//+6ykoC7wlCz Emx89+N5nqzGHWM9d6xqEsGAFd+xBs0SgMLSyJeBUTiaqbV62qhBBuvXANYzxc49FJuP U4xyOJacwkhURsDWu/0WXYH09A0LX03tNo+oxl85mcqCnBjNRI0aLkMR4A3i03/O8g+O Sog02olpR5yHAgKG7+UUd89VoX0qu0VUbZiEwVTAZYN68F1Y7A73BVWfxKY4knSJtl6e DoIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s9si19482737ejv.428.2021.05.12.00.10.34; Wed, 12 May 2021 00:10:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbhELHLj (ORCPT + 99 others); Wed, 12 May 2021 03:11:39 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:2637 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbhELHLj (ORCPT ); Wed, 12 May 2021 03:11:39 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4Fg5V95T8Zzldbw; Wed, 12 May 2021 15:08:17 +0800 (CST) Received: from linux-lmwb.huawei.com (10.175.103.112) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Wed, 12 May 2021 15:10:19 +0800 From: Zou Wei To: , , CC: , , Zou Wei Subject: [PATCH -next v2] crypto: hisilicon - switch to memdup_user_nul() Date: Wed, 12 May 2021 15:27:19 +0800 Message-ID: <1620804439-21392-1-git-send-email-zou_wei@huawei.com> X-Mailer: git-send-email 2.6.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.103.112] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use memdup_user_nul() helper instead of open-coding to simplify the code. v1-->v2: fixed patch title error Reported-by: Hulk Robot Signed-off-by: Zou Wei --- drivers/crypto/hisilicon/qm.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index ce439a0..83a5d30 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -1570,17 +1570,10 @@ static ssize_t qm_cmd_write(struct file *filp, const char __user *buffer, if (count > QM_DBG_WRITE_LEN) return -ENOSPC; - cmd_buf = kzalloc(count + 1, GFP_KERNEL); - if (!cmd_buf) + cmd_buf = memdup_user_nul(buffer, count); + if (IS_ERR(cmd_buf)) return -ENOMEM; - if (copy_from_user(cmd_buf, buffer, count)) { - kfree(cmd_buf); - return -EFAULT; - } - - cmd_buf[count] = '\0'; - cmd_buf_tmp = strchr(cmd_buf, '\n'); if (cmd_buf_tmp) { *cmd_buf_tmp = '\0'; -- 2.6.2