public inbox for linux-phy@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH phy-next] phy: apple: apple: Check the actual ioremap return value
@ 2026-02-07 16:40 Janne Grunau
  2026-02-09 16:46 ` Sven Peter
  2026-02-10 20:48 ` Vladimir Oltean
  0 siblings, 2 replies; 4+ messages in thread
From: Janne Grunau @ 2026-02-07 16:40 UTC (permalink / raw)
  To: Sven Peter, Neal Gompa, Vinod Koul, Neil Armstrong, Philipp Zabel
  Cc: asahi, linux-phy, linux-kernel, Dan Carpenter, Janne Grunau

The address where the devm_ioremap_resource() return value is stored is
always a valid pointer. Check the actual return value instead as that
that might be an error value.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/asahi/aYXvX1bYOXtYCgfC@stanley.mountain/
Fixes: 8e98ca1e74db ("phy: apple: Add Apple Type-C PHY")
Signed-off-by: Janne Grunau <j@jannau.net>
---
 drivers/phy/apple/atc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c
index dc867f368b68748ea953e594ad998d7f965d8d1d..c144e273a555a741b49adfccbe046df83d193e03 100644
--- a/drivers/phy/apple/atc.c
+++ b/drivers/phy/apple/atc.c
@@ -2206,7 +2206,7 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph
 	for (int i = 0; i < ARRAY_SIZE(resources); i++) {
 		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resources[i].name);
 		*resources[i].addr = devm_ioremap_resource(&pdev->dev, res);
-		if (IS_ERR(resources[i].addr))
+		if (IS_ERR(*resources[i].addr))
 			return dev_err_probe(atcphy->dev, PTR_ERR(resources[i].addr),
 					     "Unable to map %s regs", resources[i].name);
 

---
base-commit: dbeea86fecef7cf2b93aded4525d74f6277376ef
change-id: 20260207-phy-apple-resource-err-ptr-5923d1130465

Best regards,
-- 
Janne Grunau <j@jannau.net>


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH phy-next] phy: apple: apple: Check the actual ioremap return value
  2026-02-07 16:40 [PATCH phy-next] phy: apple: apple: Check the actual ioremap return value Janne Grunau
@ 2026-02-09 16:46 ` Sven Peter
  2026-02-10 20:48 ` Vladimir Oltean
  1 sibling, 0 replies; 4+ messages in thread
From: Sven Peter @ 2026-02-09 16:46 UTC (permalink / raw)
  To: Janne Grunau, Vinod Koul
  Cc: asahi, Neal Gompa, Neil Armstrong, linux-phy, linux-kernel,
	Dan Carpenter, Philipp Zabel

On 07.02.26 17:40, Janne Grunau wrote:
> The address where the devm_ioremap_resource() return value is stored is
> always a valid pointer. Check the actual return value instead as that
> that might be an error value.
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/asahi/aYXvX1bYOXtYCgfC@stanley.mountain/
> Fixes: 8e98ca1e74db ("phy: apple: Add Apple Type-C PHY")
> Signed-off-by: Janne Grunau <j@jannau.net>
> ---

Reviewed-by: Sven Peter <sven@kernel.org>


Thanks,


Sven



