* [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
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH 2/2] phy: sunplus: free the disc_vol buffer in update_disc_vol()
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 ` Andrew Gaylard
0 siblings, 0 replies; 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
nvmem_cell_read() returns a buffer that the caller must free.
update_disc_vol() never frees it, so every PHY initialisation leaks
it: at boot, and again each time the EHCI or OHCI driver is unbound
and bound.
Free the buffer after taking the disconnect-voltage level from it.
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 | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c
index 52d80a06abdc..043feeb6e267 100644
--- a/drivers/phy/sunplus/phy-sunplus-usb2.c
+++ b/drivers/phy/sunplus/phy-sunplus-usb2.c
@@ -20,6 +20,7 @@
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
#include <linux/reset.h>
+#include <linux/slab.h>
#define HIGH_MASK_BITS GENMASK(31, 16)
#define LOW_MASK_BITS GENMASK(15, 0)
@@ -97,6 +98,7 @@ 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;
+ kfree(otp_v);
}
if (IS_ERR(otp_v) || set == 0)
--
2.53.0
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [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;
as well as URLs for NNTP newsgroup(s).