drm/bridge: cdns-mhdp8546: Power on/off the PHY in probe/remove
Subsystems (3)
PATCH 1/1 drm/bridge: cdns-mhdp8546: Power on/off the PHY in probe/remove
The driver currently calls phy_init()/phy_exit() but never phy_power_on()/phy_power_off().
Follow the PHY API guide's recommendation to call phy_power_on and phy_power_off along with phy_init and phy_exit respectively to be compatible with different PHYs.
--- drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +10 -1
@@ -2369,6 +2369,12 @@ static int cdns_mhdp_probe(struct platform_device *pdev) goto plat_fini; } + ret =phy_power_on (mhdp->phy); +if (ret <0 ) { +dev_err (mhdp->dev,"Failed to power on PHY: %d\n" , ret); + goto phy_exit; + } +/* Initialize the work for modeset in case of link train failure */ INIT_WORK (&mhdp->modeset_retry_work, cdns_mhdp_modeset_retry_fn);INIT_WORK (&mhdp->hpd_work, cdns_mhdp_hpd_work);
@@ -2378,7 +2384,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev) ret =cdns_mhdp_load_firmware (mhdp);if (ret) - goto phy_exit; + goto power_off;if (mhdp->hdcp_supported)cdns_mhdp_hdcp_init (mhdp);
@@ -2387,6 +2393,8 @@ static int cdns_mhdp_probe(struct platform_device *pdev)return 0 ; +power_off: +phy_power_off (mhdp->phy); phy_exit:phy_exit (mhdp->phy); plat_fini:
@@ -2424,6 +2432,7 @@ static void cdns_mhdp_remove(struct platform_device *pdev) ERR_PTR(ret)); } +phy_power_off (mhdp->phy);phy_exit (mhdp->phy);if (mhdp->info && mhdp->info->ops && mhdp->info->ops->exit)
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] drm/bridge: cdns-mhdp8546…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] drm/bridge: cdns-mhdp8546: use-after-free in cdns_mhdp_fw_cb() [1]
--
commit 23a21b2ed969a0e335bad1cc0a8b7a4ecba91485
Author: Abhash Kumar Jha <[email protected]>
drm/bridge: cdns-mhdp8546: Power on/off the PHY in probe/remove
This commit adds phy_power_on() and phy_power_off() calls alongside phy_init() and phy_exit() in cdns_mhdp_probe() and cdns_mhdp_remove().
Quoted 4 lines
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +0
-0
[ ... ]
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c static void cdns_mhdp_remove(struct platform_device *pdev) · line 2438
Quoted 8 lines
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +1
-0@@ -2424,6 +2432,7 @@ static void cdns_mhdp_remove(struct platform_device *pdev) ERR_PTR(ret)); } +phy_power_off (mhdp->phy);phy_exit (mhdp->phy);if (mhdp->info && mhdp->info->ops && mhdp->info->ops->exit)
[Severity: Critical]
This problem wasn't introduced by this patch, but can cdns_mhdp_fw_cb() trigger a use-after-free on mhdp [1] if firmware loading takes longer than the 100ms timeout in cdns_mhdp_remove()?
cdns_mhdp_load_firmware() starts an asynchronous request with request_firmware_nowait(), passing the devres-managed mhdp as the callback context. If wait_event_timeout() in cdns_mhdp_remove() expires before the firmware finishes loading, cdns_mhdp_remove() logs an error and returns without cancelling or waiting for the request:
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c:cdns_mhdp_remove() {
...
ret = wait_event_timeout(mhdp->fw_load_wq,
mhdp->hw_state == MHDP_HW_READY,
timeout);
spin_lock(&mhdp->start_lock);
mhdp->hw_state = MHDP_HW_STOPPED;
spin_unlock(&mhdp->start_lock);
if (ret == 0) {
dev_err(mhdp->dev, "%s: Timeout waiting for fw loading\n",
__func__);
} else {
...
}After cdns_mhdp_remove() returns, devres cleanup frees mhdp, and when the pending request completes later, cdns_mhdp_fw_cb() dereferences the freed mhdp pointer.
[1] https://sashiko.dev/#/bug/linux-745c94fb-512f-4afa-95f5-092458e19f3a
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Hi,
Quoted 48 lines · Abhash Kumar Jha
The driver currently calls phy_init()/phy_exit() but never phy_power_on()/phy_power_off().
Follow the PHY API guide's recommendation to call
phy_power_onandphy_power_offalong withphy_initandphy_exitrespectively to be compatible with different PHYs.Signed-off-by Abhash Kumar Jha <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +9
-1@@ -2369,6 +2369,12 @@ static int cdns_mhdp_probe(struct platform_device *pdev) goto plat_fini; } + ret =phy_power_on (mhdp->phy); +if (ret <0 ) { +dev_err (mhdp->dev,"Failed to power on PHY: %d\n" , ret); + goto phy_exit; + } +/* Initialize the work for modeset in case of link train failure */ INIT_WORK (&mhdp->modeset_retry_work, cdns_mhdp_modeset_retry_fn);INIT_WORK (&mhdp->hpd_work, cdns_mhdp_hpd_work);@@ -2378,7 +2384,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev) ret =cdns_mhdp_load_firmware (mhdp);if (ret) - goto phy_exit; + goto power_off;if (mhdp->hdcp_supported)cdns_mhdp_hdcp_init (mhdp);@@ -2387,6 +2393,8 @@ static int cdns_mhdp_probe(struct platform_device *pdev)return 0 ; +power_off: +phy_power_off (mhdp->phy); phy_exit:phy_exit (mhdp->phy); plat_fini:
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c static void cdns_mhdp_remove(struct platform_device *pdev) · line 2438
Quoted 7 lines
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +1
-0@@ -2424,6 +2432,7 @@ static void cdns_mhdp_remove(struct platform_device *pdev) ERR_PTR(ret)); } +phy_power_off (mhdp->phy);phy_exit (mhdp->phy);if (mhdp->info && mhdp->info->ops && mhdp->info->ops->exit)
I think this one is fine, so:
However, I fear there's something wrong with the torrent driver itself. I didn't study it carefully, but looks like it supports bootloader enabled PHY, and it then sets 'already_configured' field. When that's set, all these calls, and dp_configuration() are ignored. And that field is only cleared on system suspend hook. So it looks quite broken, if the PHY is enabled when the torrent driver probes, the DP driver can't configure it at all. Blanking the display or even unloading/loading the DP driver does not affect it.
Could you have a look at that too?
Tomi
Quoted 63 lines · Tomi Valkeinen
Hi,
Quoted 48 lines · Abhash Kumar Jha
The driver currently calls phy_init()/phy_exit() but never phy_power_on()/phy_power_off().
Follow the PHY API guide's recommendation to call
phy_power_onandphy_power_offalong withphy_initandphy_exitrespectively to be compatible with different PHYs.Signed-off-by Abhash Kumar Jha <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +9
-1@@ -2369,6 +2369,12 @@ static int cdns_mhdp_probe(struct platform_device *pdev) goto plat_fini; } + ret =phy_power_on (mhdp->phy); +if (ret <0 ) { +dev_err (mhdp->dev,"Failed to power on PHY: %d\n" , ret); + goto phy_exit; + } +/* Initialize the work for modeset in case of link train failure */ INIT_WORK (&mhdp->modeset_retry_work, cdns_mhdp_modeset_retry_fn);INIT_WORK (&mhdp->hpd_work, cdns_mhdp_hpd_work);@@ -2378,7 +2384,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev) ret =cdns_mhdp_load_firmware (mhdp);if (ret) - goto phy_exit; + goto power_off;if (mhdp->hdcp_supported)cdns_mhdp_hdcp_init (mhdp);@@ -2387,6 +2393,8 @@ static int cdns_mhdp_probe(struct platform_device *pdev)return 0 ; +power_off: +phy_power_off (mhdp->phy); phy_exit:phy_exit (mhdp->phy); plat_fini:drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c static void cdns_mhdp_remove(struct platform_device *pdev) · line 2438
Quoted 7 lines
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +1
-0@@ -2424,6 +2432,7 @@ static void cdns_mhdp_remove(struct platform_device *pdev) ERR_PTR(ret)); } +phy_power_off (mhdp->phy);phy_exit (mhdp->phy);if (mhdp->info && mhdp->info->ops && mhdp->info->ops->exit)I think this one is fine, so:
Reviewed-by Tomi Valkeinen <[email protected]>
Quoted 8 lines
However, I fear there's something wrong with the torrent driver itself. I didn't study it carefully, but looks like it supports bootloader enabled PHY, and it then sets '
already_configured' field. When that's set, all these calls, anddp_configuration()are ignored. And that field is only cleared on system suspend hook. So it looks quite broken, if the PHY is enabled when the torrent driver probes, the DP driver can't configure it at all. Blanking the display or even unloading/loading the DP driver does not affect it.
Hello Abhash,
I am currently rewriting the torrent driver in order to fix various issues. But I am not sure to fully understand what you mean by
Quoted 1 line
if the PHY is enabled when the torrent driver probes
This is not possible. The DP PHY is only available at the end of the probe of the torrent PHY. So maybe I am missing something, could you clarify by what you mean by that. But yes this flag 'already_configured' is quite dangerous since it assume that all the registers are properly configured by the bootloader.
Signature · 3 lines
Benjamin Robin, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Hi,
Quoted 73 lines · Benjamin Robin
Quoted 63 lines · Tomi Valkeinen
Hi,
Quoted 48 lines · Abhash Kumar Jha
The driver currently calls phy_init()/phy_exit() but never phy_power_on()/phy_power_off().
Follow the PHY API guide's recommendation to call
phy_power_onandphy_power_offalong withphy_initandphy_exitrespectively to be compatible with different PHYs.Signed-off-by Abhash Kumar Jha <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +9
-1@@ -2369,6 +2369,12 @@ static int cdns_mhdp_probe(struct platform_device *pdev) goto plat_fini; } + ret =phy_power_on (mhdp->phy); +if (ret <0 ) { +dev_err (mhdp->dev,"Failed to power on PHY: %d\n" , ret); + goto phy_exit; + } +/* Initialize the work for modeset in case of link train failure */ INIT_WORK (&mhdp->modeset_retry_work, cdns_mhdp_modeset_retry_fn);INIT_WORK (&mhdp->hpd_work, cdns_mhdp_hpd_work);@@ -2378,7 +2384,7 @@ static int cdns_mhdp_probe(struct platform_device *pdev) ret =cdns_mhdp_load_firmware (mhdp);if (ret) - goto phy_exit; + goto power_off;if (mhdp->hdcp_supported)cdns_mhdp_hdcp_init (mhdp);@@ -2387,6 +2393,8 @@ static int cdns_mhdp_probe(struct platform_device *pdev)return 0 ; +power_off: +phy_power_off (mhdp->phy); phy_exit:phy_exit (mhdp->phy); plat_fini:drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c static void cdns_mhdp_remove(struct platform_device *pdev) · line 2438
Quoted 7 lines
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +1
-0@@ -2424,6 +2432,7 @@ static void cdns_mhdp_remove(struct platform_device *pdev) ERR_PTR(ret)); } +phy_power_off (mhdp->phy);phy_exit (mhdp->phy);if (mhdp->info && mhdp->info->ops && mhdp->info->ops->exit)I think this one is fine, so:
Reviewed-by Tomi Valkeinen <[email protected]>Quoted 8 lines
However, I fear there's something wrong with the torrent driver itself. I didn't study it carefully, but looks like it supports bootloader enabled PHY, and it then sets '
already_configured' field. When that's set, all these calls, anddp_configuration()are ignored. And that field is only cleared on system suspend hook. So it looks quite broken, if the PHY is enabled when the torrent driver probes, the DP driver can't configure it at all. Blanking the display or even unloading/loading the DP driver does not affect it.
Quoted 1 line
Hello Abhash,
It wasn't Abhash.
Quoted 10 lines
I am currently rewriting the torrent driver in order to fix various issues. But I am not sure to fully understand what you mean by
Quoted 1 line
if the PHY is enabled when the torrent driver probes
This is not possible. The DP PHY is only available at the end of the probe of the torrent PHY. So maybe I am missing something, could you clarify by what you mean by that. But yes this flag '
already_configured' is quite dangerous since it assume that all the registers are properly configured by the bootloader.
I meant that if the DP PHY hardware is enabled (so was enabled by the bootloader) when the torrent driver probes, 'already_configured' will be set by the driver, and then when the MHDP driver later probes, MHDP driver won't be able to configure the PHY at all.
But all I did was a quick read, feel free to correct me =).
Tomi
Quoted 9 lines · Tomi Valkeinen
Quoted 9 lines
Quoted 8 lines
However, I fear there's something wrong with the torrent driver itself. I didn't study it carefully, but looks like it supports bootloader enabled PHY, and it then sets '
already_configured' field. When that's set, all these calls, anddp_configuration()are ignored. And that field is only cleared on system suspend hook. So it looks quite broken, if the PHY is enabled when the torrent driver probes, the DP driver can't configure it at all. Blanking the display or even unloading/loading the DP driver does not affect it.
Quoted 3 lines
Quoted 1 line
Hello Abhash,
It wasn't Abhash.
Oups, sorry. Hello Tomi.
Quoted 11 lines
Quoted 10 lines
I am currently rewriting the torrent driver in order to fix various issues. But I am not sure to fully understand what you mean by
Quoted 1 line
if the PHY is enabled when the torrent driver probes
This is not possible. The DP PHY is only available at the end of the probe of the torrent PHY. So maybe I am missing something, could you clarify by what you mean by that. But yes this flag '
already_configured' is quite dangerous since it assume that all the registers are properly configured by the bootloader.
Quoted 6 lines
I meant that if the DP PHY hardware is enabled (so was enabled by the bootloader) when the torrent driver probes, '
already_configured' will be set by the driver, and then when the MHDP driver later probes, MHDP driver won't be able to configure the PHY at all.But all I did was a quick read, feel free to correct me =).
No, you're right. I'm not sure why, but I was convinced otherwise. I’ll add this to the list of points to be corrected.
Signature · 3 lines
Benjamin Robin, Bootlin Embedded Linux and Kernel engineering https://bootlin.com