linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] phy: freescale: imx8qm-hsio: Fix a use of uninitialized mutex
@ 2025-08-03  6:15 quanyang.wang
  2025-08-05 21:14 ` Frank Li
  0 siblings, 1 reply; 2+ messages in thread
From: quanyang.wang @ 2025-08-03  6:15 UTC (permalink / raw)
  To: Vinod Koul, Kishon Vijay Abraham I, Shawn Guo, Sascha Hauer,
	Richard Zhu, Frank Li
  Cc: Quanyang Wang, linux-phy, imx, linux-arm-kernel, linux-kernel

From: Quanyang Wang <quanyang.wang@windriver.com>

Using an uninitialized mutex leads to the following warning when
CONFIG_DEBUG_MUTEXES is enabled.

 DEBUG_LOCKS_WARN_ON(lock->magic != lock)
 WARNING: CPU: 2 PID: 49 at kernel/locking/mutex.c:577 __mutex_lock+0x690/0x820
 Modules linked in:
 CPU: 2 UID: 0 PID: 49 Comm: kworker/u16:2 Not tainted 6.16.0-04405-g4b290aae788e #23 PREEMPT
 Hardware name: Freescale i.MX8QM MEK (DT)
 Workqueue: events_unbound deferred_probe_work_func
 pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
 pc : __mutex_lock+0x690/0x820
 lr : __mutex_lock+0x690/0x820
 sp : ffff8000830b3900
 x29: ffff8000830b3960 x28: ffff80008223bac0 x27: 0000000000000000
 x26: ffff000802fc4680 x25: ffff000800019a0d x24: 0000000000000000
 x23: ffff8000806f0d6c x22: 0000000000000002 x21: 0000000000000000
 x20: ffff8000830b3930 x19: ffff000802338090 x18: fffffffffffe6138
 x17: 67657220796d6d75 x16: 6420676e69737520 x15: 0000000000000038
 x14: 0000000000000000 x13: ffff8000822636f0 x12: 000000000000044a
 x11: 000000000000016e x10: ffff8000822bd940 x9 : ffff8000822636f0
 x8 : 00000000ffffefff x7 : ffff8000822bb6f0 x6 : 000000000000016e
 x5 : 000000000000016f x4 : 40000000fffff16e x3 : 0000000000000000
 x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0008003b8000
 Call trace:
  __mutex_lock+0x690/0x820 (P)
  mutex_lock_nested+0x24/0x30
  imx_hsio_power_on+0x4c/0x764
  phy_power_on+0x7c/0x12c
  imx_sata_enable+0x1ec/0x488
  imx_ahci_probe+0x1a4/0x560
  platform_probe+0x5c/0x98
  really_probe+0xac/0x298
  __driver_probe_device+0x78/0x12c
  driver_probe_device+0xd8/0x160
  __device_attach_driver+0xb8/0x138
  bus_for_each_drv+0x88/0xe8
  __device_attach+0xa0/0x190
  device_initial_probe+0x14/0x20
  bus_probe_device+0xac/0xb0
  deferred_probe_work_func+0x8c/0xc8
  process_one_work+0x1e4/0x440
  worker_thread+0x1b4/0x350
  kthread+0x138/0x214
  ret_from_fork+0x10/0x20

Fixes: 82c56b6dd24f ("phy: freescale: imx8qm-hsio: Add i.MX8QM HSIO PHY driver support")
Signed-off-by: Quanyang Wang <quanyang.wang@windriver.com>
---

Changes in v2:
* Use devm_mutex_init instead of mutex_init, as suggested by Frank

 drivers/phy/freescale/phy-fsl-imx8qm-hsio.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c b/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c
index 5dca93cd325c8..348fefcfe7a5c 100644
--- a/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c
+++ b/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c
@@ -534,6 +534,7 @@ static struct phy *imx_hsio_xlate(struct device *dev,
 static int imx_hsio_probe(struct platform_device *pdev)
 {
 	int i;
+	int ret;
 	void __iomem *off;
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
@@ -590,6 +591,10 @@ static int imx_hsio_probe(struct platform_device *pdev)
 		phy_set_drvdata(phy, lane);
 	}
 
+	ret = devm_mutex_init(dev, &priv->lock);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to initialize lock\n");
+
 	dev_set_drvdata(dev, priv);
 	dev_set_drvdata(&pdev->dev, priv);
 
-- 
2.43.0



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

* Re: [PATCH v2] phy: freescale: imx8qm-hsio: Fix a use of uninitialized mutex
  2025-08-03  6:15 [PATCH v2] phy: freescale: imx8qm-hsio: Fix a use of uninitialized mutex quanyang.wang
@ 2025-08-05 21:14 ` Frank Li
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Li @ 2025-08-05 21:14 UTC (permalink / raw)
  To: quanyang.wang
  Cc: Vinod Koul, Kishon Vijay Abraham I, Shawn Guo, Sascha Hauer,
	Richard Zhu, linux-phy, imx, linux-arm-kernel, linux-kernel

