From: Bjorn Andersson <andersson@kernel.org>
To: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Cc: Bartosz Golaszewski <brgl@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Subject: Re: [PATCH v2 2/4] firmware: qcom: scm: use __free(qcom_tzmem) to simplify cleanup
Date: Tue, 4 Aug 2026 17:30:47 -0500 [thread overview]
Message-ID: <anJn_Cf0mgVNstHj@baldur> (raw)
In-Reply-To: <20260731-qcom-scm-code-shrink-v2-2-4ba76096915f@oss.qualcomm.com>
On Fri, Jul 31, 2026 at 10:00:35AM +0200, Bartosz Golaszewski wrote:
> 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>
I tried to pick patch 1 and 2, but it doesn't compile. Please have a
look.
Regards,
Bjorn
> ---
> drivers/firmware/qcom/qcom_scm.c | 49 ++++++++++++++++------------------------
> 1 file changed, 20 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
> index f35f2ee39130413ab3798551b4055228008222b4..10c79d2e59a14af0532c515d332f65bdfea05621 100644
> --- a/drivers/firmware/qcom/qcom_scm.c
> +++ b/drivers/firmware/qcom/qcom_scm.c
> @@ -634,10 +634,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;
>
> @@ -646,11 +645,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_image2(struct device *dev, u32 pas_id,
> @@ -773,10 +771,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);
>
> @@ -796,20 +795,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_table2(struct device *dev,
> @@ -820,8 +816,6 @@ static void *__qcom_scm_pas_get_rsc_table2(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;
>
> @@ -843,7 +837,9 @@ static void *__qcom_scm_pas_get_rsc_table2(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;
> @@ -851,9 +847,9 @@ static void *__qcom_scm_pas_get_rsc_table2(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 the size requested by the TZ */
> output_rt_tzm = __qcom_scm_pas_get_rsc_table(dev, ctx->pas_id,
> @@ -862,21 +858,16 @@ static void *__qcom_scm_pas_get_rsc_table2(struct device *dev,
> &size);
> if (IS_ERR(output_rt_tzm)) {
> ret = PTR_ERR(output_rt_tzm);
> - goto free_input_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;
> }
>
> *output_rt_size = size;
> - qcom_tzmem_free(output_rt_tzm);
> -
> -free_input_rt:
> - qcom_tzmem_free(input_rt_tzm);
>
> disable_scm_bw:
> qcom_scm_bw_disable();
>
> --
> 2.47.3
>
next prev parent reply other threads:[~2026-08-04 22:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 8:00 [PATCH v2 0/4] firmware: qcom: scm: simplify code by using classes Bartosz Golaszewski
2026-07-31 8:00 ` [PATCH v2 1/4] firmware: qcom: tzmem: guard against IS_ERR() in the cleanup handler Bartosz Golaszewski
2026-07-31 8:00 ` [PATCH v2 2/4] firmware: qcom: scm: use __free(qcom_tzmem) to simplify cleanup Bartosz Golaszewski
2026-08-04 22:30 ` Bjorn Andersson [this message]
2026-07-31 8:00 ` [PATCH v2 3/4] firmware: qcom: scm: introduce qcom_scm_clk class for clock management Bartosz Golaszewski
2026-08-04 15:35 ` Bjorn Andersson
2026-07-31 8:00 ` [PATCH v2 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=anJn_Cf0mgVNstHj@baldur \
--to=andersson@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--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