linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe
@ 2021-09-22 23:35 Vladimir Zapolskiy
  2021-09-23 14:08 ` Bjorn Andersson
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Vladimir Zapolskiy @ 2021-09-22 23:35 UTC (permalink / raw)
  To: Bjorn Andersson, Andy Gross, Kishon Vijay Abraham I, Vinod Koul,
	Vivek Gautam
  Cc: linux-arm-msm, linux-phy

On success nvmem_cell_read() returns a pointer to a dynamically allocated
buffer, and therefore it shall be freed after usage.

The issue is reported by kmemleak:

  # cat /sys/kernel/debug/kmemleak
  unreferenced object 0xffff3b3803e4b280 (size 128):
    comm "kworker/u16:1", pid 107, jiffies 4294892861 (age 94.120s)
    hex dump (first 32 bytes):
      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    backtrace:
      [<000000007739afdc>] __kmalloc+0x27c/0x41c
      [<0000000071c0fbf8>] nvmem_cell_read+0x40/0xe0
      [<00000000e803ef1f>] qusb2_phy_init+0x258/0x5bc
      [<00000000fc81fcfa>] phy_init+0x70/0x110
      [<00000000e3d48a57>] dwc3_core_soft_reset+0x4c/0x234
      [<0000000027d1dbd4>] dwc3_core_init+0x68/0x990
      [<000000001965faf9>] dwc3_probe+0x4f4/0x730
      [<000000002f7617ca>] platform_probe+0x74/0xf0
      [<00000000a2576cac>] really_probe+0xc4/0x470
      [<00000000bc77f2c5>] __driver_probe_device+0x11c/0x190
      [<00000000130db71f>] driver_probe_device+0x48/0x110
      [<0000000019f36c2b>] __device_attach_driver+0xa4/0x140
      [<00000000e5812ff7>]  bus_for_each_drv+0x84/0xe0
      [<00000000f4bac574>] __device_attach+0xe4/0x1c0
      [<00000000d3beb631>] device_initial_probe+0x20/0x30
      [<000000008019b9db>] bus_probe_device+0xa4/0xb0

Fixes: ca04d9d3e1b1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips")
Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
---
Changes from v1 to v2:
* fixed a memory leak in case of reading a zero value and return,
* corrected the fixed commit, the memory leak is present before a rename.

 drivers/phy/qualcomm/phy-qcom-qusb2.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c
index 3c1d3b71c825..f1d97fbd1331 100644
--- a/drivers/phy/qualcomm/phy-qcom-qusb2.c
+++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c
@@ -561,7 +561,7 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
 {
 	struct device *dev = &qphy->phy->dev;
 	const struct qusb2_phy_cfg *cfg = qphy->cfg;
-	u8 *val;
+	u8 *val, hstx_trim;
 
 	/* efuse register is optional */
 	if (!qphy->cell)
@@ -575,7 +575,13 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
 	 * set while configuring the phy.
 	 */
 	val = nvmem_cell_read(qphy->cell, NULL);
-	if (IS_ERR(val) || !val[0]) {
+	if (IS_ERR(val)) {
+		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
+		return;
+	}
+	hstx_trim = val[0];
+	kfree(val);
+	if (!hstx_trim) {
 		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
 		return;
 	}
@@ -583,12 +589,10 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
 	/* Fused TUNE1/2 value is the higher nibble only */
 	if (cfg->update_tune1_with_efuse)
 		qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
-				 val[0] << HSTX_TRIM_SHIFT,
-				 HSTX_TRIM_MASK);
+				 hstx_trim << HSTX_TRIM_SHIFT, HSTX_TRIM_MASK);
 	else
 		qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE2],
-				 val[0] << HSTX_TRIM_SHIFT,
-				 HSTX_TRIM_MASK);
+				 hstx_trim << HSTX_TRIM_SHIFT, HSTX_TRIM_MASK);
 }
 
 static int qusb2_phy_set_mode(struct phy *phy,
-- 
2.33.0


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

* Re: [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe
  2021-09-22 23:35 [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe Vladimir Zapolskiy
@ 2021-09-23 14:08 ` Bjorn Andersson
  2021-09-23 14:18 ` Bjorn Andersson
  2021-10-01  9:42 ` Vinod Koul
  2 siblings, 0 replies; 6+ messages in thread
