From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
To: Bartosz Golaszewski <brgl@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Abel Vesa <abelvesa@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Subject: [PATCH v4 2/4] firmware: qcom: scm: use __free(qcom_tzmem) to simplify cleanup
Date: Mon, 02 Nov 2026 11:18:53 +0100 [thread overview]
Message-ID: <20261102-qcom-scm-code-shrink-v4-2-21fdbe876883@oss.qualcomm.com> (raw)
In-Reply-To: <20261102-qcom-scm-code-shrink-v4-0-21fdbe876883@oss.qualcomm.com>
Use the __free(qcom_tzmem) cleanup attribute (together with no_free_ptr()
whenever ownership is transferred) to replace open-coded
qcom_tzmem_free() calls and their associated goto labels.
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Reviewed-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/firmware/qcom/qcom_scm.c | 53 +++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 31 deletions(-)
diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index 43e250faea75ab7c8387a5ad5f17bd35fdf3e518..2fad9607fb0d55c33893785ec0db602c4f9e6bdf 100644
--- a/drivers/firmware/qcom/qcom_scm.c
+++ b/drivers/firmware/qcom/qcom_scm.c
@@ -614,10 +614,9 @@ static int qcom_scm_pas_prep_and_init_image(struct device *dev,
{
struct qcom_scm_res res;
phys_addr_t mdata_phys;
- void *mdata_buf;
int ret;
- mdata_buf = qcom_tzmem_alloc(__scm->mempool, size, GFP_KERNEL);
+ void *mdata_buf __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool, size, GFP_KERNEL);
if (!mdata_buf)
return -ENOMEM;
@@ -626,11 +625,10 @@ static int qcom_scm_pas_prep_and_init_image(struct device *dev,
ret = __qcom_scm_pas_init_image(dev, ctx->pas_id, mdata_phys, &res);
if (ret < 0)
- qcom_tzmem_free(mdata_buf);
- else
- ctx->ptr = mdata_buf;
+ return ret;
- return ret ? : res.result[0];
+ ctx->ptr = no_free_ptr(mdata_buf);
+ return res.result[0];
}
static int qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
@@ -732,10 +730,11 @@ static void *__qcom_scm_pas_get_rsc_table(struct device *dev, u32 pas_id,
.owner = ARM_SMCCC_OWNER_SIP,
};
struct qcom_scm_res res;
- void *output_rt_tzm;
int ret;
- output_rt_tzm = qcom_tzmem_alloc(__scm->mempool, *output_rt_size, GFP_KERNEL);
+ void *output_rt_tzm __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool,
+ *output_rt_size,
+ GFP_KERNEL);
if (!output_rt_tzm)
return ERR_PTR(-ENOMEM);
@@ -755,20 +754,17 @@ static void *__qcom_scm_pas_get_rsc_table(struct device *dev, u32 pas_id,
* be of unresonable size.
*/
ret = qcom_scm_call(dev, &desc, &res);
- if (!ret && res.result[2] > SZ_1G) {
- ret = -E2BIG;
- goto free_output_rt;
- }
+ if (!ret && res.result[2] > SZ_1G)
+ return ERR_PTR(-E2BIG);
*output_rt_size = res.result[2];
if (ret && res.result[1] == RSCTABLE_BUFFER_NOT_SUFFICIENT)
- ret = -EOVERFLOW;
+ return ERR_PTR(-EOVERFLOW);
-free_output_rt:
if (ret)
- qcom_tzmem_free(output_rt_tzm);
+ return ERR_PTR(ret);
- return ret ? ERR_PTR(ret) : output_rt_tzm;
+ return no_free_ptr(output_rt_tzm);
}
static void *qcom_scm_pas_get_rsc_table(struct device *dev,
@@ -778,8 +774,6 @@ static void *qcom_scm_pas_get_rsc_table(struct device *dev,
{
struct resource_table empty_rsc = {};
size_t size = SZ_16K;
- void *output_rt_tzm;
- void *input_rt_tzm;
void *tbl_ptr;
int ret;
@@ -801,7 +795,9 @@ static void *qcom_scm_pas_get_rsc_table(struct device *dev,
input_rt_size = sizeof(empty_rsc);
}
- input_rt_tzm = qcom_tzmem_alloc(__scm->mempool, input_rt_size, GFP_KERNEL);
+ void *input_rt_tzm __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool,
+ input_rt_size,
+ GFP_KERNEL);
if (!input_rt_tzm) {
ret = -ENOMEM;
goto disable_scm_bw;
@@ -809,9 +805,9 @@ static void *qcom_scm_pas_get_rsc_table(struct device *dev,
memcpy(input_rt_tzm, input_rt, input_rt_size);
- output_rt_tzm = __qcom_scm_pas_get_rsc_table(dev, ctx->pas_id,
- input_rt_tzm,
- input_rt_size, &size);
+ void *output_rt_tzm __free(qcom_tzmem) =
+ __qcom_scm_pas_get_rsc_table(dev, ctx->pas_id, input_rt_tzm,
+ input_rt_size, &size);
if (PTR_ERR(output_rt_tzm) == -EOVERFLOW) {
/* Try again with a page-aligned size requested by the TZ. */
size = PAGE_ALIGN(size);
@@ -822,7 +818,7 @@ static void *qcom_scm_pas_get_rsc_table(struct device *dev,
}
if (IS_ERR(output_rt_tzm)) {
ret = PTR_ERR(output_rt_tzm);
- goto free_input_rt;
+ goto disable_scm_bw;
}
*output_rt_size = size;
@@ -830,21 +826,16 @@ static void *qcom_scm_pas_get_rsc_table(struct device *dev,
/* A zero-sized table means that TrustZone has no resource table. */
if (!size) {
tbl_ptr = NULL;
- goto free_output_rt;
+ goto disable_scm_bw;
}
tbl_ptr = kmemdup(output_rt_tzm, size, GFP_KERNEL);
if (!tbl_ptr) {
- qcom_tzmem_free(output_rt_tzm);
ret = -ENOMEM;
- goto free_input_rt;
+ goto disable_scm_bw;
}
-free_output_rt:
- qcom_tzmem_free(output_rt_tzm);
-
-free_input_rt:
- qcom_tzmem_free(input_rt_tzm);
+ *output_rt_size = size;
disable_scm_bw:
qcom_scm_bw_disable();
--
2.47.3
next prev parent reply other threads:[~2026-11-02 10:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 10:18 [PATCH v4 0/4] firmware: qcom: scm: simplify code by using classes Bartosz Golaszewski
2026-11-02 10:18 ` [PATCH v4 1/4] firmware: qcom: tzmem: guard against IS_ERR() in the cleanup handler Bartosz Golaszewski
2026-11-02 10:18 ` Bartosz Golaszewski [this message]
2026-11-02 10:18 ` [PATCH v4 3/4] firmware: qcom: scm: introduce qcom_scm_clk class for clock management Bartosz Golaszewski
2026-11-02 10:18 ` [PATCH v4 4/4] firmware: qcom: scm: introduce qcom_scm_bw class for bandwidth management Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261102-qcom-scm-code-shrink-v4-2-21fdbe876883@oss.qualcomm.com \
--to=bartosz.golaszewski@oss.qualcomm.com \
--cc=abelvesa@kernel.org \
--cc=andersson@kernel.org \
--cc=brgl@kernel.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mukesh.ojha@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®