From patchwork Mon Aug 22 16:30:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9293837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E56D607FF for ; Mon, 22 Aug 2016 16:31:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FD55289AD for ; Mon, 22 Aug 2016 16:31:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 040A4289B6; Mon, 22 Aug 2016 16:31:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E878A289AD for ; Mon, 22 Aug 2016 16:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754751AbcHVQbO (ORCPT ); Mon, 22 Aug 2016 12:31:14 -0400 Received: from mout.web.de ([212.227.15.3]:55530 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754224AbcHVQbM (ORCPT ); Mon, 22 Aug 2016 12:31:12 -0400 Received: from [192.168.1.3] ([77.182.220.187]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0Ly7vR-1b85ov1Duv-015dBI; Mon, 22 Aug 2016 18:30:36 +0200 Subject: [PATCH v2] IB/core: Use memdup_user() rather than duplicating its implementation To: linux-rdma@vger.kernel.org, Doug Ledford , Hal Rosenstock , Joe Perches , Sean Hefty , Yann Droneaud References: <566ABCD9.1060404@users.sourceforge.net> <1471802623.3746.1.camel@perches.com> <683187e0-2e6a-88c0-f87a-9c5f0489370a@users.sourceforge.net> <1471809188.3746.18.camel@perches.com> <5e87f691-edb9-0a12-ff7a-59854c2ca2f8@users.sourceforge.net> <1471859215.2764.24.camel@opteya.com> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: <3a5989cb-5a01-f502-c7fc-c489079ee73e@users.sourceforge.net> Date: Mon, 22 Aug 2016 18:30:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: <1471859215.2764.24.camel@opteya.com> X-Provags-ID: V03:K0:gzB/iUVu/4eZ9Lt9Xeqx/RqHnEmpDu9PinQuoc+UzCxFdlRH5H+ RnPj3YLzj5LBU6pTKZfd6pKvfWvfKHzQLkJVVGfHuPyFqA/A4hBIdgV5x67FBnz7l4CNVeU 9UhaALDXzsM2srPOGd8YZLPZUT9lg+b4T9wputoBTqNUijPK3OANA5e3HnJbrAmfX0A9GaY INLUVgL2qL7MABOszK2Iw== X-UI-Out-Filterresults: notjunk:1; V01:K0:ZYkt8x6DToA=:BUVND2DX6wlWfJcDku/gIO w6LKTdPrW5BRLoP9TjG8eo5u5W91oLUm7Ya+ctszhdIc7mVuoKQubSEUCQBZR1xLo051jdvsH ALOD6g6FT1MIjnvGksc5U9DVv1AQQnGvWlCNhViMlennybPLzaHTKpA+i1yNNzCTEg4OcBhsq qKWP2ExMr0o4Rg5Fj5rbmPOMbTCS5vjrBo3bHDQl7/AKKQynCf2WDAeu/6nkj0k/lZ2rNtTHu BnIzpxIJETTZqtafx3UYMqe4aQHvRKnYgjG/H9YdsOlmA3EcrPd2Ig6twuxLWsjGY1SDGrpeF H20D/XipycBodHKsGdLGSze7vxHfPg7SrZDMIp6+d6Qu92V6OonyGcEiJt6r3EPvLVrDnMKV/ sfIaLKaMTiiscCYHE1RQeWVTTse8u2FjK0OYKNk+CGIh0mNY9pBJCitIh4dvDn28jZowNEXyq m9L9zhLF679xzmOw/fRLIathW7tWzz3cq5CPtRVkLNP73UdfCUQe9rQe1kkQ0lCA1x1SZ9kK1 HokdUkCcAvsfi8UwIR/0g46+iurd6Yl/vBvzHkyYDxWM2C2B/OGyL3N8DwSfki9bXP++r0oIY ifKepJpHq+ues/XRGYVHjyrrDsZ+EeKZBI1wSAzmF0herXIKrc+oQDSDB69V9sW2PRMBJZjVm 0JX78uVsDIy4ZXmWDtDHfxha6j+OllLtVwJrAlqEWg4ODtam/zrutT2lrAU0Alvj8ZDyTr8GN aPNYL0k3Gz962nUAi7ddvKcBJhAQ1X150yVni9bJIVPaGRivZJjy26Q304ScTU20Rhr4/C7I+ oHtafFi Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Mon, 22 Aug 2016 18:23:24 +0200 * Reuse existing functionality from memdup_user() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. * The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring --- v2: The desired changes were put into a single patch instead of distributing them over two update steps. include/rdma/ib_verbs.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 6f667dd..0d8100f 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2199,22 +2199,17 @@ static inline bool ib_is_udata_cleared(struct ib_udata *udata, size_t len) { const void __user *p = udata->inbuf + offset; - bool ret = false; + bool ret; u8 *buf; if (len > USHRT_MAX) return false; - buf = kmalloc(len, GFP_KERNEL); - if (!buf) + buf = memdup_user(p, len); + if (IS_ERR(buf)) return false; - if (copy_from_user(buf, p, len)) - goto free; - ret = !memchr_inv(buf, 0, len); - -free: kfree(buf); return ret; }