mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails
@ 2026-11-16  7:40 Andrew Gaylard
  2026-11-16  7:40 ` [PATCH 2/2] phy: sunplus: free the disc_vol buffer in update_disc_vol() Andrew Gaylard
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Gaylard @ 2026-11-16  7:40 UTC (permalink / raw)
  To: Vinod Koul, Vincent Shih
  Cc: Neil Armstrong, Manivannan Sadhasivam, linux-phy, linux-usb,
	linux-kernel

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@ffroot.co.za>
---
 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


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

end of thread, other threads:[~2026-11-16  7:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16  7:40 [PATCH 1/2] phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails Andrew Gaylard
2026-11-16  7:40 ` [PATCH 2/2] phy: sunplus: free the disc_vol buffer in update_disc_vol() Andrew Gaylard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®