From: Bjorn Andersson @ 2021-09-23 14:08 UTC (permalink / raw)
  To: Vladimir Zapolskiy
  Cc: Andy Gross, Kishon Vijay Abraham I, Vinod Koul, Vivek Gautam,
	linux-arm-msm, linux-phy

On Wed 22 Sep 16:35 PDT 2021, Vladimir Zapolskiy wrote:

> On success nvmem_cell_read() returns a pointer to a dynamically allocated
> buffer, and therefore it shall be freed after usage.
> 
> The issue is reported by kmemleak:
> 
>   # cat /sys/kernel/debug/kmemleak
>   unreferenced object 0xffff3b3803e4b280 (size 128):
>     comm "kworker/u16:1", pid 107, jiffies 4294892861 (age 94.120s)
>     hex dump (first 32 bytes):
>       00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>       00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>     backtrace:
>       [<000000007739afdc>] __kmalloc+0x27c/0x41c
>       [<0000000071c0fbf8>] nvmem_cell_read+0x40/0xe0
>       [<00000000e803ef1f>] qusb2_phy_init+0x258/0x5bc
>       [<00000000fc81fcfa>] phy_init+0x70/0x110
>       [<00000000e3d48a57>] dwc3_core_soft_reset+0x4c/0x234
>       [<0000000027d1dbd4>] dwc3_core_init+0x68/0x990
>       [<000000001965faf9>] dwc3_probe+0x4f4/0x730
>       [<000000002f7617ca>] platform_probe+0x74/0xf0
>       [<00000000a2576cac>] really_probe+0xc4/0x470
>       [<00000000bc77f2c5>] __driver_probe_device+0x11c/0x190
>       [<00000000130db71f>] driver_probe_device+0x48/0x110
>       [<0000000019f36c2b>] __device_attach_driver+0xa4/0x140
>       [<00000000e5812ff7>]  bus_for_each_drv+0x84/0xe0
>       [<00000000f4bac574>] __device_attach+0xe4/0x1c0
>       [<00000000d3beb631>] device_initial_probe+0x20/0x30
>       [<000000008019b9db>] bus_probe_device+0xa4/0xb0
> 
> Fixes: ca04d9d3e1b1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips")
> Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
> ---
> Changes from v1 to v2:
> * fixed a memory leak in case of reading a zero value and return,
> * corrected the fixed commit, the memory leak is present before a rename.
> 
>  drivers/phy/qualcomm/phy-qcom-qusb2.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c
> index 3c1d3b71c825..f1d97fbd1331 100644
> --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c
> +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c
> @@ -561,7 +561,7 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>  {
>  	struct device *dev = &qphy->phy->dev;
>  	const struct qusb2_phy_cfg *cfg = qphy->cfg;
> -	u8 *val;
> +	u8 *val, hstx_trim;
>  
>  	/* efuse register is optional */
>  	if (!qphy->cell)
> @@ -575,7 +575,13 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>  	 * set while configuring the phy.
>  	 */
>  	val = nvmem_cell_read(qphy->cell, NULL);
> -	if (IS_ERR(val) || !val[0]) {
> +	if (IS_ERR(val)) {
> +		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
> +		return;
> +	}
> +	hstx_trim = val[0];
> +	kfree(val);

I don't see any additional value added by the introduction of
"hstx_trim", compared to v1.

However, it certainly makes sense if you change this to:

ret = nvmem_cell_read_u8(qphy->cell, NULL, &hstx_trim);
if (ret < 0 || !hstx_trim) {
	dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
	return;
}


In which case you don't need the kfree(), and you can drop "val"...

Regards,
Bjorn

> +	if (!hstx_trim) {
>  		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
>  		return;
>  	}
> @@ -583,12 +589,10 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>  	/* Fused TUNE1/2 value is the higher nibble only */
>  	if (cfg->update_tune1_with_efuse)
>  		qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
> -				 val[0] << HSTX_TRIM_SHIFT,
> -				 HSTX_TRIM_MASK);
> +				 hstx_trim << HSTX_TRIM_SHIFT, HSTX_TRIM_MASK);
>  	else
>  		qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE2],
> -				 val[0] << HSTX_TRIM_SHIFT,
> -				 HSTX_TRIM_MASK);
> +				 hstx_trim << HSTX_TRIM_SHIFT, HSTX_TRIM_MASK);
>  }
>  
>  static int qusb2_phy_set_mode(struct phy *phy,
> -- 
> 2.33.0
> 

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

* Re: [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe
  2021-09-22 23:35 [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe Vladimir Zapolskiy
  2021-09-23 14:08 ` Bjorn Andersson
@ 2021-09-23 14:18 ` Bjorn Andersson
  2021-10-01  9:42 ` Vinod Koul
  2 siblings, 0 replies; 6+ messages in thread
From: Bjorn Andersson @ 2021-09-23 14:18 UTC (permalink / raw)
  To: Vladimir Zapolskiy
  Cc: Andy Gross, Kishon Vijay Abraham I, Vinod Koul, Vivek Gautam,
	linux-arm-msm, linux-phy

On Wed 22 Sep 16:35 PDT 2021, Vladimir Zapolskiy wrote:

> On success nvmem_cell_read() returns a pointer to a dynamically allocated
> buffer, and therefore it shall be freed after usage.
> 
> The issue is reported by kmemleak:
> 
>   # cat /sys/kernel/debug/kmemleak
>   unreferenced object 0xffff3b3803e4b280 (size 128):
>     comm "kworker/u16:1", pid 107, jiffies 4294892861 (age 94.120s)
>     hex dump (first 32 bytes):
>       00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>       00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>     backtrace:
>       [<000000007739afdc>] __kmalloc+0x27c/0x41c
>       [<0000000071c0fbf8>] nvmem_cell_read+0x40/0xe0
>       [<00000000e803ef1f>] qusb2_phy_init+0x258/0x5bc
>       [<00000000fc81fcfa>] phy_init+0x70/0x110
>       [<00000000e3d48a57>] dwc3_core_soft_reset+0x4c/0x234
>       [<0000000027d1dbd4>] dwc3_core_init+0x68/0x990
>       [<000000001965faf9>] dwc3_probe+0x4f4/0x730
>       [<000000002f7617ca>] platform_probe+0x74/0xf0
>       [<00000000a2576cac>] really_probe+0xc4/0x470
>       [<00000000bc77f2c5>] __driver_probe_device+0x11c/0x190
>       [<00000000130db71f>] driver_probe_device+0x48/0x110
>       [<0000000019f36c2b>] __device_attach_driver+0xa4/0x140
>       [<00000000e5812ff7>]  bus_for_each_drv+0x84/0xe0
>       [<00000000f4bac574>] __device_attach+0xe4/0x1c0
>       [<00000000d3beb631>] device_initial_probe+0x20/0x30
>       [<000000008019b9db>] bus_probe_device+0xa4/0xb0
> 
> Fixes: ca04d9d3e1b1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips")
> Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
> ---
> Changes from v1 to v2:
> * fixed a memory leak in case of reading a zero value and return,
> * corrected the fixed commit, the memory leak is present before a rename.
> 

Should have read your two replies in opposite order and missed your
reason for not going to the newer API and the fact that v1 still leaks
the memory if the read value is 0.


So, this looks good and as you said, we should follow up with a cleanup
by replacing the nvmem_cell_read().

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Thanks,
Bjorn

>  drivers/phy/qualcomm/phy-qcom-qusb2.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c
> index 3c1d3b71c825..f1d97fbd1331 100644
> --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c
> +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c
> @@ -561,7 +561,7 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>  {
>  	struct device *dev = &qphy->phy->dev;
>  	const struct qusb2_phy_cfg *cfg = qphy->cfg;
> -	u8 *val;
> +	u8 *val, hstx_trim;
>  
>  	/* efuse register is optional */
>  	if (!qphy->cell)
> @@ -575,7 +575,13 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>  	 * set while configuring the phy.
>  	 */
>  	val = nvmem_cell_read(qphy->cell, NULL);
> -	if (IS_ERR(val) || !val[0]) {
> +	if (IS_ERR(val)) {
> +		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
> +		return;
> +	}
> +	hstx_trim = val[0];
> +	kfree(val);
> +	if (!hstx_trim) {
>  		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
>  		return;
>  	}
> @@ -583,12 +589,10 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>  	/* Fused TUNE1/2 value is the higher nibble only */
>  	if (cfg->update_tune1_with_efuse)
>  		qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE1],
> -				 val[0] << HSTX_TRIM_SHIFT,
> -				 HSTX_TRIM_MASK);
> +				 hstx_trim << HSTX_TRIM_SHIFT, HSTX_TRIM_MASK);
>  	else
>  		qusb2_write_mask(qphy->base, cfg->regs[QUSB2PHY_PORT_TUNE2],
> -				 val[0] << HSTX_TRIM_SHIFT,
> -				 HSTX_TRIM_MASK);
> +				 hstx_trim << HSTX_TRIM_SHIFT, HSTX_TRIM_MASK);
>  }
>  
>  static int qusb2_phy_set_mode(struct phy *phy,
> -- 
> 2.33.0
> 

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

* Re: [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe
  2021-09-22 23:35 [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe Vladimir Zapolskiy
  2021-09-23 14:08 ` Bjorn Andersson
  2021-09-23 14:18 ` Bjorn Andersson
@ 2021-10-01  9:42 ` Vinod Koul
  2021-10-01 11:04   ` Vladimir Zapolskiy
  2 siblings, 1 reply; 6+ messages in thread
From: Vinod Koul @ 2021-10-01  9:42 UTC (permalink / raw)
  To: Vladimir Zapolskiy
  Cc: Bjorn Andersson, Andy Gross, Kishon Vijay Abraham I,
	Vivek Gautam, linux-arm-msm, linux-phy

On 23-09-21, 02:35, Vladimir Zapolskiy wrote:
> On success nvmem_cell_read() returns a pointer to a dynamically allocated
> buffer, and therefore it shall be freed after usage.
> 
> The issue is reported by kmemleak:
> 
>   # cat /sys/kernel/debug/kmemleak
>   unreferenced object 0xffff3b3803e4b280 (size 128):
>     comm "kworker/u16:1", pid 107, jiffies 4294892861 (age 94.120s)
>     hex dump (first 32 bytes):
>       00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>       00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>     backtrace:
>       [<000000007739afdc>] __kmalloc+0x27c/0x41c
>       [<0000000071c0fbf8>] nvmem_cell_read+0x40/0xe0
>       [<00000000e803ef1f>] qusb2_phy_init+0x258/0x5bc
>       [<00000000fc81fcfa>] phy_init+0x70/0x110
>       [<00000000e3d48a57>] dwc3_core_soft_reset+0x4c/0x234
>       [<0000000027d1dbd4>] dwc3_core_init+0x68/0x990
>       [<000000001965faf9>] dwc3_probe+0x4f4/0x730
>       [<000000002f7617ca>] platform_probe+0x74/0xf0
>       [<00000000a2576cac>] really_probe+0xc4/0x470
>       [<00000000bc77f2c5>] __driver_probe_device+0x11c/0x190
>       [<00000000130db71f>] driver_probe_device+0x48/0x110
>       [<0000000019f36c2b>] __device_attach_driver+0xa4/0x140
>       [<00000000e5812ff7>]  bus_for_each_drv+0x84/0xe0
>       [<00000000f4bac574>] __device_attach+0xe4/0x1c0
>       [<00000000d3beb631>] device_initial_probe+0x20/0x30
>       [<000000008019b9db>] bus_probe_device+0xa4/0xb0
> 
> Fixes: ca04d9d3e1b1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips")
> Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
> ---
> Changes from v1 to v2:
> * fixed a memory leak in case of reading a zero value and return,
> * corrected the fixed commit, the memory leak is present before a rename.
> 
>  drivers/phy/qualcomm/phy-qcom-qusb2.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c
> index 3c1d3b71c825..f1d97fbd1331 100644
> --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c
> +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c
> @@ -561,7 +561,7 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>  {
>  	struct device *dev = &qphy->phy->dev;
>  	const struct qusb2_phy_cfg *cfg = qphy->cfg;
> -	u8 *val;
> +	u8 *val, hstx_trim;
>  
>  	/* efuse register is optional */
>  	if (!qphy->cell)
> @@ -575,7 +575,13 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>  	 * set while configuring the phy.
>  	 */
>  	val = nvmem_cell_read(qphy->cell, NULL);
> -	if (IS_ERR(val) || !val[0]) {
> +	if (IS_ERR(val)) {
> +		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");

not an error log..?

-- 
~Vinod

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

* Re: [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe
  2021-10-01  9:42 ` Vinod Koul
@ 2021-10-01 11:04   ` Vladimir Zapolskiy
  2021-10-05 10:37     ` Vinod Koul
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Zapolskiy @ 2021-10-01 11:04 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Bjorn Andersson, Andy Gross, Kishon Vijay Abraham I,
	Vivek Gautam, linux-arm-msm, linux-phy

On 10/1/21 12:42 PM, Vinod Koul wrote:
> On 23-09-21, 02:35, Vladimir Zapolskiy wrote:
>> On success nvmem_cell_read() returns a pointer to a dynamically allocated
>> buffer, and therefore it shall be freed after usage.
>>
>> The issue is reported by kmemleak:
>>
>>    # cat /sys/kernel/debug/kmemleak
>>    unreferenced object 0xffff3b3803e4b280 (size 128):
>>      comm "kworker/u16:1", pid 107, jiffies 4294892861 (age 94.120s)
>>      hex dump (first 32 bytes):
>>        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>>        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>>      backtrace:
>>        [<000000007739afdc>] __kmalloc+0x27c/0x41c
>>        [<0000000071c0fbf8>] nvmem_cell_read+0x40/0xe0
>>        [<00000000e803ef1f>] qusb2_phy_init+0x258/0x5bc
>>        [<00000000fc81fcfa>] phy_init+0x70/0x110
>>        [<00000000e3d48a57>] dwc3_core_soft_reset+0x4c/0x234
>>        [<0000000027d1dbd4>] dwc3_core_init+0x68/0x990
>>        [<000000001965faf9>] dwc3_probe+0x4f4/0x730
>>        [<000000002f7617ca>] platform_probe+0x74/0xf0
>>        [<00000000a2576cac>] really_probe+0xc4/0x470
>>        [<00000000bc77f2c5>] __driver_probe_device+0x11c/0x190
>>        [<00000000130db71f>] driver_probe_device+0x48/0x110
>>        [<0000000019f36c2b>] __device_attach_driver+0xa4/0x140
>>        [<00000000e5812ff7>]  bus_for_each_drv+0x84/0xe0
>>        [<00000000f4bac574>] __device_attach+0xe4/0x1c0
>>        [<00000000d3beb631>] device_initial_probe+0x20/0x30
>>        [<000000008019b9db>] bus_probe_device+0xa4/0xb0
>>
>> Fixes: ca04d9d3e1b1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips")
>> Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
>> ---
>> Changes from v1 to v2:
>> * fixed a memory leak in case of reading a zero value and return,
>> * corrected the fixed commit, the memory leak is present before a rename.
>>
>>   drivers/phy/qualcomm/phy-qcom-qusb2.c | 16 ++++++++++------
>>   1 file changed, 10 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c
>> index 3c1d3b71c825..f1d97fbd1331 100644
>> --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c
>> +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c
>> @@ -561,7 +561,7 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>>   {
>>   	struct device *dev = &qphy->phy->dev;
>>   	const struct qusb2_phy_cfg *cfg = qphy->cfg;
>> -	u8 *val;
>> +	u8 *val, hstx_trim;
>>   
>>   	/* efuse register is optional */
>>   	if (!qphy->cell)
>> @@ -575,7 +575,13 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
>>   	 * set while configuring the phy.
>>   	 */
>>   	val = nvmem_cell_read(qphy->cell, NULL);
>> -	if (IS_ERR(val) || !val[0]) {
>> +	if (IS_ERR(val)) {
>> +		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
> 
> not an error log..?
> 

It's a copy from the existing code, no changes on error but the memory leak fix.

If CONFIG_NVMEM is not set, then nvmem_cell_read() returns ERR_PTR(-EOPNOTSUPP),
still it allows to build/run the phy driver, so it seems to be a valid option,
please correct me.

--
Best wishes,
Vladimir

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

* Re: [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe
  2021-10-01 11:04   ` Vladimir Zapolskiy
@ 2021-10-05 10:37     ` Vinod Koul
  0 siblings, 0 replies; 6+ messages in thread
From: Vinod Koul @ 2021-10-05 10:37 UTC (permalink / raw)
  To: Vladimir Zapolskiy
  Cc: Bjorn Andersson, Andy Gross, Kishon Vijay Abraham I,
	Vivek Gautam, linux-arm-msm, linux-phy

On 01-10-21, 14:04, Vladimir Zapolskiy wrote:
> On 10/1/21 12:42 PM, Vinod Koul wrote:
> > On 23-09-21, 02:35, Vladimir Zapolskiy wrote:
> > > On success nvmem_cell_read() returns a pointer to a dynamically allocated
> > > buffer, and therefore it shall be freed after usage.
> > > 
> > > The issue is reported by kmemleak:
> > > 
> > >    # cat /sys/kernel/debug/kmemleak
> > >    unreferenced object 0xffff3b3803e4b280 (size 128):
> > >      comm "kworker/u16:1", pid 107, jiffies 4294892861 (age 94.120s)
> > >      hex dump (first 32 bytes):
> > >        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
> > >        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
> > >      backtrace:
> > >        [<000000007739afdc>] __kmalloc+0x27c/0x41c
> > >        [<0000000071c0fbf8>] nvmem_cell_read+0x40/0xe0
> > >        [<00000000e803ef1f>] qusb2_phy_init+0x258/0x5bc
> > >        [<00000000fc81fcfa>] phy_init+0x70/0x110
> > >        [<00000000e3d48a57>] dwc3_core_soft_reset+0x4c/0x234
> > >        [<0000000027d1dbd4>] dwc3_core_init+0x68/0x990
> > >        [<000000001965faf9>] dwc3_probe+0x4f4/0x730
> > >        [<000000002f7617ca>] platform_probe+0x74/0xf0
> > >        [<00000000a2576cac>] really_probe+0xc4/0x470
> > >        [<00000000bc77f2c5>] __driver_probe_device+0x11c/0x190
> > >        [<00000000130db71f>] driver_probe_device+0x48/0x110
> > >        [<0000000019f36c2b>] __device_attach_driver+0xa4/0x140
> > >        [<00000000e5812ff7>]  bus_for_each_drv+0x84/0xe0
> > >        [<00000000f4bac574>] __device_attach+0xe4/0x1c0
> > >        [<00000000d3beb631>] device_initial_probe+0x20/0x30
> > >        [<000000008019b9db>] bus_probe_device+0xa4/0xb0
> > > 
> > > Fixes: ca04d9d3e1b1 ("phy: qcom-qusb2: New driver for QUSB2 PHY on Qcom chips")
> > > Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
> > > ---
> > > Changes from v1 to v2:
> > > * fixed a memory leak in case of reading a zero value and return,
> > > * corrected the fixed commit, the memory leak is present before a rename.
> > > 
> > >   drivers/phy/qualcomm/phy-qcom-qusb2.c | 16 ++++++++++------
> > >   1 file changed, 10 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c
> > > index 3c1d3b71c825..f1d97fbd1331 100644
> > > --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c
> > > +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c
> > > @@ -561,7 +561,7 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
> > >   {
> > >   	struct device *dev = &qphy->phy->dev;
> > >   	const struct qusb2_phy_cfg *cfg = qphy->cfg;
> > > -	u8 *val;
> > > +	u8 *val, hstx_trim;
> > >   	/* efuse register is optional */
> > >   	if (!qphy->cell)
> > > @@ -575,7 +575,13 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy)
> > >   	 * set while configuring the phy.
> > >   	 */
> > >   	val = nvmem_cell_read(qphy->cell, NULL);
> > > -	if (IS_ERR(val) || !val[0]) {
> > > +	if (IS_ERR(val)) {
> > > +		dev_dbg(dev, "failed to read a valid hs-tx trim value\n");
> > 
> > not an error log..?
> > 
> 
> It's a copy from the existing code, no changes on error but the memory leak fix.
> 
> If CONFIG_NVMEM is not set, then nvmem_cell_read() returns ERR_PTR(-EOPNOTSUPP),
> still it allows to build/run the phy driver, so it seems to be a valid option,
> please correct me.

Yes it is not relevant to the leak fix here, so I will apply it

-- 
~Vinod

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

end of thread, other threads:[~2021-10-05 10:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 23:35 [PATCH v2] phy: qcom-qusb2: Fix a memory leak on probe Vladimir Zapolskiy
2021-09-23 14:08 ` Bjorn Andersson
2021-09-23 14:18 ` Bjorn Andersson
2021-10-01  9:42 ` Vinod Koul
2021-10-01 11:04   ` Vladimir Zapolskiy
2021-10-05 10:37     ` Vinod Koul

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