Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1583980

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

From SF Markus Elfring <elfring@users.sourceforge.net>
Newsgroups linux.kernel
Subject [PATCH 07/29] IB/mlx4: Split a condition check in handle_slaves_guid_change()
Date 2017-02-18 22:00 +0100
Message-ID <tckgO-6HX-19@gated-at.bofh.it> (permalink)
References <tck77-6Ef-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Markus Elfring <elfring@users.sourceforge.net>
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@users.sourceforge.net>
---
 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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/29] IB/mlx: Fine-tuning for several function  implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 21:50 +0100
  [PATCH 04/29] IB/mlx4: Improve another size determination in  alloc_pv_object() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:00 +0100
    Re: [PATCH 04/29] IB/mlx4: Improve another size determination in  alloc_pv_object() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:10 +0100
  [PATCH 01/29] IB/mlx4: Use kcalloc() in mlx4_ib_alloc_pv_bufs() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:00 +0100
    Re: [PATCH 01/29] IB/mlx4: Use kcalloc() in mlx4_ib_alloc_pv_bufs() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:10 +0100
  [PATCH 09/29] IB/mlx4: Move an assignment out of a check in  forward_trap() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:00 +0100
    Re: [PATCH 09/29] IB/mlx4: Move an assignment out of a check in  forward_trap() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:20 +0100
  [PATCH 03/29] IB/mlx4: Improve another size determination in  mlx4_ib_alloc_demux_ctx() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:00 +0100
    Re: [PATCH 03/29] IB/mlx4: Improve another size determination in  mlx4_ib_alloc_demux_ctx() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:10 +0100
  [PATCH 06/29] IB/mlx4: Delete three unnecessary return statements SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:00 +0100
    Re: [PATCH 06/29] IB/mlx4: Delete three unnecessary return statements Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:10 +0100
  [PATCH 05/29] IB/mlx4: Fix a typo in a comment line SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:00 +0100
    Re: [PATCH 05/29] IB/mlx4: Fix a typo in a comment line Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:10 +0100
  [PATCH 07/29] IB/mlx4: Split a condition check in  handle_slaves_guid_change() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:00 +0100
    Re: [PATCH 07/29] IB/mlx4: Split a condition check in  handle_slaves_guid_change() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:10 +0100
  [PATCH 10/29] IB/mlx4: Enclose 15 expressions for the sizeof operator  by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:00 +0100
    Re: [PATCH 10/29] IB/mlx4: Enclose 15 expressions for the sizeof  operator by parentheses Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:30 +0100
  [PATCH 15/29] IB/mlx4: Delete an unnecessary return statement in  do_slave_init() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:10 +0100
    Re: [PATCH 15/29] IB/mlx4: Delete an unnecessary return statement in  do_slave_init() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 23:40 +0100
  [PATCH 11/29] IB/mlx4: Use kmalloc_array() in three functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:10 +0100
    Re: [PATCH 11/29] IB/mlx4: Use kmalloc_array() in three functions Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:30 +0100
  [PATCH 13/29] IB/mlx4: Split a condition check in five functions SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:10 +0100
    Re: [PATCH 13/29] IB/mlx4: Split a condition check in five functions Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:30 +0100
  [PATCH 12/29] IB/mlx4: Enclose 17 expressions for the sizeof operator  by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:10 +0100
    Re: [PATCH 12/29] IB/mlx4: Enclose 17 expressions for the sizeof  operator by parentheses Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:30 +0100
  [PATCH 18/29] IB/mlx4: Delete an unnecessary variable initialisation  in mlx4_ib_add() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:10 +0100
  [PATCH 19/29] IB/mlx4: Delete an unnecessary variable assignment in  mlx4_ib_add() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:10 +0100
    Re: [PATCH 19/29] IB/mlx4: Delete an unnecessary variable assignment  in mlx4_ib_add() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 20:50 +0100
  [PATCH 14/29] IB/mlx4: Delete an unnecessary variable in  __mlx4_ib_query_gid() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:10 +0100
  [PATCH 17/29] IB/mlx4: Improve another size determination in  mlx4_ib_add() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:10 +0100
    Re: [PATCH 17/29] IB/mlx4: Improve another size determination in  mlx4_ib_add() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:40 +0100
    Re: [PATCH 17/29] IB/mlx4: Improve another size determination in  mlx4_ib_add() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:40 +0100
  [PATCH 22/29] IB/mlx4: Use kmalloc_array() in alloc_proxy_bufs() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
    Re: [PATCH 22/29] IB/mlx4: Use kmalloc_array() in alloc_proxy_bufs() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 21:00 +0100
  [PATCH 20/29] IB/mlx4: Delete an error message for a failed memory  allocation in mlx4_ib_add() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
    Re: [PATCH 20/29] IB/mlx4: Delete an error message for a failed  memory allocation in mlx4_ib_add() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 20:50 +0100
  [PATCH 21/29] IB/mlx4: Delete unnecessary braces in mlx4_ib_add() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
    Re: [PATCH 21/29] IB/mlx4: Delete unnecessary braces in mlx4_ib_add() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 21:10 +0100
  [PATCH 29/29] IB/mlx5: Use kmalloc_array() in create_srq_kernel() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
  [PATCH 24/29] IB/mlx4: Delete unwanted spaces behind usages of the  sizeof operator SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
  [PATCH 28/29] IB/mlx5: Less function calls in create_kernel_qp()  after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
  [PATCH 27/29] IB/mlx5: Use kmalloc_array() in create_kernel_qp() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
  [PATCH 23/29] IB/mlx4: Improve size determinations in  create_qp_common() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
    Re: [PATCH 23/29] IB/mlx4: Improve size determinations in  create_qp_common() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 21:00 +0100
  [PATCH 16/29] IB/mlx4: Improve another size determination in  do_slave_init() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:20 +0100
  [PATCH 08/29] IB/mlx4: Delete an unnecessary check before the  function call "kfree" in free_pv_object() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:30 +0100
    Re: [PATCH 08/29] IB/mlx4: Delete an unnecessary check before the  function call "kfree" in free_pv_object() Majd Dibbiny <majd@mellanox.com> - 2017-02-19 18:20 +0100
  [PATCH 26/29] IB/mlx4: Enclose 14 expressions for the sizeof operator  by parentheses SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:30 +0100
  [PATCH 25/29] IB/mlx4: Add spaces for better code readability SF Markus Elfring <elfring@users.sourceforge.net> - 2017-02-18 22:50 +0100

csiph-web