Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3259738pxj; Mon, 24 May 2021 02:29:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2PzelChpabGSGaNB+uc6h+3vBCJV4eP96w+eg6XbonX6K9sIjNlhXakJjBaSb8NtR0TH+ X-Received: by 2002:a17:906:3da9:: with SMTP id y9mr22346775ejh.303.1621848545444; Mon, 24 May 2021 02:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621848545; cv=none; d=google.com; s=arc-20160816; b=OqSrZHQ40kYvRvZ7q3ZhoGiDiRn46m1Adi2FMM5I1NrspyhxfqKBCI9wIWYW2dt74+ FBzmvkTF6//gnUMrcDJF2Dn9lxEFGeXpaKz9CYLqXLISeenKUnOnEJ+j/3ElwmmBLSAh eW0YEzydfRDb8Q082OWPT4tJrOXJnBrwy+ZAPFNos+uL4NZkLj5anvzstz37N9BLPdBq RXILfWCjOsAPdKB0VTieJhjpckCsP4E9MNppllxKLMGwwuuXe0fRa8UqSZdcO4+I4/WQ g8G724VbKYPbT4vG5RwFHJjpdw3iD6H8vhYHNYpqJhHM0Athzxa4N0cu0aPJY7tYm5lZ ZxmQ== 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=Gqxb6jLYVJm0BdOwc9sJFpJL4dOXboLX+DlcUKJK3T4=; b=ax9GrteN1FH13j+hBBVpW8eubnwucnIwW4cMsZzp3n8sueehT4dA36ItFEP37MRm8i RQzqXP/pghK5MXX2ygQaGp6PIJSObIA61i+LhSjcTWVm3VFKZGA3Oa1TH3FHCVAYXyYu grVGnQxe3xnsL/34ERYayA4dbMpAmJEs6Hj8uBlZEt2bQKOqVIbrwRZQ2o3N8BHub6+c Qq2bOFlpeMI2Mne/2SZK8TtiyR8uURLtmckZ+WpOT3zBLQiHMCd2/vr01NnZDGERVNyt vjP96gPb/I8LrDyouvLlnSz/E/SOTrMiH7mDdPKp7OZLBs96b9ZDaB9vB+Otn0AH+nic otIA== 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 i11si13382151edc.325.2021.05.24.02.28.32; Mon, 24 May 2021 02:29:05 -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 S232426AbhEXJ3y (ORCPT + 99 others); Mon, 24 May 2021 05:29:54 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5529 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232318AbhEXJ3y (ORCPT ); Mon, 24 May 2021 05:29:54 -0400 Received: from dggems701-chm.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FpWz24ClCzkYZ9; Mon, 24 May 2021 17:25:34 +0800 (CST) Received: from dggemi762-chm.china.huawei.com (10.1.198.148) by dggems701-chm.china.huawei.com (10.3.19.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Mon, 24 May 2021 17:28:24 +0800 Received: from linux-lmwb.huawei.com (10.175.103.112) by dggemi762-chm.china.huawei.com (10.1.198.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 24 May 2021 17:28:24 +0800 From: Zou Wei To: , , CC: , , Zou Wei Subject: [PATCH -next v3] crypto: hisilicon - switch to memdup_user_nul() Date: Mon, 24 May 2021 17:47:08 +0800 Message-ID: <1621849628-108717-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-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggemi762-chm.china.huawei.com (10.1.198.148) 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 v2-->v3: return the actual error Reported-by: Hulk Robot Signed-off-by: Zou Wei --- drivers/crypto/hisilicon/qm.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 8f7ea50..8b389c2 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -1571,16 +1571,9 @@ 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) - return -ENOMEM; - - if (copy_from_user(cmd_buf, buffer, count)) { - kfree(cmd_buf); - return -EFAULT; - } - - cmd_buf[count] = '\0'; + cmd_buf = memdup_user_nul(buffer, count); + if (IS_ERR(cmd_buf)) + return PTR_ERR(cmd_buf); cmd_buf_tmp = strchr(cmd_buf, '\n'); if (cmd_buf_tmp) { -- 2.6.2