Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3243997pxj; Mon, 10 May 2021 23:20:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHXfPzDJUk56l2vRP2JtrllUL1SrshDgprYJkkPdhpC5DQMos+TGDTwLb4bxfEDnKziAuu X-Received: by 2002:a02:77d6:: with SMTP id g205mr25669331jac.48.1620714052625; Mon, 10 May 2021 23:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620714052; cv=none; d=google.com; s=arc-20160816; b=H1NlyTVTzpAUkuhiLV5NBQe2x+iw0LRTC+U0zuerbIT32JbNTGziS04gyK046H6f/K Bpnh7+EUygxTUDE5ZPunDcH/iS/NVtI3d0fr9TCqDS/OJQcSNUzP4nkMu3iO+3KCBIea o/Bb4McXOdF4SzbtGSG+JWFJrWV02nDOLrB1dNf9pRcoIYcbeOYfpdP2CO4kRx4/z/CS 2sK+rdwMlt/mvFVGaJU5j3YtJzAbpW7NZDdvx/rb2UbzmL5w7bS7pqIKfrp6879mBO/s sxcHWYLEQEdyOgTkUXlwjMZCdykK9O6lDdYwdZCXl9637u1Hs2pzD+YOlxFGzfecxbWJ ivYQ== 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=WFJqSFPhXNWBTfDsWNS4N6Ku3mZGWqFZAOhf8lEiug0=; b=M9YrRkfUynYh2UdErZ6Cv+1KpeI5Vuu2B0jhQ7bQvcN65txcMehNEX1fwQDcORQJf5 m7ejjvLMNQlfApC/ImTgYJkUEpi7/flnKppcIyq7ea7C7dXJX1YANFjcw79d2D5YyUdh sfxUMqTd3thopoQI/Oj2tMrFZNYMkkBDaHBCM8kqhBA/QttAnV5zVvqCo/lXZIQzSs8b 9kMuzj3wCNIIQsab60AD+NYdWayNSXntMZ6eHtkbnwqlCMoRas1Zi8RRXBhfne48L4ia S1gk3Mq+AaCZmeAkrvuqgBmPRCDpY4psyjiaRKPi9bQy2wb5ScBi/xnb62eVF6r67vPy eNBQ== 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 v3si9733445jas.76.2021.05.10.23.20.28; Mon, 10 May 2021 23:20:52 -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 S230160AbhEKGVc (ORCPT + 99 others); Tue, 11 May 2021 02:21:32 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:2439 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbhEKGVc (ORCPT ); Tue, 11 May 2021 02:21:32 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FfSQH67CMzCr4w; Tue, 11 May 2021 14:17:43 +0800 (CST) Received: from linux-lmwb.huawei.com (10.175.103.112) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Tue, 11 May 2021 14:20:12 +0800 From: Zou Wei To: , , CC: , , Zou Wei Subject: [PATCH -next] crypto: hisilicon -: switch to memdup_user_nul() Date: Tue, 11 May 2021 14:37:11 +0800 Message-ID: <1620715031-107265-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. 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