Skip to content

Commit 20635bc

Browse files
krzkandersson
authored andcommitted
soc: qcom: ocmem: simplify with cleanup.h
Allocate the memory with scoped/cleanup.h to reduce error handling (less error paths) 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: Bjorn Andersson <[email protected]>
1 parent 01dd825 commit 20635bc

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/soc/qcom/ocmem.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <linux/bitfield.h>
13+
#include <linux/cleanup.h>
1314
#include <linux/clk.h>
1415
#include <linux/io.h>
1516
#include <linux/kernel.h>
@@ -216,7 +217,6 @@ EXPORT_SYMBOL_GPL(of_get_ocmem);
216217
struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client,
217218
unsigned long size)
218219
{
219-
struct ocmem_buf *buf;
220220
int ret;
221221

222222
/* TODO: add support for other clients... */
@@ -229,7 +229,7 @@ struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client,
229229
if (test_and_set_bit_lock(BIT(client), &ocmem->active_allocations))
230230
return ERR_PTR(-EBUSY);
231231

232-
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
232+
struct ocmem_buf *buf __free(kfree) = kzalloc(sizeof(*buf), GFP_KERNEL);
233233
if (!buf) {
234234
ret = -ENOMEM;
235235
goto err_unlock;
@@ -247,7 +247,7 @@ struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client,
247247
if (ret) {
248248
dev_err(ocmem->dev, "could not lock: %d\n", ret);
249249
ret = -EINVAL;
250-
goto err_kfree;
250+
goto err_unlock;
251251
}
252252
} else {
253253
ocmem_write(ocmem, OCMEM_REG_GFX_MPU_START, buf->offset);
@@ -258,10 +258,8 @@ struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client,
258258
dev_dbg(ocmem->dev, "using %ldK of OCMEM at 0x%08lx for client %d\n",
259259
size / 1024, buf->addr, client);
260260

261-
return buf;
261+
return_ptr(buf);
262262

263-
err_kfree:
264-
kfree(buf);
265263
err_unlock:
266264
clear_bit_unlock(BIT(client), &ocmem->active_allocations);
267265

0 commit comments

Comments
 (0)