phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails
Subsystems (3)
PATCH 1/2 phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails
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.
--- drivers/phy/sunplus/phy-sunplus-usb2.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/phy/sunplus/phy-sunplus-usb2.c +5 -4
@@ -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
Signature · 1 line
2.53.0
PATCH 2/2 phy: sunplus: free the disc_vol buffer in update_disc_vol()
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.
--- drivers/phy/sunplus/phy-sunplus-usb2.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/phy/sunplus/phy-sunplus-usb2.c +2 -0
@@ -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 )
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 2/2] phy: sunplus: free the disc_vol buffer in update_disc_vol()
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 5 lines
update_disc_vol()returns early only whennvmem_cell_get()gives -EPROBE_DEFER. On any other error, such as-ENOENTfor a device tree without adisc_volcell, it passes the error pointer tonvmem_cell_read()andnvmem_cell_put(), which dereference it.
Quoted 8 lines
Use the default disconnect-voltage level on these errors, as the function already does when the read fails.
nvmem_cell_get()never returns NULL, soIS_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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1