[PATCH 1/2] phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails
From: Andrew Gaylard
Date: Mon Nov 16 2026 - 02:40:51 EST
update_disc_vol() returns early only when nvmem_cell_get() gives
-EPROBE_DEFER. On any other error, such as -ENOENT for a device tree
without a disc_vol cell, it passes the error pointer to
nvmem_cell_read() and nvmem_cell_put(), which dereference it.
Use the default disconnect-voltage level on these errors, as the function
already does when the read fails. nvmem_cell_get() never returns NULL,
so IS_ERR() is enough.
Tested on a Tibbo LTPP3G2 board.
Fixes: 99d9ccd97385 ("phy: usb: Add USB2.0 phy driver for Sunplus SP7021")
Signed-off-by: Andrew Gaylard <ag@xxxxxxxxxxxx>
---
drivers/phy/sunplus/phy-sunplus-usb2.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c
index 0ad4c7160d17..52d80a06abdc 100644
--- a/drivers/phy/sunplus/phy-sunplus-usb2.c
+++ b/drivers/phy/sunplus/phy-sunplus-usb2.c
@@ -84,14 +84,15 @@ static int update_disc_vol(struct sp_usbphy *usbphy)
u32 val, set;
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;
+ otp_v = ERR_CAST(cell);
+ } else {
+ otp_v = nvmem_cell_read(cell, &otp_l);
+ nvmem_cell_put(cell);
}
- otp_v = nvmem_cell_read(cell, &otp_l);
- nvmem_cell_put(cell);
-
if (!IS_ERR(otp_v)) {
set = *(otp_v + 1);
set = (set << (sizeof(char) * 8)) | *otp_v;
base-commit: 6bdfbe223ed4735073c299a6645ebd3faac3f51f
--
2.53.0