Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4450026pxb; Tue, 10 Nov 2020 17:18:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJx160IwTtX8d7redDlIEYexqGG/2S78jnx1qpsHX2n07GMYH1sFexAdJ2cduCSEAtYEFP5j X-Received: by 2002:a17:906:14d:: with SMTP id 13mr22404490ejh.516.1605057507507; Tue, 10 Nov 2020 17:18:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605057507; cv=none; d=google.com; s=arc-20160816; b=eFDBw651esCotWPnFItwXEPrU+UiYRVe2hCxIggJh6YB0ZILC++Yp8hSQ39Pa+w6Cm Cpa05xPW119oZg9/ZKvI38CkVMDhCCWdGIZGDtA/1Mg0pCM2NWOIThB8eOKnbpkBHtdt LbWSSUJ0pF43yY+3yybDuJnr/xSpET2FN9JDjbkeQ62AUU2Gzq67+TF39pHmgS/YHQ6a C1sH+Z2WK0Hy9XXkxIlxW5HKJguQqJ4EN+D9ZhTwhJKnxItaWaE3EgvIZaxPwdx9VNEk ev5B92OtmKdmIb1FhtOv6dcR7zEC0exHOBmxqlVlEp3sTptHCCsyU749eGBU1ua3B7/y Z+7g== 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:to:from; bh=y4Erx3oslWXxfkY7a4NNlbUAr8iiFOka9dM+YpGPkMw=; b=pLi7eeQmP4+EX7fAWpLtVbj1AhfME9+woLHyiiKPe6pqEbtuvnhh/jiw7bB2p1MI2m KLqkeG20xyMAek7e6vj0mIk9pxkRa8XVDoYp3VUA7Tym1sk5FZr+NmBheWDg+qcyoG8f n2OujWljzFnZ1QUD2fHnET0z/ZshcTYj7o21if2+K5KyoFyK6FHoKh00lF3bMT6qUoaR Z8trEBZsvZ6doCXylIDzirIjQrE+oLCGbPFK4BSMjijkjQwQVx1z/gLedC5zWDW1MfLE bRJB2USyVsqAL7mSzXkLHA/laiMXratGycEdyQBJVw/pwiPrcwEeIBggtpueeHIlxpPZ O4Xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si238700ejf.28.2020.11.10.17.17.55; Tue, 10 Nov 2020 17:18:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732574AbgKKBO0 (ORCPT + 99 others); Tue, 10 Nov 2020 20:14:26 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:7627 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731746AbgKKBOW (ORCPT ); Tue, 10 Nov 2020 20:14:22 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CW6FW4x09zLx6D; Wed, 11 Nov 2020 09:14:07 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Wed, 11 Nov 2020 09:14:17 +0800 From: Tian Tao To: , , , , , Subject: [PATCH] vhost_vdpa: switch to vmemdup_user() Date: Wed, 11 Nov 2020 09:14:48 +0800 Message-ID: <1605057288-60400-1-git-send-email-tiantao6@hisilicon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace opencoded alloc and copy with vmemdup_user() Signed-off-by: Tian Tao --- drivers/vhost/vdpa.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 2754f30..4c39583 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -245,14 +245,10 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v, return -EFAULT; if (vhost_vdpa_config_validate(v, &config)) return -EINVAL; - buf = kvzalloc(config.len, GFP_KERNEL); - if (!buf) - return -ENOMEM; - if (copy_from_user(buf, c->buf, config.len)) { - kvfree(buf); - return -EFAULT; - } + buf = vmemdup_user(c->buf, config.len); + if (IS_ERR(buf)) + return PTR_ERR(buf); ops->set_config(vdpa, config.off, buf, config.len); -- 2.7.4