From: Abel Vesa <abel.vesa@linaro.org>
To: Tudor Ambarus <tudor.ambarus@linaro.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Ulf Hansson <ulf.hansson@linaro.org>,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Eric Biggers <ebiggers@google.com>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org,
andre.draszik@linaro.org, peter.griffin@linaro.org,
willmcvicker@google.com, kernel-team@android.com
Subject: Re: [PATCH v2 1/4] soc: qcom: ice: introduce devm_of_qcom_ice_get
Date: Sun, 19 Jan 2025 18:57:32 +0200 [thread overview]
Message-ID: <Z40u/DkEQIK9naI2@linaro.org> (raw)
In-Reply-To: <20250117-qcom-ice-fix-dev-leak-v2-1-1ffa5b6884cb@linaro.org>
On 25-01-17 14:18:50, Tudor Ambarus wrote:
> Callers of of_qcom_ice_get() leak the device reference taken by
> of_find_device_by_node(). Introduce devm variant for of_qcom_ice_get().
> Existing consumers need the ICE instance for the entire life of their
> device, thus exporting qcom_ice_put() is not required.
>
> Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Good catch. LGTM.
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
> ---
> drivers/soc/qcom/ice.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> include/soc/qcom/ice.h | 2 ++
> 2 files changed, 50 insertions(+)
>
> diff --git a/drivers/soc/qcom/ice.c b/drivers/soc/qcom/ice.c
> index 393d2d1d275f..79e04bff3e33 100644
> --- a/drivers/soc/qcom/ice.c
> +++ b/drivers/soc/qcom/ice.c
> @@ -11,6 +11,7 @@
> #include <linux/cleanup.h>
> #include <linux/clk.h>
> #include <linux/delay.h>
> +#include <linux/device.h>
> #include <linux/iopoll.h>
> #include <linux/of.h>
> #include <linux/of_platform.h>
> @@ -324,6 +325,53 @@ struct qcom_ice *of_qcom_ice_get(struct device *dev)
> }
> EXPORT_SYMBOL_GPL(of_qcom_ice_get);
>
> +static void qcom_ice_put(const struct qcom_ice *ice)
> +{
> + struct platform_device *pdev = to_platform_device(ice->dev);
> +
> + if (!platform_get_resource_byname(pdev, IORESOURCE_MEM, "ice"))
> + platform_device_put(pdev);
> +}
> +
> +static void devm_of_qcom_ice_put(struct device *dev, void *res)
> +{
> + qcom_ice_put(*(struct qcom_ice **)res);
> +}
> +
> +/**
> + * devm_of_qcom_ice_get() - Devres managed helper to get an ICE instance from
> + * a DT node.
> + * @dev: device pointer for the consumer device.
> + *
> + * This function will provide an ICE instance either by creating one for the
> + * consumer device if its DT node provides the 'ice' reg range and the 'ice'
> + * clock (for legacy DT style). On the other hand, if consumer provides a
> + * phandle via 'qcom,ice' property to an ICE DT, the ICE instance will already
> + * be created and so this function will return that instead.
> + *
> + * Return: ICE pointer on success, NULL if there is no ICE data provided by the
> + * consumer or ERR_PTR() on error.
> + */
> +struct qcom_ice *devm_of_qcom_ice_get(struct device *dev)
> +{
> + struct qcom_ice *ice, **dr;
> +
> + dr = devres_alloc(devm_of_qcom_ice_put, sizeof(*dr), GFP_KERNEL);
> + if (!dr)
> + return ERR_PTR(-ENOMEM);
> +
> + ice = of_qcom_ice_get(dev);
> + if (!IS_ERR_OR_NULL(ice)) {
> + *dr = ice;
> + devres_add(dev, dr);
> + } else {
> + devres_free(dr);
> + }
> +
> + return ice;
> +}
> +EXPORT_SYMBOL_GPL(devm_of_qcom_ice_get);
> +
> static int qcom_ice_probe(struct platform_device *pdev)
> {
> struct qcom_ice *engine;
> diff --git a/include/soc/qcom/ice.h b/include/soc/qcom/ice.h
> index 5870a94599a2..d5f6a228df65 100644
> --- a/include/soc/qcom/ice.h
> +++ b/include/soc/qcom/ice.h
> @@ -34,4 +34,6 @@ int qcom_ice_program_key(struct qcom_ice *ice,
> int slot);
> int qcom_ice_evict_key(struct qcom_ice *ice, int slot);
> struct qcom_ice *of_qcom_ice_get(struct device *dev);
> +struct qcom_ice *devm_of_qcom_ice_get(struct device *dev);
> +
> #endif /* __QCOM_ICE_H__ */
>
> --
> 2.48.0.rc2.279.g1de40edade-goog
>
next prev parent reply other threads:[~2025-01-19 16:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-17 14:18 [PATCH v2 0/4] soc: qcom: ice: fix dev reference leaked through of_qcom_ice_get Tudor Ambarus
2025-01-17 14:18 ` [PATCH v2 1/4] soc: qcom: ice: introduce devm_of_qcom_ice_get Tudor Ambarus
2025-01-18 13:31 ` Krzysztof Kozlowski
2025-01-19 16:57 ` Abel Vesa [this message]
2025-01-17 14:18 ` [PATCH v2 2/4] mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get Tudor Ambarus
2025-01-19 16:59 ` Abel Vesa
2025-01-17 14:18 ` [PATCH v2 3/4] scsi: ufs: qcom: " Tudor Ambarus
2025-01-19 16:59 ` Abel Vesa
2025-02-03 21:43 ` Martin K. Petersen
2025-01-17 14:18 ` [PATCH v2 4/4] soc: qcom: ice: make of_qcom_ice_get() static Tudor Ambarus
2025-01-19 16:58 ` Abel Vesa
2025-01-24 7:38 ` [PATCH v2 0/4] soc: qcom: ice: fix dev reference leaked through of_qcom_ice_get Manivannan Sadhasivam
2025-02-14 22:38 ` Bjorn Andersson
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=Z40u/DkEQIK9naI2@linaro.org \
--to=abel.vesa@linaro.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=adrian.hunter@intel.com \
--cc=andersson@kernel.org \
--cc=andre.draszik@linaro.org \
--cc=ebiggers@google.com \
--cc=kernel-team@android.com \
--cc=konradybcio@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=martin.petersen@oracle.com \
--cc=peter.griffin@linaro.org \
--cc=tudor.ambarus@linaro.org \
--cc=ulf.hansson@linaro.org \
--cc=willmcvicker@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.