Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3532780imu; Mon, 10 Dec 2018 03:54:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/VQInwrsl207xBi3HDF3vp9ZY9zOBg9KvTzz1Tp1OCfoLU7RXKNpT1ZrhmOFQRdYKDv0fqn X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr12064289plb.107.1544442883539; Mon, 10 Dec 2018 03:54:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544442883; cv=none; d=google.com; s=arc-20160816; b=i0y6VSUUKMBwaxFJomMlVSfoF9QL6NF/Wf4V1KSC/+JDWjTW0vrKpqhS4vrpEU7Mow 1T10JEYajCuHmCs75e3WQD4R7FhzXt733VT2jdpwU0YrhY6AJMWSgLTsZgsdYK3ZXLWp NwcmRQMBQjR/nEs35vpDekGWkDZd9xdEmSacSHwenBEx3zDsohO7QBGjEs60ekrvFtxz qjo/RP+2tF1Qvn/BlIbSyRYIWb34GHd4zTMiaU8mUCtKlQaQFpThH2s/bpq+/dMr4JzM mljJABuvcUXLIMjlMdi4ImTEbqS8Pd6PEmydd2MJtBzHvHZJvaDOC4vfkmllDuMxMKO+ uTwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=88hhtU8hSave79PyoKAZOYgK7vZ5imxjpCJOWj/q8gE=; b=J58QtR2Im5PWdJGz/wKezJAaybQ2oDNSW4paezCsqNa0SpAJYLojQQhOiM+PCgIeeY NwerEGBoDbAZ20kbXkvIW/EobO75iNx7kgrULpQPE8TEUfHBEZOxqWohgBenJsVxZWB4 Q66PArz399Nhs127jMM/5AG6o7T0TLkagQSw8QeKT/qRO2eW4V8Y/NNDUGUWHsJ0KIXt ThLM83krX6cSgCqvz1/68oGy/deeShRvKdhEVLolg4G5mU5wg86DNzcaQysJqc1eECjt lIThHcfQkMQdy6TCnsZ4GOq0BfYT1dt2t2mRGY8ASBmN/sAty82tY1drqsYbdOk1NvB1 PUxg== 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 h16si9428878pgj.203.2018.12.10.03.54.28; Mon, 10 Dec 2018 03:54:43 -0800 (PST) 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 S1727542AbeLJLgY (ORCPT + 99 others); Mon, 10 Dec 2018 06:36:24 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:11638 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbeLJLgX (ORCPT ); Mon, 10 Dec 2018 06:36:23 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 172E8F9031B527D552F7; Mon, 10 Dec 2018 19:36:20 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wBABaBGX063831; Mon, 10 Dec 2018 19:36:11 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from LIN-A6CB96A0603.zte.intra ([10.90.106.118]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018121019361911-15858711 ; Mon, 10 Dec 2018 19:36:19 +0800 From: Wen Yang To: Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, Wen Yang Subject: [PATCH] VMCI: Use memdup_user() rather than duplicating its implementation Date: Mon, 10 Dec 2018 19:36:07 +0800 Message-Id: <20181210113607.46154-1-wen.yang99@zte.com.cn> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-12-10 19:36:19, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-12-10 19:36:11 Content-Transfer-Encoding: quoted-printable X-MAIL: mse01.zte.com.cn wBABaBGX063831 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reuse existing functionality from memdup=5Fuser() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. Signed-off-by: Wen Yang CC: Arnd Bergmann CC: Greg Kroah-Hartman CC: linux-kernel@vger.kernel.org --- drivers/misc/vmw=5Fvmci/vmci=5Fhost.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/misc/vmw=5Fvmci/vmci=5Fhost.c b/drivers/misc/vmw=5Fvmc= i/vmci=5Fhost.c index edfffc9699ba..5da1f3e3f997 100644 --- a/drivers/misc/vmw=5Fvmci/vmci=5Fhost.c +++ b/drivers/misc/vmw=5Fvmci/vmci=5Fhost.c @@ -750,19 +750,10 @@ static int vmci=5Fhost=5Fdo=5Fctx=5Fset=5Fcpt=5Fstate= (struct vmci=5Fhost=5Fdev *vmci=5Fhost=5Fdev, if (copy=5Ffrom=5Fuser(&set=5Finfo, uptr, sizeof(set=5Finfo))) return -EFAULT; =20 - cpt=5Fbuf =3D kmalloc(set=5Finfo.buf=5Fsize, GFP=5FKERNEL); - if (!cpt=5Fbuf) { - vmci=5Fioctl=5Ferr( - "cannot allocate memory to set cpt state (type=3D%d)\n", - set=5Finfo.cpt=5Ftype); - return -ENOMEM; - } - - if (copy=5Ffrom=5Fuser(cpt=5Fbuf, (void =5F=5Fuser *)(uintptr=5Ft)set=5Fi= nfo.cpt=5Fbuf, - set=5Finfo.buf=5Fsize)) { - retval =3D -EFAULT; - goto out; - } + cpt=5Fbuf =3D memdup=5Fuser((void =5F=5Fuser *)(uintptr=5Ft)set=5Finfo.cp= t=5Fbuf, + set=5Finfo.buf=5Fsize); + if (IS=5FERR(cpt=5Fbuf)) + return PTR=5FERR(cpt=5Fbuf); =20 cid =3D vmci=5Fctx=5Fget=5Fid(vmci=5Fhost=5Fdev->context); set=5Finfo.result =3D vmci=5Fctx=5Fset=5Fchkpt=5Fstate(cid, set=5Finfo.cp= t=5Ftype, @@ -770,7 +761,6 @@ static int vmci=5Fhost=5Fdo=5Fctx=5Fset=5Fcpt=5Fstate(s= truct vmci=5Fhost=5Fdev *vmci=5Fhost=5Fdev, =20 retval =3D copy=5Fto=5Fuser(uptr, &set=5Finfo, sizeof(set=5Finfo)) ? -EFA= ULT : 0; =20 -out: kfree(cpt=5Fbuf); return retval; } --=20 2.19.1