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

soundwire: amd_init: simplify with cleanup.h

Allocate the memory with scoped/cleanup.h to reduce error handling and
make the code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240703-soundwire-cleanup-h-v1-3-24fa0dbb948f@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Vinod Koul
1f93cb22 02611eee

+3 -4
+3 -4
drivers/soundwire/amd_init.c
··· 8 8 */ 9 9 10 10 #include <linux/acpi.h> 11 + #include <linux/cleanup.h> 11 12 #include <linux/export.h> 12 13 #include <linux/io.h> 13 14 #include <linux/module.h> ··· 70 69 { 71 70 struct sdw_amd_ctx *ctx; 72 71 struct acpi_device *adev; 73 - struct resource *sdw_res; 74 72 struct acp_sdw_pdata sdw_pdata[2]; 75 73 struct platform_device_info pdevinfo[2]; 76 74 u32 link_mask; ··· 104 104 105 105 ctx->count = count; 106 106 ctx->link_mask = res->link_mask; 107 - sdw_res = kzalloc(sizeof(*sdw_res), GFP_KERNEL); 107 + struct resource *sdw_res __free(kfree) = kzalloc(sizeof(*sdw_res), 108 + GFP_KERNEL); 108 109 if (!sdw_res) { 109 110 kfree(ctx); 110 111 return NULL; ··· 133 132 if (IS_ERR(ctx->pdev[index])) 134 133 goto err; 135 134 } 136 - kfree(sdw_res); 137 135 return ctx; 138 136 err: 139 137 while (index--) { ··· 142 142 platform_device_unregister(ctx->pdev[index]); 143 143 } 144 144 145 - kfree(sdw_res); 146 145 kfree(ctx); 147 146 return NULL; 148 147 }