linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] soc: qcom: ice: fix dev reference leaked through of_qcom_ice_get
@ 2025-01-17 14:18 Tudor Ambarus
  2025-01-17 14:18 ` [PATCH v2 1/4] soc: qcom: ice: introduce devm_of_qcom_ice_get Tudor Ambarus
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Tudor Ambarus @ 2025-01-17 14:18 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Abel Vesa, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers
  Cc: linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, Tudor Ambarus, stable,
	Krzysztof Kozlowski

Hi!

Recently I've been pointed to this driver for an example on how consumers
can get a pointer to the supplier's driver data and I noticed a leak.

Callers of of_qcom_ice_get() leak the device reference taken by
of_find_device_by_node(). Introduce devm_of_qcom_ice_get().
Exporting qcom_ice_put() is not done intentionally as the consumers need
the ICE intance for the entire life of their device. Update the consumers
to use the devm variant and make of_qcom_ice_get() static afterwards.

This set touches mmc and scsi subsystems. Since the fix is trivial for
them, I'd suggest taking everything through the SoC tree with Acked-by
tags if people consider this fine. Note that the mmc and scsi patches
depend on the first patch that introduces devm_of_qcom_ice_get().

Thanks!

Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
---
Changes in v2:
- add kernel doc for newly introduced devm_of_qcom_ice_get().
- update cover letter and commit message of first patch.
- collect R-b and A-b tags.
- Link to v1: https://lore.kernel.org/r/20250116-qcom-ice-fix-dev-leak-v1-0-84d937683790@linaro.org

---
Tudor Ambarus (4):
      soc: qcom: ice: introduce devm_of_qcom_ice_get
      mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get
      scsi: ufs: qcom: fix dev reference leaked through of_qcom_ice_get
      soc: qcom: ice: make of_qcom_ice_get() static

 drivers/mmc/host/sdhci-msm.c |  2 +-
 drivers/soc/qcom/ice.c       | 51 ++++++++++++++++++++++++++++++++++++++++++--
 drivers/ufs/host/ufs-qcom.c  |  2 +-
 include/soc/qcom/ice.h       |  3 ++-
 4 files changed, 53 insertions(+), 5 deletions(-)
---
base-commit: b323d8e7bc03d27dec646bfdccb7d1a92411f189
change-id: 20250110-qcom-ice-fix-dev-leak-bbff59a964fb

Best regards,
-- 
Tudor Ambarus <tudor.ambarus@linaro.org>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/4] soc: qcom: ice: introduce devm_of_qcom_ice_get
  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 ` Tudor Ambarus
  2025-01-18 13:31   ` Krzysztof Kozlowski
  2025-01-19 16:57   ` Abel Vesa
  2025-01-17 14:18 ` [PATCH v2 2/4] mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get Tudor Ambarus
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 13+ messages in thread
From: Tudor Ambarus @ 2025-01-17 14:18 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Abel Vesa, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers
  Cc: linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, Tudor Ambarus

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>
---
 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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/4] mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get
  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-17 14:18 ` Tudor Ambarus
  2025-01-19 16:59   ` Abel Vesa
  2025-01-17 14:18 ` [PATCH v2 3/4] scsi: ufs: qcom: " Tudor Ambarus
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Tudor Ambarus @ 2025-01-17 14:18 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Abel Vesa, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers
  Cc: linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, Tudor Ambarus, stable,
	Krzysztof Kozlowski

The driver leaks the device reference taken with
of_find_device_by_node(). Fix the leak by using devm_of_qcom_ice_get().

Fixes: c7eed31e235c ("mmc: sdhci-msm: Switch to the new ICE API")
Cc: stable@vger.kernel.org
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/mmc/host/sdhci-msm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 4610f067faca..559ea5af27f2 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -1824,7 +1824,7 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
 	if (!(cqhci_readl(cq_host, CQHCI_CAP) & CQHCI_CAP_CS))
 		return 0;
 
-	ice = of_qcom_ice_get(dev);
+	ice = devm_of_qcom_ice_get(dev);
 	if (ice == ERR_PTR(-EOPNOTSUPP)) {
 		dev_warn(dev, "Disabling inline encryption support\n");
 		ice = NULL;

-- 
2.48.0.rc2.279.g1de40edade-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/4] scsi: ufs: qcom: fix dev reference leaked through of_qcom_ice_get
  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-17 14:18 ` [PATCH v2 2/4] mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get Tudor Ambarus
@ 2025-01-17 14:18 ` 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
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 13+ messages in thread
From: Tudor Ambarus @ 2025-01-17 14:18 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Abel Vesa, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers
  Cc: linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, Tudor Ambarus, stable,
	Krzysztof Kozlowski

The driver leaks the device reference taken with
of_find_device_by_node(). Fix the leak by using devm_of_qcom_ice_get().

