Skip to content

Commit d14402a

Browse files
WhiteFox-Projectvinodkoul
authored andcommitted
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. Signed-off-by: Chenyuan Yang <[email protected]> Fixes: a5d6b1a ("phy: qcom-qmp-usb: fix memleak on probe deferral") CC: Johan Hovold <[email protected]> CC: Krzysztof Kozlowski <[email protected]> Reviewed-by: Johan Hovold <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent e00c9ae commit d14402a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/phy/qualcomm/phy-qcom-qmp-usb.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,12 +2106,16 @@ static void __iomem *qmp_usb_iomap(struct device *dev, struct device_node *np,
21062106
int index, bool exclusive)
21072107
{
21082108
struct resource res;
2109+
void __iomem *mem;
21092110

21102111
if (!exclusive) {
21112112
if (of_address_to_resource(np, index, &res))
21122113
return IOMEM_ERR_PTR(-EINVAL);
21132114

2114-
return devm_ioremap(dev, res.start, resource_size(&res));
2115+
mem = devm_ioremap(dev, res.start, resource_size(&res));
2116+
if (!mem)
2117+
return IOMEM_ERR_PTR(-ENOMEM);
2118+
return mem;
21152119
}
21162120

21172121
return devm_of_iomap(dev, np, index, NULL);

0 commit comments

Comments
 (0)