[PATCH 07/29] IB/mlx4: Split a condition check in handle_slaves_guid_change()

From: SF Markus Elfring
Date: Sat Feb 18 2017 - 15:55:29 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
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 <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
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