From: SF Markus Elfring Date: Sat, 18 Feb 2017 20:55:08 +0000 Subject: [PATCH 07/29] IB/mlx4: Split a condition check in handle_slaves_guid_change() Message-Id: <951c0746-b88e-8ee7-78e8-5be2a53a2e43@users.sourceforge.net> List-Id: References: <1935365a-bd7c-461e-6a84-0c5d3a501fff@users.sourceforge.net> In-Reply-To: <1935365a-bd7c-461e-6a84-0c5d3a501fff-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Doug Ledford , Hal Rosenstock , Leon Romanovsky , Matan Barak , Sean Hefty , Yishai Hadas Cc: LKML , kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org 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 --- 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) -- 2.11.1