Skip to contentSkip to conversation

phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug

PATCH Applied Chenyuan Yang 4 participants 4 messages Apr 14, 2025 – May 14, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug

The qmp_usb_iomap() helper function currently returns the raw result of devm_ioremap() for non-exclusive mappings. Since devm_ioremap() may return a NULL pointer and the caller only checks error pointers with IS_ERR(), NULL could bypass the check and lead to an invalid dereference.

Fix the issue by checking if devm_ioremap() returns NULL. When it does, qmp_usb_iomap() now returns an error pointer via IOMEM_ERR_PTR(-ENOMEM), ensuring safe and consistent error handling.

Fixes a5d6b1ac56cb ("phy: qcom-qmp-usb: fix memleak on probe deferral")
CC Johan Hovold <[email protected]>
CC Krzysztof Kozlowski <[email protected]>
---
 drivers/phy/qualcomm/phy-qcom-qmp-usb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +5 -1
index 787721570457..ed646a7e705b 100644
@@ -2106,12 +2106,16 @@ static void __iomem *qmp_usb_iomap(struct device *dev, struct device_node *np,
 					int index, bool exclusive)
 {
 	struct resource res;
+	void __iomem *mem;
 
 	if (!exclusive) {
 		if (of_address_to_resource(np, index, &res))
 			return IOMEM_ERR_PTR(-EINVAL);
 
-		return devm_ioremap(dev, res.start, resource_size(&res));
+		mem = devm_ioremap(dev, res.start, resource_size(&res));
+		if (!mem)
+			return IOMEM_ERR_PTR(-ENOMEM);
+		return mem;
 	}
 
 	return devm_of_iomap(dev, np, index, NULL);
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Chenyuan Yang

The qmp_usb_iomap() helper function currently returns the raw result of devm_ioremap() for non-exclusive mappings. Since devm_ioremap() may return a NULL pointer and the caller only checks error pointers with IS_ERR(), NULL could bypass the check and lead to an invalid dereference.

Fix the issue by checking if devm_ioremap() returns NULL. When it does, qmp_usb_iomap() now returns an error pointer via IOMEM_ERR_PTR(-ENOMEM), ensuring safe and consistent error handling.

Quoted 5 lines
Fixes a5d6b1ac56cb ("phy: qcom-qmp-usb: fix memleak on probe deferral")
CC Johan Hovold <[email protected]>
CC Krzysztof Kozlowski <[email protected]>

---

Thanks for the update, looks good.

Next time, remember to include a short changelog here after the --- line (so that it does not get included in the commit message when the patch is applied).

Johan

Reviewed-by on v2 1/1
#2 lore raw
In reply to Chenyuan Yang
Quoted 9 lines · Chenyuan Yang

The qmp_usb_iomap() helper function currently returns the raw result of devm_ioremap() for non-exclusive mappings. Since devm_ioremap() may return a NULL pointer and the caller only checks error pointers with IS_ERR(), NULL could bypass the check and lead to an invalid dereference.

Fix the issue by checking if devm_ioremap() returns NULL. When it does, qmp_usb_iomap() now returns an error pointer via IOMEM_ERR_PTR(-ENOMEM), ensuring safe and consistent error handling.

Quoted 8 lines
Fixes a5d6b1ac56cb ("phy: qcom-qmp-usb: fix memleak on probe deferral")
CC Johan Hovold <[email protected]>
CC Krzysztof Kozlowski <[email protected]>
---
 drivers/phy/qualcomm/phy-qcom-qmp-usb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 2 lines
With best wishes
Dmitry
maintainer Applied
#3 lore raw
In reply to Chenyuan Yang
Quoted 10 lines · Chenyuan Yang

The qmp_usb_iomap() helper function currently returns the raw result of devm_ioremap() for non-exclusive mappings. Since devm_ioremap() may return a NULL pointer and the caller only checks error pointers with IS_ERR(), NULL could bypass the check and lead to an invalid dereference.

Fix the issue by checking if devm_ioremap() returns NULL. When it does, qmp_usb_iomap() now returns an error pointer via IOMEM_ERR_PTR(-ENOMEM), ensuring safe and consistent error handling.

[...]

Applied, thanks!

[1/1] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug

      commit: d14402a38c2d868cacb1facaf9be908ca6558e59

Best regards,

Signature · 1 line
~Vinod