[PATCH 2/2] net/smc: Improve exception handling in smc_llc_cli_add_link_invite()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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






[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux