From patchwork Thu Aug 18 09:56:44 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: 9287183 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 6E427607FF for ; Thu, 18 Aug 2016 09:57:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DF6D2903B for ; Thu, 18 Aug 2016 09:57:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5257729093; Thu, 18 Aug 2016 09:57:13 +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=unavailable 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 012E82903B for ; Thu, 18 Aug 2016 09:57:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1945897AbcHRJ5B (ORCPT ); Thu, 18 Aug 2016 05:57:01 -0400 Received: from mout.web.de ([212.227.15.14]:54217 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753785AbcHRJ47 (ORCPT ); Thu, 18 Aug 2016 05:56:59 -0400 Received: from [192.168.1.3] ([77.182.223.38]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0LfRyz-1apm6h1Ysb-00p2To; Thu, 18 Aug 2016 11:56:46 +0200 Subject: [PATCH 2/5] block-cciss: Less function calls in cciss_bigpassthru() after error detection To: esc.storagedev@microsemi.com, iss_storagedev@hp.com, linux-scsi@vger.kernel.org, Don Brace References: <566ABCD9.1060404@users.sourceforge.net> <686a1f95-a76c-2624-50e1-9d0e59948e64@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: Date: Thu, 18 Aug 2016 11:56:44 +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: <686a1f95-a76c-2624-50e1-9d0e59948e64@users.sourceforge.net> X-Provags-ID: V03:K0:CZJxEutEV1GFqmRdUSGHj+nTTp2756zWY4Ex2jKZvoUBG02nKtZ 29rHbA3xXxzblX4+swhLDT0LKMf1vMlNs1laeDFGgoV2b1ueR26e4w2IMiUXNv0XyYRzSZZ KfcG3g8bBj220ng3RPA3RSzTI5YOEHySmE/LrsYIszf1MO4Si+ot/OMpi1TnSG2onHg3pDw ukFv5bU75I609sRz5xa7g== X-UI-Out-Filterresults: notjunk:1; V01:K0:ttoF1hk4S5c=:1woKljZkgPn7ViuFBrAEJY UrsLa87z/wpzTLKWT7bSNYgm3NJwCbKx6O2Xz8vBecnncswqdb8HVr2J4BFQKoOBIYRyeqgAk jaDKE4Mtp2j1mSXM1JJ8K8fGg/NulzcYqBgpRZoqrdvltkW7NznPLyEZuKsgNvlPaxivzenNJ rUM0Oov+HjAq7TvWU/d5qUc4xJprN42FfsSk8AlI0pHhlL/z7PcP4exVANe6ePfxmXEhaVGSo 9zbg82+kvD0Xivn6ySeURZgVVEH6G2oqEIXmsJ2+c7Xc/GqsNiNPkJ/0CfuYFwuBb9/4DM1qF fSwOdE6EbjW+B4uBbY7lNqMXVtllFbkGUYceGvscIDgr5KUlIWrRu5XXx5exvVGG6SmkDiqwk ZZ7bP9LNiwTOc/k1QY/393RtYDv/YXE/bdB34yZ6mCfd+7ek4O9u71QGJ2ru6nTBtalra1Ww3 qQt+07MFCbM11kzWDtHDvZLpnbtCIv4mjgCI+nbRHbwC4BQ6cUWtWoV5n5F7A6eGxHo0Wzuu7 bm/OMU5jlJ9EKqjX6sM/1fG8VabiBjkL1MfFn+Mn6RYS44gzXwbumf28V+ZCHdxOUbXNAbF2/ 0SBRvWaLIUeIRwKA+b6Ako9BXB4VMxzwvV9aCd9UlDB64mDCn4BG4Gy3iYv12Ni1WJSeUqHtX JB6KFnYkp2Ztnjou5tciYYGPXY0a7tAYVhbLuapziVmFIASvHeVu443W65fDz9TKSAAZuq3XN a78DPoCTF8FYu9qt9Lo0mSY6jwHPszKLhRlBhTP4/RY8d8rzGeUCdOlTICZQTC8Fp77gHPTzG Rt6CaVX Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Wed, 17 Aug 2016 22:39:31 +0200 The kfree() function was called in a few cases by the cciss_bigpassthru() function during error handling even if a passed variable contained a null pointer. Adjust jump targets according to the Linux coding style convention. Signed-off-by: Markus Elfring --- drivers/block/cciss.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index e044342..43ac632 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c @@ -1593,26 +1593,26 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp) if ((ioc->buf_size < 1) && (ioc->Request.Type.Direction != XFER_NONE)) { status = -EINVAL; - goto cleanup1; + goto free_ioc; } /* Check kmalloc limits using all SGs */ if (ioc->malloc_size > MAX_KMALLOC_SIZE) { status = -EINVAL; - goto cleanup1; + goto free_ioc; } if (ioc->buf_size > ioc->malloc_size * MAXSGENTRIES) { status = -EINVAL; - goto cleanup1; - } - buff = kzalloc(MAXSGENTRIES * sizeof(char *), GFP_KERNEL); - if (!buff) { - status = -ENOMEM; - goto cleanup1; + goto free_ioc; } buff_size = kmalloc(MAXSGENTRIES * sizeof(int), GFP_KERNEL); if (!buff_size) { status = -ENOMEM; - goto cleanup1; + goto free_ioc; + } + buff = kzalloc(MAXSGENTRIES * sizeof(char *), GFP_KERNEL); + if (!buff) { + status = -ENOMEM; + goto free_size; } left = ioc->buf_size; data_ptr = ioc->buf; @@ -1622,12 +1622,12 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp) buff[sg_used] = kmalloc(sz, GFP_KERNEL); if (buff[sg_used] == NULL) { status = -ENOMEM; - goto cleanup1; + goto free_buffer; } if (ioc->Request.Type.Direction == XFER_WRITE) { if (copy_from_user(buff[sg_used], data_ptr, sz)) { status = -EFAULT; - goto cleanup1; + goto free_buffer; } } else { memset(buff[sg_used], 0, sz); @@ -1639,7 +1639,7 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp) c = cmd_special_alloc(h); if (!c) { status = -ENOMEM; - goto cleanup1; + goto free_buffer; } c->cmd_type = CMD_IOCTL_PEND; c->Header.ReplyQueue = 0; @@ -1674,7 +1674,7 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp) if (copy_to_user(argp, ioc, sizeof(*ioc))) { cmd_special_free(h, c); status = -EFAULT; - goto cleanup1; + goto free_buffer; } if (ioc->Request.Type.Direction == XFER_READ) { /* Copy the data out of the buffer we created */ @@ -1683,20 +1683,20 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp) if (copy_to_user(ptr, buff[i], buff_size[i])) { cmd_special_free(h, c); status = -EFAULT; - goto cleanup1; + goto free_buffer; } ptr += buff_size[i]; } } cmd_special_free(h, c); status = 0; -cleanup1: - if (buff) { - for (i = 0; i < sg_used; i++) - kfree(buff[i]); - kfree(buff); - } +free_buffer: + for (i = 0; i < sg_used; i++) + kfree(buff[i]); + kfree(buff); +free_size: kfree(buff_size); +free_ioc: kfree(ioc); return status; }