Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5415760imm; Tue, 18 Sep 2018 09:10:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaGAVY5ZaGBHJOhEpBU/ov7+0Xybax452STA1jP9iEyk1WXTirMaOxKH/4kcxaOHmPBmzDK X-Received: by 2002:a65:5304:: with SMTP id m4-v6mr28930368pgq.250.1537287047059; Tue, 18 Sep 2018 09:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537287047; cv=none; d=google.com; s=arc-20160816; b=regs7i++HqdSGQhdEgHKUYRetuIcpMtn//QJAdaEjA6ddv3Wktb3AY9VXaSCTAklE1 fPDOw5KeDknoIh79exGNpZHJ/nB904NjKxe0a1lS3R/hQGYmxA+2SQTonm1f33F5feHV syFEgsGkX3kYBD1d8UVYrd/KEhU/pHsSa+Pq6ggEiOJ3YAlZ38wMHYweU33E4zWquCLR iSaTpve1122HcQ517yUNsYBkqdazHnxHFZGqc6hDKiGimrT1E6U+gGA6bymKBiKFg3tS lrroXXH7cNCP5URNXe9apmyb08lGCVa7mUWl5NJVSb7nu7/iDpRpJ/VzKQJ3EKEmp982 3XzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=WAGIXGqzDmARRotEfRELhP93TxkoiL76WBmHFIyyXlA=; b=oPHFVbLj8tLJ76cFTQb1bzCZJ6kf70UeQx5AUftLz3/9t7IjUu36D0a8eiZEs+PKqm 52sLn1OWpSsfbLZt8K4MnPfsnWEmcTpncOgXJeqvd62T3J1UB+j/2otUcXjLLr45hnh2 0X+qdFVuyT32bzBboCEHoelRP7wPc4iZK5Jojn+Ux7nmVxoB5aVfnesSGQjdgtnSqZ3p psf1QApP4QVjfQ6FjKbjohU4Qv4GeDDAtHy+c2AEe34lQ/xDJp1OsahU9rO3oN4T17T2 m6HjU3FMiIMiqUhSBD5UM9IiKP2+kz8eGHekbsPKx8KmBjWZAU+V1Lv0ndsqohn5m27s 10lA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q74-v6si21689344pfq.32.2018.09.18.09.10.02; Tue, 18 Sep 2018 09:10:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730152AbeIRVka (ORCPT + 99 others); Tue, 18 Sep 2018 17:40:30 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:12179 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729447AbeIRVka (ORCPT ); Tue, 18 Sep 2018 17:40:30 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 6B483F8366FDB; Wed, 19 Sep 2018 00:07:06 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.399.0; Wed, 19 Sep 2018 00:07:04 +0800 From: zhong jiang To: CC: , , , Subject: [RESEND PATCH v2] scsi: Use vmemdup_user to replace the open code Date: Tue, 18 Sep 2018 23:54:41 +0800 Message-ID: <1537286081-63081-1-git-send-email-zhongjiang@huawei.com> X-Mailer: git-send-email 1.7.12.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vmemdup_user is better than duplicating its implementation, So just replace the open code. The issue is detected with the help of Coccinelle. Tested-by: Don Brace Acked-by: Don Brace Signed-off-by: zhong jiang --- drivers/scsi/hpsa.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 58bb70b..666ba09e5 100644 --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c @@ -6381,13 +6381,9 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) return -EINVAL; if (!capable(CAP_SYS_RAWIO)) return -EPERM; - ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); - if (!ioc) { - status = -ENOMEM; - goto cleanup1; - } - if (copy_from_user(ioc, argp, sizeof(*ioc))) { - status = -EFAULT; + ioc = vmemdup_user(argp, sizeof(*ioc)); + if (IS_ERR(ioc)) { + status = PTR_ERR(ioc); goto cleanup1; } if ((ioc->buf_size < 1) && @@ -6505,7 +6501,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp) kfree(buff); } kfree(buff_size); - kfree(ioc); + kvfree(ioc); return status; } -- 1.7.12.4