* [PATCH v2] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug
@ 2025-04-14 12:50 Chenyuan Yang
2025-04-14 12:58 ` Johan Hovold
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Chenyuan Yang @ 2025-04-14 12:50 UTC (permalink / raw)
To: vkoul, kishon, lumag, quic_kriskura, manivannan.sadhasivam,
konrad.dybcio, quic_varada, quic_kbajaj, johan+linaro
Cc: linux-arm-msm, linux-phy, linux-kernel, Chenyuan Yang,
Johan Hovold, Krzysztof Kozlowski
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@gmail.com>
Fixes: a5d6b1ac56cb ("phy: qcom-qmp-usb: fix memleak on probe deferral")
CC: Johan Hovold <johan@kernel.org>
CC: Krzysztof Kozlowski <krzk@kernel.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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug
2025-04-14 12:50 [PATCH v2] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug Chenyuan Yang
@ 2025-04-14 12:58 ` Johan Hovold
2025-04-15 10:26 ` Dmitry Baryshkov
2025-05-14 11:37 ` Vinod Koul
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2025-04-14 12:58 UTC (permalink / raw)
To: Chenyuan Yang
Cc: vkoul, kishon, lumag, quic_kriskura, manivannan.sadhasivam,
konrad.dybcio, quic_varada, quic_kbajaj, johan+linaro,
linux-arm-msm, linux-phy, linux-kernel, Krzysztof Kozlowski
On Mon, Apr 14, 2025 at 07:50:50AM -0500, Chenyuan Yang wrote:
> 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@gmail.com>
> Fixes: a5d6b1ac56cb ("phy: qcom-qmp-usb: fix memleak on probe deferral")
> CC: Johan Hovold <johan@kernel.org>
> CC: Krzysztof Kozlowski <krzk@kernel.org>
> ---
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).
Reviewed-by: Johan Hovold <johan+linaro@kernel.org>
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug
2025-04-14 12:50 [PATCH v2] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug Chenyuan Yang
2025-04-14 12:58 ` Johan Hovold
@ 2025-04-15 10:26 ` Dmitry Baryshkov
2025-05-14 11:37 ` Vinod Koul
2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Baryshkov @ 2025-04-15 10:26 UTC (permalink / raw)
To: Chenyuan Yang
Cc: vkoul, kishon, lumag, quic_kriskura, manivannan.sadhasivam,
konrad.dybcio, quic_varada, quic_kbajaj, johan+linaro,
linux-arm-msm, linux-phy, linux-kernel, Johan Hovold,
Krzysztof Kozlowski
On Mon, Apr 14, 2025 at 07:50:50AM -0500, Chenyuan Yang wrote:
> 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@gmail.com>
> Fixes: a5d6b1ac56cb ("phy: qcom-qmp-usb: fix memleak on probe deferral")
> CC: Johan Hovold <johan@kernel.org>
> CC: Krzysztof Kozlowski <krzk@kernel.org>
> ---
> drivers/phy/qualcomm/phy-qcom-qmp-usb.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug
2025-04-14 12:50 [PATCH v2] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug Chenyuan Yang
2025-04-14 12:58 ` Johan Hovold
2025-04-15 10:26 ` Dmitry Baryshkov
@ 2025-05-14 11:37 ` Vinod Koul
2 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2025-05-14 11:37 UTC (permalink / raw)
To: kishon, lumag, quic_kriskura, manivannan.sadhasivam,
konrad.dybcio, quic_varada, quic_kbajaj, johan+linaro,
Chenyuan Yang
Cc: linux-arm-msm, linux-phy, linux-kernel, Johan Hovold,
Krzysztof Kozlowski
On Mon, 14 Apr 2025 07:50:50 -0500, Chenyuan Yang wrote:
> 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,
--
~Vinod
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-05-14 11:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-14 12:50 [PATCH v2] phy: qcom-qmp-usb: Fix an NULL vs IS_ERR() bug Chenyuan Yang
2025-04-14 12:58 ` Johan Hovold
2025-04-15 10:26 ` Dmitry Baryshkov
2025-05-14 11:37 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®