diff mbox series

[2/2] batman-adv: Improve exception handling in batadv_throw_uevent()

Message ID d2ce9337-e1a4-4213-ad6f-926c085dc17f@web.de (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series batman-adv: 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 success Errors and warnings before: 1113 this patch: 1113
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 1140 this patch: 1140
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 success Errors and warnings before: 1140 this patch: 1140
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 37 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 Jan. 2, 2024, 7:12 a.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 2 Jan 2024 07:52:21 +0100

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

* Thus adjust jump targets.

* Reorder kfree() calls at the end.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/batman-adv/main.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

--
2.43.0

Comments

Sven Eckelmann Jan. 2, 2024, 11:24 a.m. UTC | #1
On Tuesday, 2 January 2024 08:12:56 CET Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 2 Jan 2024 07:52:21 +0100
> 
> The kfree() function was called in up to three cases by
> the batadv_throw_uevent() function during error handling
> even if the passed variable contained a null pointer.
> This issue was detected by using the Coccinelle software.
> 
> * Thus adjust jump targets.
> 
> * Reorder kfree() calls at the end.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Acked-by: Sven Eckelmann <sven@narfation.org>

> ---
>  net/batman-adv/main.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
> index 5fc754b0b3f7..75119f1ffccc 100644
> --- a/net/batman-adv/main.c
> +++ b/net/batman-adv/main.c
> @@ -691,29 +691,31 @@ int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
>  				  "%s%s", BATADV_UEV_TYPE_VAR,
>  				  batadv_uev_type_str[type]);
>  	if (!uevent_env[0])
> -		goto out;
> +		goto report_error;
> 
>  	uevent_env[1] = kasprintf(GFP_ATOMIC,
>  				  "%s%s", BATADV_UEV_ACTION_VAR,
>  				  batadv_uev_action_str[action]);
>  	if (!uevent_env[1])
> -		goto out;
> +		goto free_first_env;
> 
>  	/* If the event is DEL, ignore the data field */
>  	if (action != BATADV_UEV_DEL) {
>  		uevent_env[2] = kasprintf(GFP_ATOMIC,
>  					  "%s%s", BATADV_UEV_DATA_VAR, data);
>  		if (!uevent_env[2])
> -			goto out;
> +			goto free_second_env;
>  	}
> 
>  	ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
> -out:
> -	kfree(uevent_env[0]);
> -	kfree(uevent_env[1]);
>  	kfree(uevent_env[2]);
> +free_second_env:
> +	kfree(uevent_env[1]);
> +free_first_env:
> +	kfree(uevent_env[0]);
> 
>  	if (ret)
> +report_error:
>  		batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
>  			   "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
>  			   batadv_uev_type_str[type],
> --
> 2.43.0
> 
>
diff mbox series

Patch

diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 5fc754b0b3f7..75119f1ffccc 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -691,29 +691,31 @@  int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
 				  "%s%s", BATADV_UEV_TYPE_VAR,
 				  batadv_uev_type_str[type]);
 	if (!uevent_env[0])
-		goto out;
+		goto report_error;

 	uevent_env[1] = kasprintf(GFP_ATOMIC,
 				  "%s%s", BATADV_UEV_ACTION_VAR,
 				  batadv_uev_action_str[action]);
 	if (!uevent_env[1])
-		goto out;
+		goto free_first_env;

 	/* If the event is DEL, ignore the data field */
 	if (action != BATADV_UEV_DEL) {
 		uevent_env[2] = kasprintf(GFP_ATOMIC,
 					  "%s%s", BATADV_UEV_DATA_VAR, data);
 		if (!uevent_env[2])
-			goto out;
+			goto free_second_env;
 	}

 	ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
-out:
-	kfree(uevent_env[0]);
-	kfree(uevent_env[1]);
 	kfree(uevent_env[2]);
+free_second_env:
+	kfree(uevent_env[1]);
+free_first_env:
+	kfree(uevent_env[0]);

 	if (ret)
+report_error:
 		batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
 			   "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
 			   batadv_uev_type_str[type],