On Sun, Aug 03, 2025 at 02:15:29PM +0800, quanyang.wang@windriver.com wrote:
> From: Quanyang Wang <quanyang.wang@windriver.com>
>
> Using an uninitialized mutex leads to the following warning when
> CONFIG_DEBUG_MUTEXES is enabled.
>
>  DEBUG_LOCKS_WARN_ON(lock->magic != lock)
>  WARNING: CPU: 2 PID: 49 at kernel/locking/mutex.c:577 __mutex_lock+0x690/0x820
>  Modules linked in:
>  CPU: 2 UID: 0 PID: 49 Comm: kworker/u16:2 Not tainted 6.16.0-04405-g4b290aae788e #23 PREEMPT
>  Hardware name: Freescale i.MX8QM MEK (DT)
>  Workqueue: events_unbound deferred_probe_work_func
>  pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
>  pc : __mutex_lock+0x690/0x820
>  lr : __mutex_lock+0x690/0x820
>  sp : ffff8000830b3900
>  x29: ffff8000830b3960 x28: ffff80008223bac0 x27: 0000000000000000
>  x26: ffff000802fc4680 x25: ffff000800019a0d x24: 0000000000000000
>  x23: ffff8000806f0d6c x22: 0000000000000002 x21: 0000000000000000
>  x20: ffff8000830b3930 x19: ffff000802338090 x18: fffffffffffe6138
>  x17: 67657220796d6d75 x16: 6420676e69737520 x15: 0000000000000038
>  x14: 0000000000000000 x13: ffff8000822636f0 x12: 000000000000044a
>  x11: 000000000000016e x10: ffff8000822bd940 x9 : ffff8000822636f0
>  x8 : 00000000ffffefff x7 : ffff8000822bb6f0 x6 : 000000000000016e
>  x5 : 000000000000016f x4 : 40000000fffff16e x3 : 0000000000000000
>  x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0008003b8000
>  Call trace:
>   __mutex_lock+0x690/0x820 (P)
>   mutex_lock_nested+0x24/0x30
>   imx_hsio_power_on+0x4c/0x764
>   phy_power_on+0x7c/0x12c
>   imx_sata_enable+0x1ec/0x488
>   imx_ahci_probe+0x1a4/0x560
>   platform_probe+0x5c/0x98
>   really_probe+0xac/0x298
>   __driver_probe_device+0x78/0x12c
>   driver_probe_device+0xd8/0x160
>   __device_attach_driver+0xb8/0x138
>   bus_for_each_drv+0x88/0xe8
>   __device_attach+0xa0/0x190
>   device_initial_probe+0x14/0x20
>   bus_probe_device+0xac/0xb0
>   deferred_probe_work_func+0x8c/0xc8
>   process_one_work+0x1e4/0x440
>   worker_thread+0x1b4/0x350
>   kthread+0x138/0x214
>   ret_from_fork+0x10/0x20
>
> Fixes: 82c56b6dd24f ("phy: freescale: imx8qm-hsio: Add i.MX8QM HSIO PHY driver support")
> Signed-off-by: Quanyang Wang <quanyang.wang@windriver.com>

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---
>
> Changes in v2:
> * Use devm_mutex_init instead of mutex_init, as suggested by Frank
>
>  drivers/phy/freescale/phy-fsl-imx8qm-hsio.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c b/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c
> index 5dca93cd325c8..348fefcfe7a5c 100644
> --- a/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c
> +++ b/drivers/phy/freescale/phy-fsl-imx8qm-hsio.c
> @@ -534,6 +534,7 @@ static struct phy *imx_hsio_xlate(struct device *dev,
>  static int imx_hsio_probe(struct platform_device *pdev)
>  {
>  	int i;
> +	int ret;
>  	void __iomem *off;
>  	struct device *dev = &pdev->dev;
>  	struct device_node *np = dev->of_node;
> @@ -590,6 +591,10 @@ static int imx_hsio_probe(struct platform_device *pdev)
>  		phy_set_drvdata(phy, lane);
>  	}
>
> +	ret = devm_mutex_init(dev, &priv->lock);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "Failed to initialize lock\n");
> +
>  	dev_set_drvdata(dev, priv);
>  	dev_set_drvdata(&pdev->dev, priv);
>
> --
> 2.43.0
>


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

end of thread, other threads:[~2025-08-05 21:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-03  6:15 [PATCH v2] phy: freescale: imx8qm-hsio: Fix a use of uninitialized mutex quanyang.wang
2025-08-05 21:14 ` Frank Li

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