From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============8446441360101224182==" MIME-Version: 1.0 From: kernel test robot To: kbuild-all@lists.01.org Subject: [PATCH] tree-wide: fix memdup_user.cocci warnings Date: Fri, 14 Aug 2020 02:52:56 +0800 Message-ID: <20200813185256.GA47284@7df7513c7447> In-Reply-To: <20200813161359.904275-2-josef@toxicpanda.com> List-Id: --===============8446441360101224182== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: kernel test robot mm/util.c:198:5-13: WARNING opportunity for vmemdup_user Use memdup_user rather than duplicating its implementation This is a little bit restricted to reduce false positives Generated by: scripts/coccinelle/api/memdup_user.cocci CC: Josef Bacik Signed-off-by: kernel test robot --- url: https://github.com/0day-ci/linux/commits/Josef-Bacik/proc-use-vmall= oc-for-our-kernel-buffer/20200814-001519 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next Please take the patch only if it's a positive warning. Thanks! util.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) --- a/mm/util.c +++ b/mm/util.c @@ -195,14 +195,9 @@ void *kvmemdup_user(const void __user *s { void *p; = - p =3D kvmalloc(len, GFP_USER); - if (!p) - return ERR_PTR(-ENOMEM); - - if (copy_from_user(p, src, len)) { - kvfree(p); - return ERR_PTR(-EFAULT); - } + p =3D vmemdup_user(src, len); + if (IS_ERR(p)) + return ERR_PTR(PTR_ERR(p)); = return p; } --===============8446441360101224182==--