Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756079AbbLHMYL (ORCPT ); Tue, 8 Dec 2015 07:24:11 -0500 Received: from mail-db3on0128.outbound.protection.outlook.com ([157.55.234.128]:51376 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751098AbbLHMYJ convert rfc822-to-8bit (ORCPT ); Tue, 8 Dec 2015 07:24:09 -0500 From: "Pathak, Rahul (R.)" To: "gregkh@linuxfoundation.org" , "stern@rowland.harvard.edu" , "kborer@gmail.com" , "dan.carpenter@oracle.com" , "chasemetzger15@gmail.com" CC: "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH v2] usb: Use memdup_user to reuse the code Thread-Topic: [PATCH v2] usb: Use memdup_user to reuse the code Thread-Index: AQHRMbNUIeAYKt1FS06zPSs0/3kOQA== Date: Tue, 8 Dec 2015 12:24:05 +0000 Message-ID: <20151208122358.GA17073@visteon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=rpathak@visteon.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [202.0.77.197] x-microsoft-exchange-diagnostics: 1;DB4PR06MB586;5:/EnsP1Jpu3mrEDT6PggHr91KPMAJftrIVJuSdYJgAWwFLMbBnC0PvBsuvbFrzg/oLJiREiEXQfYxFuwfAz36isfBpaW01SozImsilBboKqMKDWAnrEvJD13Wmc/uJcyvyRo7rPMlg58TySb3xoTJmw==;24:Ck+l/fbXJijfggRLVwMlDKvjEqmF3OARfg9Tl4uF9Sam8HBFEUH9UhevcgpFmQWrwga+eFnfiji7OR/jHkPzqxKx7w+6eSSJm9y/Bdhhwvs= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB4PR06MB586; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(208512329853888); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(3002001)(10201501046);SRVR:DB4PR06MB586;BCL:0;PCL:0;RULEID:;SRVR:DB4PR06MB586; x-forefront-prvs: 0784C803FD x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(189002)(199003)(3846002)(86362001)(2501003)(2171001)(33656002)(101416001)(36756003)(106116001)(11100500001)(189998001)(66066001)(106356001)(5004730100002)(105586002)(10400500002)(5001770100001)(87936001)(5008740100001)(97736004)(81156007)(586003)(229853001)(5002640100001)(6116002)(102836003)(92566002)(50986999)(1220700001)(5001960100002)(54356999)(77096005)(2900100001)(122556002)(19580395003)(1096002)(40100003)(19580405001)(1076002)(2201001);DIR:OUT;SFP:1102;SCL:1;SRVR:DB4PR06MB586;H:DB4PR06MB585.eurprd06.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: <326ECB14E67CE243A91C5A6DAB1C66B8@eurprd06.prod.outlook.com> Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: visteon.com X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Dec 2015 12:24:05.9713 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7a147aaf-01ec-498c-80a1-e34a8c63c548 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR06MB586 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1466 Lines: 41 From: Rahul Pathak Fixing coccicheck warning which recommends to use memdup_user instead to reimplement its code, using memdup_user simplifies the code ./drivers/usb/core/devio.c:1398:11-18: WARNING opportunity for memdup_user Changes after v1: setting isopkt=NULL for proper kfree() call Signed-off-by: Rahul Pathak --- drivers/usb/core/devio.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 38ae877c..844407c 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -1395,11 +1395,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb number_of_packets = uurb->number_of_packets; isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) * number_of_packets; - isopkt = kmalloc(isofrmlen, GFP_KERNEL); - if (!isopkt) - return -ENOMEM; - if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) { - ret = -EFAULT; + isopkt = memdup_user(iso_frame_desc, isofrmlen); + if (IS_ERR(isopkt)) { + ret = PTR_ERR(isopkt); + isopkt = NULL; goto error; } for (totlen = u = 0; u < number_of_packets; u++) { -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/