From patchwork Fri Aug 19 07:06:20 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: 9289515 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 D757F6077B for ; Fri, 19 Aug 2016 07:09:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD03F292E5 for ; Fri, 19 Aug 2016 07:09:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B16F7292EA; Fri, 19 Aug 2016 07:09:31 +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 5452E292E5 for ; Fri, 19 Aug 2016 07:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751442AbcHSHJ3 (ORCPT ); Fri, 19 Aug 2016 03:09:29 -0400 Received: from mout.web.de ([212.227.17.12]:54291 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753881AbcHSHJ3 (ORCPT ); Fri, 19 Aug 2016 03:09:29 -0400 Received: from [192.168.1.3] ([77.181.218.203]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0Lba7D-1auNyO0cw7-00lHMw; Fri, 19 Aug 2016 09:06:31 +0200 To: linux-rdma@vger.kernel.org, Doug Ledford , Hal Rosenstock , Mike Marciniszyn , Sean Hefty Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Subject: [PATCH] IB/qib: Use memdup_user() rather than duplicating its implementation Message-ID: <620b3961-6e05-6638-4ca8-18766acc91f4@users.sourceforge.net> Date: Fri, 19 Aug 2016 09:06:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 X-Provags-ID: V03:K0:+b8x8QXDJpBfDyNg+cJI6zUqgk64Yw6KLwEGNUxITHUMZCsV9KU VJ3YIFoCjC7swj8oJoh5E07PxJDbCTrA0q7SkPdRz+/1JRok/b9mxatsehUUOdPcw+apCUx 6RZUBkz6WZwKOLsNBzEdGItRfvI8Kwhm7abGGzO53jFywr8I6+00+JCuF5VUdYCTsonw2Jg Ow7m19aQn/ajreQ2SAqig== X-UI-Out-Filterresults: notjunk:1; V01:K0:FmAqoja524Y=:F/flEUNV+YnGSc4xmGMKvk wG8z6XSTQeYkR57ieOHp8OI3KEzLUQbZxOSoq783Eei26PFbmil6WFcK82b+WgJgqZR9f9/yB GPoVveTw/aNULlPdkfypg0MHSPRassrmWoPWckC95tycvMWgV36DwDMALLCA3oTkFdsnnBHuF KTMmngo45b+XN2v7Jtpe9411a0bmJ8Ysnqi0xQmoSeuHbpBjVXBY47p0QZrdVBuW4NmkMkXY4 IGGYNIMYd5iVOyHpMIsyZ3ValN/BLv5tkbBOUckCQd80UgiZ9PmOEusFRpaVuS1wOMa25Wz/o lEqKD7ycGUBteUGfH98lcsqkQjJCaX1F+MkLNleGK8fe/xgZB4gZR5TrH4Tha63+j343iQTOF zzz9e2/7AmBgeCQN+o7e/WUYd31XZkQiwYULRSe1FBzKsNnui0c4zX+w8OxU9/P11IqGrUljw xGvgs0KAmjJq+gFbvCzy832caMrRBkBgUKteGisTB9d4q63EqLDXM6z2RXdgs7kMZsgVKTZPg SGBfBZc3si7XKossVsKxPfBASarbIGNSJ638dce6Q2COZZp/0B4bLdat2DnUXe09eIt5lGqyn uPC4V1d4UHBoWAvG5D52QoyitDVAndPSiWqJbNMI7gZGl2FMKU7CZIVrSRmMnwZVSDDDeE3zY tdFysaIAcCnMgs6FwWSiW2ShaQWOYZXnwE0K3HstSIlRh1F/DPiZVjYq+QA3rSytvXsP2Us9q M4dnux22I8GlzzIT3COOGHLit+qnJSB5iaJZfFphHyx+vxMhpWfadPRv8pPNhTohMk68Rl3xP zQv53RD 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: Fri, 19 Aug 2016 08:50:23 +0200 Reuse existing functionality from memdup_user() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Reviewed-by: Leon Romanovsky --- drivers/infiniband/hw/qib/qib_fs.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c index fcdf3791..910f0d9 100644 --- a/drivers/infiniband/hw/qib/qib_fs.c +++ b/drivers/infiniband/hw/qib/qib_fs.c @@ -338,17 +338,12 @@ static ssize_t flash_write(struct file *file, const char __user *buf, goto bail; } - tmp = kmalloc(count, GFP_KERNEL); - if (!tmp) { - ret = -ENOMEM; + tmp = memdup_user(buf, count); + if (IS_ERR(tmp)) { + ret = PTR_ERR(tmp); goto bail; } - if (copy_from_user(tmp, buf, count)) { - ret = -EFAULT; - goto bail_tmp; - } - dd = private2dd(file); if (qib_eeprom_write(dd, pos, tmp, count)) { ret = -ENXIO;