[PATCH v2 1/2] phy: sunplus: fix memory leak in update_disc_vol()
From: Felix Gu
Date: Fri Aug 07 2026 - 09:42:08 EST
nvmem_cell_read() returns a kmalloc'd buffer that update_disc_vol()
never freed. Free it after extracting the disconnect-voltage value.
Fixes: 99d9ccd97385 ("phy: usb: Add USB2.0 phy driver for Sunplus SP7021")
Signed-off-by: Felix Gu <ustc.gu@xxxxxxxxx>
---
drivers/phy/sunplus/phy-sunplus-usb2.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c
index 637a5fbae6d9..842087bdfba5 100644
--- a/drivers/phy/sunplus/phy-sunplus-usb2.c
+++ b/drivers/phy/sunplus/phy-sunplus-usb2.c
@@ -81,7 +81,7 @@ 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)) {
@@ -96,11 +96,11 @@ 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;
-
val = readl(usbphy->phy_regs + CONFIG7);
val = (val & ~J_DISC) | set;
writel(val, usbphy->phy_regs + CONFIG7);
--
2.43.0