Fixes: 56541c7c4468 ("scsi: ufs: ufs-qcom: Switch to the new ICE API")
Cc: stable@vger.kernel.org
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/ufs/host/ufs-qcom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 23b9f6efa047..a455a95f65fc 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -125,7 +125,7 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host)
 	int err;
 	int i;
 
-	ice = of_qcom_ice_get(dev);
+	ice = devm_of_qcom_ice_get(dev);
 	if (ice == ERR_PTR(-EOPNOTSUPP)) {
 		dev_warn(dev, "Disabling inline encryption support\n");
 		ice = NULL;

-- 
2.48.0.rc2.279.g1de40edade-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/4] soc: qcom: ice: make of_qcom_ice_get() static
  2025-01-17 14:18 [PATCH v2 0/4] soc: qcom: ice: fix dev reference leaked through of_qcom_ice_get Tudor Ambarus
                   ` (2 preceding siblings ...)
  2025-01-17 14:18 ` [PATCH v2 3/4] scsi: ufs: qcom: " Tudor Ambarus
@ 2025-01-17 14:18 ` 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
  5 siblings, 1 reply; 13+ messages in thread
From: Tudor Ambarus @ 2025-01-17 14:18 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Abel Vesa, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers
  Cc: linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, Tudor Ambarus,
	Krzysztof Kozlowski

There's no consumer calling it left, make the method static.

Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/soc/qcom/ice.c | 3 +--
 include/soc/qcom/ice.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/soc/qcom/ice.c b/drivers/soc/qcom/ice.c
index 79e04bff3e33..2310afa77b76 100644
--- a/drivers/soc/qcom/ice.c
+++ b/drivers/soc/qcom/ice.c
@@ -262,7 +262,7 @@ static struct qcom_ice *qcom_ice_create(struct device *dev,
  * Return: ICE pointer on success, NULL if there is no ICE data provided by the
  * consumer or ERR_PTR() on error.
  */
-struct qcom_ice *of_qcom_ice_get(struct device *dev)
+static struct qcom_ice *of_qcom_ice_get(struct device *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct qcom_ice *ice;
@@ -323,7 +323,6 @@ struct qcom_ice *of_qcom_ice_get(struct device *dev)
 
 	return ice;
 }
-EXPORT_SYMBOL_GPL(of_qcom_ice_get);
 
 static void qcom_ice_put(const struct qcom_ice *ice)
 {
diff --git a/include/soc/qcom/ice.h b/include/soc/qcom/ice.h
index d5f6a228df65..fdf1b5c21eb9 100644
--- a/include/soc/qcom/ice.h
+++ b/include/soc/qcom/ice.h
@@ -33,7 +33,6 @@ int qcom_ice_program_key(struct qcom_ice *ice,
 			 const u8 crypto_key[], u8 data_unit_size,
 			 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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/4] soc: qcom: ice: introduce devm_of_qcom_ice_get
  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
  1 sibling, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-01-18 13:31 UTC (permalink / raw)
  To: Tudor Ambarus, Bjorn Andersson, Konrad Dybcio, Adrian Hunter,
	Ulf Hansson, Abel Vesa, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers
  Cc: linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team

On 17/01/2025 15:18, 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>
> ---
>  drivers/soc/qcom/ice.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  include/soc/qcom/ice.h |  2 ++
>  2 files changed, 50 insertions(+)


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 1/4] soc: qcom: ice: introduce devm_of_qcom_ice_get
  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
  1 sibling, 0 replies; 13+ messages in thread
From: Abel Vesa @ 2025-01-19 16:57 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers,
	linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team

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
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 4/4] soc: qcom: ice: make of_qcom_ice_get() static
  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
  0 siblings, 0 replies; 13+ messages in thread
From: Abel Vesa @ 2025-01-19 16:58 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers,
	linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, Krzysztof Kozlowski

On 25-01-17 14:18:53, Tudor Ambarus wrote:
> There's no consumer calling it left, make the method static.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Reviewed-by: Abel Vesa <abel.vesa@linaro.org>

> ---
>  drivers/soc/qcom/ice.c | 3 +--
>  include/soc/qcom/ice.h | 1 -
>  2 files changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/soc/qcom/ice.c b/drivers/soc/qcom/ice.c
> index 79e04bff3e33..2310afa77b76 100644
> --- a/drivers/soc/qcom/ice.c
> +++ b/drivers/soc/qcom/ice.c
> @@ -262,7 +262,7 @@ static struct qcom_ice *qcom_ice_create(struct device *dev,
>   * Return: ICE pointer on success, NULL if there is no ICE data provided by the
>   * consumer or ERR_PTR() on error.
>   */
> -struct qcom_ice *of_qcom_ice_get(struct device *dev)
> +static struct qcom_ice *of_qcom_ice_get(struct device *dev)
>  {
>  	struct platform_device *pdev = to_platform_device(dev);
>  	struct qcom_ice *ice;
> @@ -323,7 +323,6 @@ struct qcom_ice *of_qcom_ice_get(struct device *dev)
>  
>  	return ice;
>  }
> -EXPORT_SYMBOL_GPL(of_qcom_ice_get);
>  
>  static void qcom_ice_put(const struct qcom_ice *ice)
>  {
> diff --git a/include/soc/qcom/ice.h b/include/soc/qcom/ice.h
> index d5f6a228df65..fdf1b5c21eb9 100644
> --- a/include/soc/qcom/ice.h
> +++ b/include/soc/qcom/ice.h
> @@ -33,7 +33,6 @@ int qcom_ice_program_key(struct qcom_ice *ice,
>  			 const u8 crypto_key[], u8 data_unit_size,
>  			 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
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 3/4] scsi: ufs: qcom: fix dev reference leaked through of_qcom_ice_get
  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
  1 sibling, 0 replies; 13+ messages in thread
From: Abel Vesa @ 2025-01-19 16:59 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers,
	linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, stable,
	Krzysztof Kozlowski

On 25-01-17 14:18:52, Tudor Ambarus wrote:
> The driver leaks the device reference taken with
> of_find_device_by_node(). Fix the leak by using devm_of_qcom_ice_get().
> 
> Fixes: 56541c7c4468 ("scsi: ufs: ufs-qcom: Switch to the new ICE API")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Reviewed-by: Abel Vesa <abel.vesa@linaro.org>

> ---
>  drivers/ufs/host/ufs-qcom.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
> index 23b9f6efa047..a455a95f65fc 100644
> --- a/drivers/ufs/host/ufs-qcom.c
> +++ b/drivers/ufs/host/ufs-qcom.c
> @@ -125,7 +125,7 @@ static int ufs_qcom_ice_init(struct ufs_qcom_host *host)
>  	int err;
>  	int i;
>  
> -	ice = of_qcom_ice_get(dev);
> +	ice = devm_of_qcom_ice_get(dev);
>  	if (ice == ERR_PTR(-EOPNOTSUPP)) {
>  		dev_warn(dev, "Disabling inline encryption support\n");
>  		ice = NULL;
> 
> -- 
> 2.48.0.rc2.279.g1de40edade-goog
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/4] mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get
  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
  0 siblings, 0 replies; 13+ messages in thread
From: Abel Vesa @ 2025-01-19 16:59 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers,
	linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, stable,
	Krzysztof Kozlowski

On 25-01-17 14:18:51, Tudor Ambarus wrote:
> The driver leaks the device reference taken with
> of_find_device_by_node(). Fix the leak by using devm_of_qcom_ice_get().
> 
> Fixes: c7eed31e235c ("mmc: sdhci-msm: Switch to the new ICE API")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>

Reviewed-by: Abel Vesa <abel.vesa@linaro.org>

> ---
>  drivers/mmc/host/sdhci-msm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
> index 4610f067faca..559ea5af27f2 100644
> --- a/drivers/mmc/host/sdhci-msm.c
> +++ b/drivers/mmc/host/sdhci-msm.c
> @@ -1824,7 +1824,7 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
>  	if (!(cqhci_readl(cq_host, CQHCI_CAP) & CQHCI_CAP_CS))
>  		return 0;
>  
> -	ice = of_qcom_ice_get(dev);
> +	ice = devm_of_qcom_ice_get(dev);
>  	if (ice == ERR_PTR(-EOPNOTSUPP)) {
>  		dev_warn(dev, "Disabling inline encryption support\n");
>  		ice = NULL;
> 
> -- 
> 2.48.0.rc2.279.g1de40edade-goog
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/4] soc: qcom: ice: fix dev reference leaked through of_qcom_ice_get
  2025-01-17 14:18 [PATCH v2 0/4] soc: qcom: ice: fix dev reference leaked through of_qcom_ice_get Tudor Ambarus
                   ` (3 preceding siblings ...)
  2025-01-17 14:18 ` [PATCH v2 4/4] soc: qcom: ice: make of_qcom_ice_get() static Tudor Ambarus
@ 2025-01-24  7:38 ` Manivannan Sadhasivam
  2025-02-14 22:38 ` Bjorn Andersson
  5 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2025-01-24  7:38 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Abel Vesa, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers,
	linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, stable,
	Krzysztof Kozlowski

On Fri, Jan 17, 2025 at 02:18:49PM +0000, Tudor Ambarus wrote:
> Hi!
> 
> Recently I've been pointed to this driver for an example on how consumers
> can get a pointer to the supplier's driver data and I noticed a leak.
> 
> Callers of of_qcom_ice_get() leak the device reference taken by
> of_find_device_by_node(). Introduce devm_of_qcom_ice_get().
> Exporting qcom_ice_put() is not done intentionally as the consumers need
> the ICE intance for the entire life of their device. Update the consumers
> to use the devm variant and make of_qcom_ice_get() static afterwards.
> 
> This set touches mmc and scsi subsystems. Since the fix is trivial for
> them, I'd suggest taking everything through the SoC tree with Acked-by
> tags if people consider this fine. Note that the mmc and scsi patches
> depend on the first patch that introduces devm_of_qcom_ice_get().
> 
> Thanks!
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> ---
> Changes in v2:
> - add kernel doc for newly introduced devm_of_qcom_ice_get().
> - update cover letter and commit message of first patch.
> - collect R-b and A-b tags.
> - Link to v1: https://lore.kernel.org/r/20250116-qcom-ice-fix-dev-leak-v1-0-84d937683790@linaro.org
> 
> ---
> Tudor Ambarus (4):
>       soc: qcom: ice: introduce devm_of_qcom_ice_get
>       mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get
>       scsi: ufs: qcom: fix dev reference leaked through of_qcom_ice_get
>       soc: qcom: ice: make of_qcom_ice_get() static
> 
>  drivers/mmc/host/sdhci-msm.c |  2 +-
>  drivers/soc/qcom/ice.c       | 51 ++++++++++++++++++++++++++++++++++++++++++--
>  drivers/ufs/host/ufs-qcom.c  |  2 +-
>  include/soc/qcom/ice.h       |  3 ++-
>  4 files changed, 53 insertions(+), 5 deletions(-)
> ---
> base-commit: b323d8e7bc03d27dec646bfdccb7d1a92411f189
> change-id: 20250110-qcom-ice-fix-dev-leak-bbff59a964fb
> 
> Best regards,
> -- 
> Tudor Ambarus <tudor.ambarus@linaro.org>
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 3/4] scsi: ufs: qcom: fix dev reference leaked through of_qcom_ice_get
  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
  1 sibling, 0 replies; 13+ messages in thread
From: Martin K. Petersen @ 2025-02-03 21:43 UTC (permalink / raw)
  To: Tudor Ambarus
  Cc: Krzysztof Kozlowski, Bjorn Andersson, Konrad Dybcio,
	Adrian Hunter, Ulf Hansson, Abel Vesa, Manivannan Sadhasivam,
	James E.J. Bottomley, Martin K. Petersen, Eric Biggers,
	linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, stable,
	Krzysztof Kozlowski


Tudor,

> The driver leaks the device reference taken with
> of_find_device_by_node(). Fix the leak by using devm_of_qcom_ice_get().

Acked-by: Martin K. Petersen <martin.petersen@oracle.com> # SCSI

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/4] soc: qcom: ice: fix dev reference leaked through of_qcom_ice_get
  2025-01-17 14:18 [PATCH v2 0/4] soc: qcom: ice: fix dev reference leaked through of_qcom_ice_get Tudor Ambarus
                   ` (4 preceding siblings ...)
  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
  5 siblings, 0 replies; 13+ messages in thread
