[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250414125050.2118619-1-chenyuan0y@gmail.com>
Date: Mon, 14 Apr 2025 07:50:50 -0500
From: Chenyuan Yang <chenyuan0y@...il.com>
To: vkoul@...nel.org,
kishon@...nel.org,
lumag@...nel.org,
quic_kriskura@...cinc.com,
manivannan.sadhasivam@...aro.org,
konrad.dybcio@....qualcomm.com,
quic_varada@...cinc.com,
quic_kbajaj@...cinc.com,
johan+linaro@...nel.org
Cc: linux-arm-msm@...r.kernel.org,
linux-phy@...ts.infradead.org,
linux-kernel@...r.kernel.org,
Chenyuan Yang <chenyuan0y@...il.com>,
Johan Hovold <johan@...nel.org>,
Krzysztof Kozlowski <krzk@...nel.org>
Subject: [PATCH v2] 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 <chenyuan0y@...il.com>
Fixes: a5d6b1ac56cb ("phy: qcom-qmp-usb: fix memleak on probe deferral")
CC: Johan Hovold <johan@...nel.org>
CC: Krzysztof Kozlowski <krzk@...nel.org>
---
drivers/phy/qualcomm/phy-qcom-qmp-usb.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-usb.c b/drivers/phy/qualcomm/phy-qcom-qmp-usb.c
index 787721570457..ed646a7e705b 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp-usb.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp-usb.c
@@ -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);
--
2.34.1
Powered by blists - more mailing lists