public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-s390@vger.kernel.org, netdev@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	"D. Wythe" <alibuda@linux.alibaba.com>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Jan Karcher <jaka@linux.ibm.com>, Paolo Abeni <pabeni@redhat.com>,
	Tony Lu <tonylu@linux.alibaba.com>,
	Wen Gu <guwen@linux.alibaba.com>,
	Wenjia Zhang <wenjia@linux.ibm.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] net/smc: Improve exception handling in smc_llc_cli_add_link_invite()
Date: Sun, 31 Dec 2023 16:00:22 +0100	[thread overview]
Message-ID: <5253e660-6b66-4775-ae2f-06f5a1d40be5@web.de> (raw)
In-Reply-To: <8ba404fd-7f41-44a9-9869-84f3af18fb46@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 31 Dec 2023 15:42:07 +0100

The kfree() function was called in some cases by
the smc_llc_cli_add_link_invite() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

* Thus use another label.

* Merge two if statements.

* Omit an initialisation (for the variable “ini”)
  which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/smc/smc_llc.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c
index 018ce8133b02..2ff24a7feb26 100644
--- a/net/smc/smc_llc.c
+++ b/net/smc/smc_llc.c
@@ -1163,23 +1163,21 @@ static void smc_llc_cli_add_link_invite(struct smc_link *link,
 					struct smc_llc_qentry *qentry)
 {
 	struct smc_link_group *lgr = smc_get_lgr(link);
-	struct smc_init_info *ini = NULL;
+	struct smc_init_info *ini;

 	if (lgr->smc_version == SMC_V2) {
 		smc_llc_send_request_add_link(link);
-		goto out;
+		goto free_qentry;
 	}

 	if (lgr->type == SMC_LGR_SYMMETRIC ||
-	    lgr->type == SMC_LGR_ASYMMETRIC_PEER)
-		goto out;
-
-	if (lgr->type == SMC_LGR_SINGLE && lgr->max_links <= 1)
-		goto out;
+	    lgr->type == SMC_LGR_ASYMMETRIC_PEER ||
+	    lgr->type == SMC_LGR_SINGLE && lgr->max_links <= 1)
+		goto free_qentry;

 	ini = kzalloc(sizeof(*ini), GFP_KERNEL);
 	if (!ini)
-		goto out;
+		goto free_qentry;

 	ini->vlan_id = lgr->vlan_id;
 	smc_pnet_find_alt_roce(lgr, ini, link->smcibdev);
@@ -1190,6 +1188,7 @@ static void smc_llc_cli_add_link_invite(struct smc_link *link,
 			      ini->ib_gid, NULL, SMC_LLC_REQ);
 out:
 	kfree(ini);
+free_qentry:
 	kfree(qentry);
 }

--
2.43.0


  parent reply	other threads:[~2023-12-31 15:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31 14:55 [PATCH 0/2] net/smc: Adjustments for two function implementations Markus Elfring
2023-12-31 14:58 ` [PATCH 1/2] net/smc: Return directly after a failed kzalloc() in smc_fill_gid_list() Markus Elfring
2024-01-02  2:13   ` Tony Lu
2023-12-31 15:00 ` Markus Elfring [this message]
2023-12-31 22:09   ` [PATCH 2/2] net/smc: Improve exception handling in smc_llc_cli_add_link_invite() kernel test robot
2023-12-31 22:40   ` kernel test robot
2024-01-02  2:19   ` Tony Lu
2024-01-02  8:13 ` [PATCH 0/2] net/smc: Adjustments for two function implementations Wen Gu
2024-01-02  8:44   ` Tony Lu
2024-01-02  8:51   ` [0/2] " Markus Elfring
2024-01-02 11:33     ` Wen Gu
2024-01-02 11:50       ` Markus Elfring
2024-01-04 20:40       ` Simon Horman
2024-01-03 13:44 ` [PATCH 0/2] " Wenjia Zhang
2024-01-03 14:16   ` [0/2] " Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5253e660-6b66-4775-ae2f-06f5a1d40be5@web.de \
    --to=markus.elfring@web.de \
    --cc=alibuda@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=guwen@linux.alibaba.com \
    --cc=jaka@linux.ibm.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tonylu@linux.alibaba.com \
    --cc=wenjia@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox