From patchwork Sat Feb 18 20:55:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9581241 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 4DB21604A4 for ; Sat, 18 Feb 2017 20:55:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D78C284FE for ; Sat, 18 Feb 2017 20:55:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3013528768; Sat, 18 Feb 2017 20:55:27 +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 ABDC9284FE for ; Sat, 18 Feb 2017 20:55:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754370AbdBRUzZ (ORCPT ); Sat, 18 Feb 2017 15:55:25 -0500 Received: from mout.web.de ([212.227.15.3]:61107 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754215AbdBRUzY (ORCPT ); Sat, 18 Feb 2017 15:55:24 -0500 Received: from [192.168.1.2] ([77.181.107.93]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lp9kK-1cBKri302m-00erhw; Sat, 18 Feb 2017 21:55:11 +0100 Subject: [PATCH 07/29] IB/mlx4: Split a condition check in handle_slaves_guid_change() To: linux-rdma@vger.kernel.org, Doug Ledford , Hal Rosenstock , Leon Romanovsky , Matan Barak , Sean Hefty , Yishai Hadas References: <1935365a-bd7c-461e-6a84-0c5d3a501fff@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: <951c0746-b88e-8ee7-78e8-5be2a53a2e43@users.sourceforge.net> Date: Sat, 18 Feb 2017 21:55:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <1935365a-bd7c-461e-6a84-0c5d3a501fff@users.sourceforge.net> X-Provags-ID: V03:K0:0fXeSAoXM93dief/ay6FH3jYKbhXaXv4cQD07cl6pXJPokWdnvc Hb+1yK3EhLRX5/R7sUwm9gXP7ItITyGnzSxXincrX0/i7+pY1HUcSVRjM93qqY7Z68ciTdg P2ni/snvb140NG3fO0US4VCtLtvlQ7GBZzijvw4FUO/Bx/h+yN/KwX1tcePwbHd/t+cXDLi Qhsl8idEoqQCLHjFcZ6Hg== X-UI-Out-Filterresults: notjunk:1; V01:K0:XzSV1xUNryk=:nXihSlobDPE43yv4UJhzgz 2Jvn5YD2d1TxKLteDJv9GZ3OEr+wueDVuIs+k9jZ4aYzLfq7B+4Ue8brNIx9mrL02e0oGRUYW e/YqFpNMyCWcJQtppQO1U33tRl3cnc+UNxbSFAdmVtuXIPkLDh259B8t6wZ6+R8CxwMJitBpa a/DSr8IUc4HIhFxkbkK0m8kGHKSHy12QJTG9OBDn1MPkZ6JFwME3dDhCx/24ACccvdErpKqJt wZ6MwrYGypiJBbO9Q8zEqDfZzED//+SEpRvPGcUQ+79ynOSb0WcmNUAOs1TbOhHPfMxSzq4Sy aUeGVM5SwgMExHGiDylJ/UmZxvVA6ARVWySfQW0XaBCbMtL0Mcz6udUUcRD3GJegF2MJt5Gy7 EKPq+Y7P1QEnvGPUG0LNRiDX/0r8D1kKEwTMRelouTNiFmUslJTND3qxOXTmU3YZUgkih3UqV 5vcGC3I80HPNlMBO6PBmWbcNM8uOSpZRlNhPmGZpMic4oowPM+Pkqjodq02ihuPiXPcw0QyOf JgWtLldVa/sceMM15RhtTN4unA+jeYSNi6WTfvUgk/L26NEPoCMsewh4paHe4R8Ta8GGz1UzW PjOjRsy16S+GrIyDtUB8QAeikytLoiIwrDTG5bmSEY6CBSrAOt4zaIKYEfX3NNyHnVu66BiEF RV6ofM0UVDo8xerAVhjJRi2Zgudg8BEvMDcj6OBCs+GdSc30GICk7hqiVVOoSmPzxkK6O39P0 kMF3L6DoSxfr5f8ZIJIOLeAJZjAahC4GfDIkUxbQkuHL7EbnfPI+8MeHvxs/A9d+ocyLUexP5 IVWcd46 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, 17 Feb 2017 21:41:25 +0100 The kfree() function was called in up to two cases by the handle_slaves_guid_change() function during error handling even if the passed variable contained a null pointer. * Split a condition check for memory allocation failures. * Adjust jump targets according to the Linux coding style convention. * Delete an initialisation for these variables at the beginning which became unnecessary with this refactoring. Signed-off-by: Markus Elfring Reviewed-by: Majd Dibbiny --- drivers/infiniband/hw/mlx4/mad.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c index cf33efce69d2..75b6522b3a8f 100644 --- a/drivers/infiniband/hw/mlx4/mad.c +++ b/drivers/infiniband/hw/mlx4/mad.c @@ -1128,17 +1128,20 @@ static void propagate_pkey_ev(struct mlx4_ib_dev *dev, int port_num, static void handle_slaves_guid_change(struct mlx4_ib_dev *dev, u8 port_num, u32 guid_tbl_blk_num, u32 change_bitmap) { - struct ib_smp *in_mad = NULL; - struct ib_smp *out_mad = NULL; + struct ib_smp *in_mad; + struct ib_smp *out_mad; u16 i; if (!mlx4_is_mfunc(dev->dev) || !mlx4_is_master(dev->dev)) return; in_mad = kmalloc(sizeof *in_mad, GFP_KERNEL); + if (!in_mad) + return; + out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); - if (!in_mad || !out_mad) - goto out; + if (!out_mad) + goto free_in_mad; guid_tbl_blk_num *= 4; @@ -1171,8 +1174,9 @@ static void handle_slaves_guid_change(struct mlx4_ib_dev *dev, u8 port_num, } out: - kfree(in_mad); kfree(out_mad); +free_in_mad: + kfree(in_mad); } void handle_port_mgmt_change_event(struct work_struct *work)