Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Zilin Guan and committed by
Ilpo Järvinen
2ee83230 6343e067

+8 -17
+8 -17
drivers/platform/x86/amd/wbrf.c
··· 42 42 static int wbrf_record(struct acpi_device *adev, uint8_t action, struct wbrf_ranges_in_out *in) 43 43 { 44 44 union acpi_object argv4; 45 - union acpi_object *tmp; 46 - union acpi_object *obj; 47 45 u32 num_of_ranges = 0; 48 46 u32 num_of_elements; 49 47 u32 arg_idx = 0; ··· 72 74 */ 73 75 num_of_elements = 2 * num_of_ranges + 2; 74 76 75 - tmp = kcalloc(num_of_elements, sizeof(*tmp), GFP_KERNEL); 77 + union acpi_object *tmp __free(kfree) = kcalloc(num_of_elements, sizeof(*tmp), GFP_KERNEL); 76 78 if (!tmp) 77 79 return -ENOMEM; 78 80 ··· 99 101 tmp[arg_idx++].integer.value = in->band_list[i].end; 100 102 } 101 103 102 - obj = acpi_evaluate_dsm(adev->handle, &wifi_acpi_dsm_guid, 103 - WBRF_REVISION, WBRF_RECORD, &argv4); 104 + union acpi_object *obj __free(kfree) = 105 + acpi_evaluate_dsm(adev->handle, &wifi_acpi_dsm_guid, 106 + WBRF_REVISION, WBRF_RECORD, &argv4); 104 107 105 - if (!obj) { 106 - kfree(tmp); 108 + if (!obj) 107 109 return -EINVAL; 108 - } 109 110 110 - if (obj->type != ACPI_TYPE_INTEGER) { 111 - ret = -EINVAL; 112 - goto out; 113 - } 111 + if (obj->type != ACPI_TYPE_INTEGER) 112 + return -EINVAL; 114 113 115 114 ret = obj->integer.value; 116 115 if (ret) 117 - ret = -EINVAL; 118 - 119 - out: 120 - ACPI_FREE(obj); 121 - kfree(tmp); 116 + return -EINVAL; 122 117 123 118 return ret; 124 119 }