Skip to content

Commit 2ee8323

Browse files
GoodLuck612ij-intel
authored andcommitted
platform/x86/amd: Use scope-based cleanup for wbrf_record()
Simplify resource management in wbrf_record() by using the scope-based cleanup helper __free(). This ensures that the tmp and obj are automatically freed when they go out of scope, eliminating the need for explicit error handling labels and manual freeing. Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Suggested-by: Markus Elfring <Markus.Elfring@web.de> Co-developed-by: Jianhao Xu <jianhao.xu@seu.edu.cn> Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn> Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Link: https://patch.msgid.link/20260106091318.747019-2-zilin@seu.edu.cn Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 6343e06 commit 2ee8323

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

  • drivers/platform/x86/amd

drivers/platform/x86/amd/wbrf.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ static BLOCKING_NOTIFIER_HEAD(wbrf_chain_head);
4242
static int wbrf_record(struct acpi_device *adev, uint8_t action, struct wbrf_ranges_in_out *in)
4343
{
4444
union acpi_object argv4;
45-
union acpi_object *tmp;
46-
union acpi_object *obj;
4745
u32 num_of_ranges = 0;
4846
u32 num_of_elements;
4947
u32 arg_idx = 0;
@@ -74,7 +72,7 @@ static int wbrf_record(struct acpi_device *adev, uint8_t action, struct wbrf_ran
7472
*/
7573
num_of_elements = 2 * num_of_ranges + 2;
7674

77-
tmp = kcalloc(num_of_elements, sizeof(*tmp), GFP_KERNEL);
75+
union acpi_object *tmp __free(kfree) = kcalloc(num_of_elements, sizeof(*tmp), GFP_KERNEL);
7876
if (!tmp)
7977
return -ENOMEM;
8078

@@ -101,26 +99,19 @@ static int wbrf_record(struct acpi_device *adev, uint8_t action, struct wbrf_ran
10199
tmp[arg_idx++].integer.value = in->band_list[i].end;
102100
}
103101

104-
obj = acpi_evaluate_dsm(adev->handle, &wifi_acpi_dsm_guid,
105-
WBRF_REVISION, WBRF_RECORD, &argv4);
102+
union acpi_object *obj __free(kfree) =
103+
acpi_evaluate_dsm(adev->handle, &wifi_acpi_dsm_guid,
104+
WBRF_REVISION, WBRF_RECORD, &argv4);
106105

107-
if (!obj) {
108-
kfree(tmp);
106+
if (!obj)
109107
return -EINVAL;
110-
}
111108

112-
if (obj->type != ACPI_TYPE_INTEGER) {
113-
ret = -EINVAL;
114-
goto out;
115-
}
109+
if (obj->type != ACPI_TYPE_INTEGER)
110+
return -EINVAL;
116111

117112
ret = obj->integer.value;
118113
if (ret)
119-
ret = -EINVAL;
120-
121-
out:
122-
ACPI_FREE(obj);
123-
kfree(tmp);
114+
return -EINVAL;
124115

125116
return ret;
126117
}

0 commit comments

Comments
 (0)