-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH phy-next] phy: apple: apple: Check the actual ioremap return value
  2026-02-07 16:40 [PATCH phy-next] phy: apple: apple: Check the actual ioremap return value Janne Grunau
  2026-02-09 16:46 ` Sven Peter
@ 2026-02-10 20:48 ` Vladimir Oltean
  2026-02-15  7:58   ` Janne Grunau
  1 sibling, 1 reply; 4+ messages in thread
From: Vladimir Oltean @ 2026-02-10 20:48 UTC (permalink / raw)
  To: Janne Grunau
  Cc: Sven Peter, Neal Gompa, Vinod Koul, Neil Armstrong, Philipp Zabel,
	asahi, linux-phy, linux-kernel, Dan Carpenter

Hello Janne,

On Sat, Feb 07, 2026 at 05:40:34PM +0100, Janne Grunau wrote:
> The address where the devm_ioremap_resource() return value is stored is
> always a valid pointer. Check the actual return value instead as that
> that might be an error value.
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/asahi/aYXvX1bYOXtYCgfC@stanley.mountain/
> Fixes: 8e98ca1e74db ("phy: apple: Add Apple Type-C PHY")
> Signed-off-by: Janne Grunau <j@jannau.net>
> ---
>  drivers/phy/apple/atc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c
> index dc867f368b68748ea953e594ad998d7f965d8d1d..c144e273a555a741b49adfccbe046df83d193e03 100644
> --- a/drivers/phy/apple/atc.c
> +++ b/drivers/phy/apple/atc.c
> @@ -2206,7 +2206,7 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph
>  	for (int i = 0; i < ARRAY_SIZE(resources); i++) {
>  		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resources[i].name);
>  		*resources[i].addr = devm_ioremap_resource(&pdev->dev, res);
> -		if (IS_ERR(resources[i].addr))
> +		if (IS_ERR(*resources[i].addr))
>  			return dev_err_probe(atcphy->dev, PTR_ERR(resources[i].addr),
>  					     "Unable to map %s regs", resources[i].name);

This does not seem correct - every call site that tests a pointer for
IS_ERR() also decodes the error using PTR_ERR(). Whereas you are here
creating the pattern "if (IS_ERR(*a)) return PTR_ERR(a)".

Proven practice seems to tell us that insisting to save the
devm_ioremap_resource() return code directly in *resources[i].addr
is too complex here.

Would you consider creating a temporary "void __iomem *addr" local
variable, and set "*resources[i].addr = addr" only once it's validated?
This would make the code obviously correct upon review.

>  
> 
> ---
> base-commit: dbeea86fecef7cf2b93aded4525d74f6277376ef
> change-id: 20260207-phy-apple-resource-err-ptr-5923d1130465
> 
> Best regards,
> -- 
> Janne Grunau <j@jannau.net>
> 
> 

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH phy-next] phy: apple: apple: Check the actual ioremap return value
  2026-02-10 20:48 ` Vladimir Oltean
@ 2026-02-15  7:58   ` Janne Grunau
  0 siblings, 0 replies; 4+ messages in thread
From: Janne Grunau @ 2026-02-15  7:58 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Sven Peter, Neal Gompa, Vinod Koul, Neil Armstrong, Philipp Zabel,
	asahi, linux-phy, linux-kernel, Dan Carpenter

Hej Vladimir,

On Tue, Feb 10, 2026 at 10:48:22PM +0200, Vladimir Oltean wrote:
> Hello Janne,
> 
> On Sat, Feb 07, 2026 at 05:40:34PM +0100, Janne Grunau wrote:
> > The address where the devm_ioremap_resource() return value is stored is
> > always a valid pointer. Check the actual return value instead as that
> > that might be an error value.
> > 
> > Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > Closes: https://lore.kernel.org/asahi/aYXvX1bYOXtYCgfC@stanley.mountain/
> > Fixes: 8e98ca1e74db ("phy: apple: Add Apple Type-C PHY")
> > Signed-off-by: Janne Grunau <j@jannau.net>
> > ---
> >  drivers/phy/apple/atc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c
> > index dc867f368b68748ea953e594ad998d7f965d8d1d..c144e273a555a741b49adfccbe046df83d193e03 100644
> > --- a/drivers/phy/apple/atc.c
> > +++ b/drivers/phy/apple/atc.c
> > @@ -2206,7 +2206,7 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph
> >  	for (int i = 0; i < ARRAY_SIZE(resources); i++) {
> >  		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, resources[i].name);
> >  		*resources[i].addr = devm_ioremap_resource(&pdev->dev, res);
> > -		if (IS_ERR(resources[i].addr))
> > +		if (IS_ERR(*resources[i].addr))
> >  			return dev_err_probe(atcphy->dev, PTR_ERR(resources[i].addr),
> >  					     "Unable to map %s regs", resources[i].name);
> 
> This does not seem correct - every call site that tests a pointer for
> IS_ERR() also decodes the error using PTR_ERR(). Whereas you are here
> creating the pattern "if (IS_ERR(*a)) return PTR_ERR(a)".

missed this.

> Proven practice seems to tell us that insisting to save the
> devm_ioremap_resource() return code directly in *resources[i].addr
> is too complex here.
> 
> Would you consider creating a temporary "void __iomem *addr" local
> variable, and set "*resources[i].addr = addr" only once it's validated?
> This would make the code obviously correct upon review.

I agree. A local variable makes this easier to read. Thanks for spotting
this and the suggestion. I'll change that for v2.

Janne

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-15  7:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-07 16:40 [PATCH phy-next] phy: apple: apple: Check the actual ioremap return value Janne Grunau
2026-02-09 16:46 ` Sven Peter
2026-02-10 20:48 ` Vladimir Oltean
2026-02-15  7:58   ` Janne Grunau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox