diff mbox series

[v2,2/2] platform/x86: dell-smbios: Simplify error handling

Message ID 20240528204903.445546-2-W_Armin@gmx.de (mailing list archive)
State Accepted, archived
Delegated to: Hans de Goede
Headers show
Series [v2,1/2] platform/x86: dell-smbios: Fix wrong token data in sysfs | expand

Commit Message

Armin Wolf May 28, 2024, 8:49 p.m. UTC
When the allocation of value_name fails, the error handling code
uses two gotos for error handling, which is not necessary.

Simplify the error handling in this case by only using a single goto.

Tested on a Dell Inspiron 3505.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
Changes since v1:
- add patch
---
 drivers/platform/x86/dell/dell-smbios-base.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

--
2.39.2

Comments

Ilpo Järvinen May 31, 2024, 4:19 p.m. UTC | #1
On Tue, 28 May 2024, Armin Wolf wrote:

> When the allocation of value_name fails, the error handling code
> uses two gotos for error handling, which is not necessary.
> 
> Simplify the error handling in this case by only using a single goto.
> 
> Tested on a Dell Inspiron 3505.
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
> Changes since v1:
> - add patch
> ---
>  drivers/platform/x86/dell/dell-smbios-base.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/platform/x86/dell/dell-smbios-base.c b/drivers/platform/x86/dell/dell-smbios-base.c
> index 86b95206cb1b..b562ed99ec4e 100644
> --- a/drivers/platform/x86/dell/dell-smbios-base.c
> +++ b/drivers/platform/x86/dell/dell-smbios-base.c
> @@ -492,19 +492,16 @@ static int build_tokens_sysfs(struct platform_device *dev)
>  		/* add value */
>  		value_name = kasprintf(GFP_KERNEL, "%04x_value",
>  				       da_tokens[i].tokenID);
> -		if (value_name == NULL)
> -			goto loop_fail_create_value;
> +		if (!value_name) {
> +			kfree(location_name);
> +			goto out_unwind_strings;
> +		}
> 
>  		sysfs_attr_init(&token_entries[i].value_attr.attr);
>  		token_entries[i].value_attr.attr.name = value_name;
>  		token_entries[i].value_attr.attr.mode = 0444;
>  		token_entries[i].value_attr.show = value_show;
>  		token_attrs[j++] = &token_entries[i].value_attr.attr;
> -		continue;
> -
> -loop_fail_create_value:
> -		kfree(location_name);
> -		goto out_unwind_strings;
>  	}
>  	smbios_attribute_group.attrs = token_attrs;

Good cleanup. Using continue on the main level of a loop is almost never a 
good idea.

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
diff mbox series

Patch

diff --git a/drivers/platform/x86/dell/dell-smbios-base.c b/drivers/platform/x86/dell/dell-smbios-base.c
index 86b95206cb1b..b562ed99ec4e 100644
--- a/drivers/platform/x86/dell/dell-smbios-base.c
+++ b/drivers/platform/x86/dell/dell-smbios-base.c
@@ -492,19 +492,16 @@  static int build_tokens_sysfs(struct platform_device *dev)
 		/* add value */
 		value_name = kasprintf(GFP_KERNEL, "%04x_value",
 				       da_tokens[i].tokenID);
-		if (value_name == NULL)
-			goto loop_fail_create_value;
+		if (!value_name) {
+			kfree(location_name);
+			goto out_unwind_strings;
+		}

 		sysfs_attr_init(&token_entries[i].value_attr.attr);
 		token_entries[i].value_attr.attr.name = value_name;
 		token_entries[i].value_attr.attr.mode = 0444;
 		token_entries[i].value_attr.show = value_show;
 		token_attrs[j++] = &token_entries[i].value_attr.attr;
-		continue;
-
-loop_fail_create_value:
-		kfree(location_name);
-		goto out_unwind_strings;
 	}
 	smbios_attribute_group.attrs = token_attrs;