diff mbox series

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

Message ID 5253e660-6b66-4775-ae2f-06f5a1d40be5@web.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net/smc: Adjustments for two function implementations | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 1113 this patch: 1114
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang fail Errors and warnings before: 1140 this patch: 1143
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 1140 this patch: 1141
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 36 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Markus Elfring Dec. 31, 2023, 3 p.m. UTC
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(-)

--
2.43.0

Comments

kernel test robot Dec. 31, 2023, 10:09 p.m. UTC | #1
Hi Markus,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net/main]
[also build test WARNING on net-next/main linus/master v6.7-rc7 next-20231222]
[cannot apply to horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Markus-Elfring/net-smc-Return-directly-after-a-failed-kzalloc-in-smc_fill_gid_list/20231231-231406
base:   net/main
patch link:    https://lore.kernel.org/r/5253e660-6b66-4775-ae2f-06f5a1d40be5%40web.de
patch subject: [PATCH 2/2] net/smc: Improve exception handling in smc_llc_cli_add_link_invite()
config: x86_64-randconfig-002-20231231 (https://download.01.org/0day-ci/archive/20240101/202401010536.XhzcWDPH-lkp@intel.com/config)
compiler: ClangBuiltLinux clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240101/202401010536.XhzcWDPH-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401010536.XhzcWDPH-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> net/smc/smc_llc.c:1175:34: warning: '&&' within '||' [-Wlogical-op-parentheses]
    1174 |             lgr->type == SMC_LGR_ASYMMETRIC_PEER ||
         |                                                  ~~
    1175 |             lgr->type == SMC_LGR_SINGLE && lgr->max_links <= 1)
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
   net/smc/smc_llc.c:1175:34: note: place parentheses around the '&&' expression to silence this warning
    1175 |             lgr->type == SMC_LGR_SINGLE && lgr->max_links <= 1)
         |                                         ^                     
         |             (                                                 )
   1 warning generated.


vim +1175 net/smc/smc_llc.c

  1160	
  1161	/* as an SMC client, invite server to start the add_link processing */
  1162	static void smc_llc_cli_add_link_invite(struct smc_link *link,
  1163						struct smc_llc_qentry *qentry)
  1164	{
  1165		struct smc_link_group *lgr = smc_get_lgr(link);
  1166		struct smc_init_info *ini;
  1167	
  1168		if (lgr->smc_version == SMC_V2) {
  1169			smc_llc_send_request_add_link(link);
  1170			goto free_qentry;
  1171		}
  1172	
  1173		if (lgr->type == SMC_LGR_SYMMETRIC ||
  1174		    lgr->type == SMC_LGR_ASYMMETRIC_PEER ||
> 1175		    lgr->type == SMC_LGR_SINGLE && lgr->max_links <= 1)
  1176			goto free_qentry;
  1177	
  1178		ini = kzalloc(sizeof(*ini), GFP_KERNEL);
  1179		if (!ini)
  1180			goto free_qentry;
  1181	
  1182		ini->vlan_id = lgr->vlan_id;
  1183		smc_pnet_find_alt_roce(lgr, ini, link->smcibdev);
  1184		if (!ini->ib_dev)
  1185			goto out;
  1186	
  1187		smc_llc_send_add_link(link, ini->ib_dev->mac[ini->ib_port - 1],
  1188				      ini->ib_gid, NULL, SMC_LLC_REQ);
  1189	out:
  1190		kfree(ini);
  1191	free_qentry:
  1192		kfree(qentry);
  1193	}
  1194
kernel test robot Dec. 31, 2023, 10:40 p.m. UTC | #2
Hi Markus,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net/main]
[also build test WARNING on net-next/main linus/master v6.7-rc7 next-20231222]
[cannot apply to horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Markus-Elfring/net-smc-Return-directly-after-a-failed-kzalloc-in-smc_fill_gid_list/20231231-231406
base:   net/main
patch link:    https://lore.kernel.org/r/5253e660-6b66-4775-ae2f-06f5a1d40be5%40web.de
patch subject: [PATCH 2/2] net/smc: Improve exception handling in smc_llc_cli_add_link_invite()
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20240101/202401010657.eexbMD1F-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240101/202401010657.eexbMD1F-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401010657.eexbMD1F-lkp@intel.com/

All warnings (new ones prefixed by >>):

   net/smc/smc_llc.c: In function 'smc_llc_cli_add_link_invite':
>> net/smc/smc_llc.c:1175:41: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    1175 |             lgr->type == SMC_LGR_SINGLE && lgr->max_links <= 1)
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~


vim +1175 net/smc/smc_llc.c

  1160	
  1161	/* as an SMC client, invite server to start the add_link processing */
  1162	static void smc_llc_cli_add_link_invite(struct smc_link *link,
  1163						struct smc_llc_qentry *qentry)
  1164	{
  1165		struct smc_link_group *lgr = smc_get_lgr(link);
  1166		struct smc_init_info *ini;
  1167	
  1168		if (lgr->smc_version == SMC_V2) {
  1169			smc_llc_send_request_add_link(link);
  1170			goto free_qentry;
  1171		}
  1172	
  1173		if (lgr->type == SMC_LGR_SYMMETRIC ||
  1174		    lgr->type == SMC_LGR_ASYMMETRIC_PEER ||
> 1175		    lgr->type == SMC_LGR_SINGLE && lgr->max_links <= 1)
  1176			goto free_qentry;
  1177	
  1178		ini = kzalloc(sizeof(*ini), GFP_KERNEL);
  1179		if (!ini)
  1180			goto free_qentry;
  1181	
  1182		ini->vlan_id = lgr->vlan_id;
  1183		smc_pnet_find_alt_roce(lgr, ini, link->smcibdev);
  1184		if (!ini->ib_dev)
  1185			goto out;
  1186	
  1187		smc_llc_send_add_link(link, ini->ib_dev->mac[ini->ib_port - 1],
  1188				      ini->ib_gid, NULL, SMC_LLC_REQ);
  1189	out:
  1190		kfree(ini);
  1191	free_qentry:
  1192		kfree(qentry);
  1193	}
  1194
Tony Lu Jan. 2, 2024, 2:19 a.m. UTC | #3
On Sun, Dec 31, 2023 at 04:00:22PM +0100, Markus Elfring wrote:
> 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>

Thank you, LGTM. Also net and Fixes tags are needed.

Reviewed-by: Tony Lu <tonylu@linux.alibaba.com>
> ---
>  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
diff mbox series

Patch

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);
 }