Skip to content

Commit 1f93cb2

Browse files
krzkvinodkoul
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 02611ee commit 1f93cb2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/soundwire/amd_init.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <linux/acpi.h>
11+
#include <linux/cleanup.h>
1112
#include <linux/export.h>
1213
#include <linux/io.h>
1314
#include <linux/module.h>
@@ -69,7 +70,6 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
6970
{
7071
struct sdw_amd_ctx *ctx;
7172
struct acpi_device *adev;
72-
struct resource *sdw_res;
7373
struct acp_sdw_pdata sdw_pdata[2];
7474
struct platform_device_info pdevinfo[2];
7575
u32 link_mask;
@@ -104,7 +104,8 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
104104

105105
ctx->count = count;
106106
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);
108109
if (!sdw_res) {
109110
kfree(ctx);
110111
return NULL;
@@ -132,7 +133,6 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
132133
if (IS_ERR(ctx->pdev[index]))
133134
goto err;
134135
}
135-
kfree(sdw_res);
136136
return ctx;
137137
err:
138138
while (index--) {
@@ -142,7 +142,6 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res)
142142
platform_device_unregister(ctx->pdev[index]);
143143
}
144144

145-
kfree(sdw_res);
146145
kfree(ctx);
147146
return NULL;
148147
}

0 commit comments

Comments
 (0)