Skip to contentSkip to conversation

ASoC: SOF: imx: Fix devm_ioremap_resource check

PATCH Superseded Daniel Baluta 3 participants 3 messages Sep 1, 2025 – Sep 2, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Daniel Baluta

author maintainer
#0 lore raw

PATCH 1/1 ASoC: SOF: imx: Fix devm_ioremap_resource check

devm_ioremap_resource does not return NULL on error but an error pointer so we need to use IS_ERR to check the return code.

Fixes bc163baef570 ("ASoC: Use of_reserved_mem_region_to_resource() for "memory-region"")
---
 sound/soc/sof/imx/imx-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sof/imx/imx-common.c +1 -1
index 40debc541bf9..b3248c65215d 100644
@@ -316,7 +316,7 @@ static int imx_parse_ioremap_memory(struct snd_sof_dev *sdev)
 		}
 
 		sdev->bar[blk_type] = devm_ioremap_resource(sdev->dev, res);
-		if (!sdev->bar[blk_type])
+		if (IS_ERR(sdev->bar[blk_type]))
 			return dev_err_probe(sdev->dev,
 					     -ENOMEM,
 					     "failed to ioremap %s region\n",
Signature · 1 line
2.45.2
maintainer
#1 lore raw

sound/soc/sof/imx/imx-common.c static int imx_parse_ioremap_memory(struct snd_sof_dev *sdev) · line 322

Quoted 10 lines · Daniel Baluta

devm_ioremap_resource does not return NULL on error but an error pointer so we need to use IS_ERR to check the return code.

sound/soc/sof/imx/imx-common.c +1 -1
 		sdev->bar[blk_type] = devm_ioremap_resource(sdev->dev, res);
-		if (!sdev->bar[blk_type])
+		if (IS_ERR(sdev->bar[blk_type]))
 			return dev_err_probe(sdev->dev,
 					     -ENOMEM,
 					     "failed to ioremap %s region\n",

If it's returning an error code we should feed that into dev_err_probe() rather than hard coding to -ENOMEM.

#2 lore raw
In reply to Daniel Baluta
Quoted 15 lines · Daniel Baluta

devm_ioremap_resource does not return NULL on error but an error pointer so we need to use IS_ERR to check the return code.

Fixes bc163baef570 ("ASoC: Use of_reserved_mem_region_to_resource() for "memory-region"")
---
 sound/soc/sof/imx/imx-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sof/imx/imx-common.c +0 -0
index 40debc541bf9..b3248c65215d 100644

sound/soc/sof/imx/imx-common.c static int imx_parse_ioremap_memory(struct snd_sof_dev *sdev) · line 321

Quoted 7 lines
sound/soc/sof/imx/imx-common.c +1 -1
@@ -316,7 +316,7 @@ static int imx_parse_ioremap_memory(struct snd_sof_dev *sdev)
 		}
 
 		sdev->bar[blk_type] = devm_ioremap_resource(sdev->dev, res);
-		if (!sdev->bar[blk_type])
+		if (IS_ERR(sdev->bar[blk_type]))
 			return dev_err_probe(sdev->dev,
 					     -ENOMEM,

It's annoying that I didn't catch this bug. It's because the error pointer was stored in an array instead of a a "simple" variable. Smatch does actually have a lower quality warning for this but I wasn't reviewing them since that check had too many false positives.

I've done a little hack around, so this bug will be caught in the future and it found a few other similar bugs which I've fixed as well.

regards,
dan carpenter