Commit 20635bcc authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Bjorn Andersson

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: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240703-thermal-const-v1-3-6e59e139c65d@linaro.orgSigned-off-by: default avatarBjorn Andersson <andersson@kernel.org>
parent 01dd825d
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
*/ */
#include <linux/bitfield.h> #include <linux/bitfield.h>
#include <linux/cleanup.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -216,7 +217,6 @@ EXPORT_SYMBOL_GPL(of_get_ocmem); ...@@ -216,7 +217,6 @@ EXPORT_SYMBOL_GPL(of_get_ocmem);
struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client, struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client,
unsigned long size) unsigned long size)
{ {
struct ocmem_buf *buf;
int ret; int ret;
/* TODO: add support for other clients... */ /* TODO: add support for other clients... */
...@@ -229,7 +229,7 @@ struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client, ...@@ -229,7 +229,7 @@ struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client,
if (test_and_set_bit_lock(BIT(client), &ocmem->active_allocations)) if (test_and_set_bit_lock(BIT(client), &ocmem->active_allocations))
return ERR_PTR(-EBUSY); return ERR_PTR(-EBUSY);
buf = kzalloc(sizeof(*buf), GFP_KERNEL); struct ocmem_buf *buf __free(kfree) = kzalloc(sizeof(*buf), GFP_KERNEL);
if (!buf) { if (!buf) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_unlock; goto err_unlock;
...@@ -247,7 +247,7 @@ struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client, ...@@ -247,7 +247,7 @@ struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client,
if (ret) { if (ret) {
dev_err(ocmem->dev, "could not lock: %d\n", ret); dev_err(ocmem->dev, "could not lock: %d\n", ret);
ret = -EINVAL; ret = -EINVAL;
goto err_kfree; goto err_unlock;
} }
} else { } else {
ocmem_write(ocmem, OCMEM_REG_GFX_MPU_START, buf->offset); 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, ...@@ -258,10 +258,8 @@ struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client,
dev_dbg(ocmem->dev, "using %ldK of OCMEM at 0x%08lx for client %d\n", dev_dbg(ocmem->dev, "using %ldK of OCMEM at 0x%08lx for client %d\n",
size / 1024, buf->addr, client); size / 1024, buf->addr, client);
return buf; return_ptr(buf);
err_kfree:
kfree(buf);
err_unlock: err_unlock:
clear_bit_unlock(BIT(client), &ocmem->active_allocations); clear_bit_unlock(BIT(client), &ocmem->active_allocations);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment