* [PATCH] phy: sunplus: fix crash when the disc_vol nvmem cell is missing
@ 2026-08-04 13:58 Felix Gu
2026-08-06 10:22 ` Vinod Koul
0 siblings, 1 reply; 2+ messages in thread
From: Felix Gu @ 2026-08-04 13:58 UTC (permalink / raw)
To: Vincent Shih, Vinod Koul, Neil Armstrong
Cc: linux-usb, linux-phy, linux-kernel, Felix Gu
nvmem_cell_get() can fail with errors other than -EPROBE_DEFER, but
update_disc_vol() only handled -EPROBE_DEFER and then called
nvmem_cell_read() with the error pointer, crashing the kernel.
Fall back to the default disconnect voltage on a failed cell lookup,
and free the buffer returned by nvmem_cell_read().
Fixes: 99d9ccd97385 ("phy: usb: Add USB2.0 phy driver for Sunplus SP7021")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
drivers/phy/sunplus/phy-sunplus-usb2.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c
index 637a5fbae6d9..94146118e9c2 100644
--- a/drivers/phy/sunplus/phy-sunplus-usb2.c
+++ b/drivers/phy/sunplus/phy-sunplus-usb2.c
@@ -81,12 +81,13 @@ static int update_disc_vol(struct sp_usbphy *usbphy)
char *disc_name = "disc_vol";
ssize_t otp_l = 0;
char *otp_v;
- u32 val, set;
+ u32 val, set = OTP_DISC_LEVEL_DEFAULT;
cell = nvmem_cell_get(usbphy->dev, disc_name);
- if (IS_ERR_OR_NULL(cell)) {
+ if (IS_ERR(cell)) {
if (PTR_ERR(cell) == -EPROBE_DEFER)
return -EPROBE_DEFER;
+ goto out;
}
otp_v = nvmem_cell_read(cell, &otp_l);
@@ -96,11 +97,12 @@ static int update_disc_vol(struct sp_usbphy *usbphy)
set = *(otp_v + 1);
set = (set << (sizeof(char) * 8)) | *otp_v;
set = (set >> usbphy->disc_vol_addr_off) & J_DISC;
+ if (set == 0)
+ set = OTP_DISC_LEVEL_DEFAULT;
+ kfree(otp_v);
}
- if (IS_ERR(otp_v) || set == 0)
- set = OTP_DISC_LEVEL_DEFAULT;
-
+out:
val = readl(usbphy->phy_regs + CONFIG7);
val = (val & ~J_DISC) | set;
writel(val, usbphy->phy_regs + CONFIG7);
---
base-commit: 9a4cdc958dd79fc6c3b20b51a10debec6ca09fec
change-id: 20260804-sunplus-53a7bb1bcd72
Best regards,
--
Felix Gu <ustc.gu@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] phy: sunplus: fix crash when the disc_vol nvmem cell is missing
2026-08-04 13:58 [PATCH] phy: sunplus: fix crash when the disc_vol nvmem cell is missing Felix Gu
@ 2026-08-06 10:22 ` Vinod Koul
0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2026-08-06 10:22 UTC (permalink / raw)
To: Felix Gu; +Cc: Vincent Shih, Neil Armstrong, linux-usb, linux-phy, linux-kernel
On 04-08-26, 21:58, Felix Gu wrote:
Where is the crash report?
Patch title should document the change not the reason, please read the
documentation on how to create patches
> nvmem_cell_get() can fail with errors other than -EPROBE_DEFER, but
> update_disc_vol() only handled -EPROBE_DEFER and then called
> nvmem_cell_read() with the error pointer, crashing the kernel.
>
> Fall back to the default disconnect voltage on a failed cell lookup,
> and free the buffer returned by nvmem_cell_read().
>
> Fixes: 99d9ccd97385 ("phy: usb: Add USB2.0 phy driver for Sunplus SP7021")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
> drivers/phy/sunplus/phy-sunplus-usb2.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c
> index 637a5fbae6d9..94146118e9c2 100644
> --- a/drivers/phy/sunplus/phy-sunplus-usb2.c
> +++ b/drivers/phy/sunplus/phy-sunplus-usb2.c
> @@ -81,12 +81,13 @@ static int update_disc_vol(struct sp_usbphy *usbphy)
> char *disc_name = "disc_vol";
> ssize_t otp_l = 0;
> char *otp_v;
> - u32 val, set;
> + u32 val, set = OTP_DISC_LEVEL_DEFAULT;
>
> cell = nvmem_cell_get(usbphy->dev, disc_name);
> - if (IS_ERR_OR_NULL(cell)) {
> + if (IS_ERR(cell)) {
> if (PTR_ERR(cell) == -EPROBE_DEFER)
> return -EPROBE_DEFER;
> + goto out;
> }
>
> otp_v = nvmem_cell_read(cell, &otp_l);
> @@ -96,11 +97,12 @@ static int update_disc_vol(struct sp_usbphy *usbphy)
> set = *(otp_v + 1);
> set = (set << (sizeof(char) * 8)) | *otp_v;
> set = (set >> usbphy->disc_vol_addr_off) & J_DISC;
> + if (set == 0)
> + set = OTP_DISC_LEVEL_DEFAULT;
> + kfree(otp_v);
> }
>
> - if (IS_ERR(otp_v) || set == 0)
> - set = OTP_DISC_LEVEL_DEFAULT;
> -
> +out:
> val = readl(usbphy->phy_regs + CONFIG7);
> val = (val & ~J_DISC) | set;
> writel(val, usbphy->phy_regs + CONFIG7);
>
> ---
> base-commit: 9a4cdc958dd79fc6c3b20b51a10debec6ca09fec
> change-id: 20260804-sunplus-53a7bb1bcd72
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
--
~Vinod
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-06 10:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-04 13:58 [PATCH] phy: sunplus: fix crash when the disc_vol nvmem cell is missing Felix Gu
2026-08-06 10:22 ` 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).