From: Bjorn Andersson @ 2025-02-14 22:38 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Konrad Dybcio, Adrian Hunter, Ulf Hansson,
	Abel Vesa, Manivannan Sadhasivam, James E.J. Bottomley,
	Martin K. Petersen, Eric Biggers, Tudor Ambarus
  Cc: linux-arm-msm, linux-kernel, linux-mmc, linux-scsi, andre.draszik,
	peter.griffin, willmcvicker, kernel-team, stable,
	Krzysztof Kozlowski


On Fri, 17 Jan 2025 14:18:49 +0000, Tudor Ambarus wrote:
> Recently I've been pointed to this driver for an example on how consumers
> can get a pointer to the supplier's driver data and I noticed a leak.
> 
> Callers of of_qcom_ice_get() leak the device reference taken by
> of_find_device_by_node(). Introduce devm_of_qcom_ice_get().
> Exporting qcom_ice_put() is not done intentionally as the consumers need
> the ICE intance for the entire life of their device. Update the consumers
> to use the devm variant and make of_qcom_ice_get() static afterwards.
> 
> [...]

Applied, thanks!

[1/4] soc: qcom: ice: introduce devm_of_qcom_ice_get
      commit: 1c13d6060d612601a61423f2e8fbf9e48126acca
[2/4] mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get
      commit: cbef7442fba510b7eb229dcc9f39d3dde4a159a4
[3/4] scsi: ufs: qcom: fix dev reference leaked through of_qcom_ice_get
      commit: ded40f32b55f7f2f4ed9627dd3c37a1fe89ed8c6
[4/4] soc: qcom: ice: make of_qcom_ice_get() static
      commit: 1e9e40fc6fb06d80fd9d834fab5eb5475f64787a

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-02-14 22:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).