usb: ulpi: fix memory leak on ulpi_register() error paths
PATCH 1/1 usb: ulpi: fix memory leak on ulpi_register() error paths
Commit 01af542392b5 ("usb: ulpi: fix double free in ulpi_register_interface() error path") removed kfree(ulpi) from ulpi_register_interface() to fix a double-free when device_register() fails.
But when ulpi_of_register() or ulpi_read_id() fail before device_register() is called, the ulpi allocation is leaked.
Add kfree(ulpi) on both error paths to properly clean up the allocation.
--- drivers/usb/common/ulpi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/common/ulpi.c +4 -1
@@ -286,12 +286,15 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)ACPI_COMPANION_SET (&ulpi->dev,ACPI_COMPANION (dev)); ret =ulpi_of_register (ulpi); -if (ret) +if (ret) { +kfree (ulpi);return ret; + } ret =ulpi_read_id (ulpi);if (ret) {of_node_put (ulpi->dev.of_node); +kfree (ulpi);return ret; }
---
base-commit: 816f193dd0d95246f208590924dd962b192def78
change-id: 20260407-ulpi-25d4859c0954
Best regards,
Signature · 1 line
Felix Gu <[email protected]>
Quoted 5 lines · Felix Gu
Commit
01af542392b5("usb: ulpi: fix double free inulpi_register_interface()error path") removed kfree(ulpi) fromulpi_register_interface()to fix a double-free whendevice_register()fails.
Quoted 7 lines
But when
ulpi_of_register()orulpi_read_id()fail beforedevice_register()is called, the ulpi allocation is leaked.Add kfree(ulpi) on both error paths to properly clean up the allocation.
Fixes 01af542392b5 ("usb: ulpi: fix double free in ulpi_register_interface() error path")Signed-off-by Felix Gu <[email protected]>
Quoted 25 lines
--- drivers/usb/common/ulpi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/usb/common/ulpi.c +4
-1@@ -286,12 +286,15 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)ACPI_COMPANION_SET (&ulpi->dev,ACPI_COMPANION (dev)); ret =ulpi_of_register (ulpi); -if (ret) +if (ret) { +kfree (ulpi);return ret; + } ret =ulpi_read_id (ulpi);if (ret) {of_node_put (ulpi->dev.of_node); +kfree (ulpi);return ret; }
Signature · 1 line
heikki