Skip to contentSkip to conversation

iommu: omap: Simplify few things

PATCH Applied Krzysztof Kozlowski 3 participants 7 messages Jun 24, 2025 – Jun 27, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover iommu: omap: Simplify few things

Changes in v3:
- Rebase
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Combine patches #1 and #2, add dev_err_probe() and drop the comment
(resolving Robin's comment)
- New patch: iommu: mtk_iommu_v1: Simplify by dropping local 'mtk_mapping' variable
- Rb tag
- Link to resend of v1: https://lore.kernel.org/r/[email protected]
- Link to v1: https://lore.kernel.org/r/[email protected]

Few code simplifications without functional impact. Not tested on hardware.

Best regards,
Krzysztof

---
Krzysztof Kozlowski (3):
iommu: omap: Drop redundant check if ti,syscon-mmuconfig exists
iommu: omap: Use syscon_regmap_lookup_by_phandle_args
iommu: mtk_iommu_v1: Simplify by dropping local 'mtk_mapping' variable

 drivers/iommu/mtk_iommu_v1.c |  4 +---
 drivers/iommu/omap-iommu.c   | 24 +++++-------------------
 2 files changed, 6 insertions(+), 22 deletions(-)

---
base-commit: 2ae2aaafb21454f4781c30734959cf223ab486ef
change-id: 20250111-syscon-phandle-args-iommu-2ea162b223a4

Best regards,

Signature · 1 line
Krzysztof Kozlowski <[email protected]>
#1 lore raw

PATCH v3 1/3 iommu: omap: Drop redundant check if ti,syscon-mmuconfig exists

The syscon_regmap_lookup_by_phandle() will fail if property does not exist, so doing of_property_read_bool() earlier is redundant. Drop that check and move error message to syscon_regmap_lookup_by_phandle() error case while converting it to dev_err_probe().

---
 drivers/iommu/omap-iommu.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/iommu/omap-iommu.c +3 -11
index 3c62337f43c67720a15b67e8b610da7886f6f39c..4448c0a512137c79195112eea25d762266c77bc3 100644
@@ -1123,23 +1123,15 @@ static int omap_iommu_dra7_get_dsp_system_cfg(struct platform_device *pdev,
 					      struct omap_iommu *obj)
 {
 	struct device_node *np = pdev->dev.of_node;
-	int ret;
 
 	if (!of_device_is_compatible(np, "ti,dra7-dsp-iommu"))
 		return 0;
 
-	if (!of_property_read_bool(np, "ti,syscon-mmuconfig")) {
-		dev_err(&pdev->dev, "ti,syscon-mmuconfig property is missing\n");
-		return -EINVAL;
-	}
-
 	obj->syscfg =
 		syscon_regmap_lookup_by_phandle(np, "ti,syscon-mmuconfig");
-	if (IS_ERR(obj->syscfg)) {
-		/* can fail with -EPROBE_DEFER */
-		ret = PTR_ERR(obj->syscfg);
-		return ret;
-	}
+	if (IS_ERR(obj->syscfg))
+		return dev_err_probe(&pdev->dev, PTR_ERR(obj->syscfg),
+				     "ti,syscon-mmuconfig property is missing\n");
 
 	if (of_property_read_u32_index(np, "ti,syscon-mmuconfig", 1,
 				       &obj->id)) {
Signature · 1 line
2.48.1
reviewer Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] iommu: omap: Drop redundant check if ti,syscon-mmuconfig exists

Quoted 4 lines · Krzysztof Kozlowski

The syscon_regmap_lookup_by_phandle() will fail if property does not exist, so doing of_property_read_bool() earlier is redundant. Drop that check and move error message to syscon_regmap_lookup_by_phandle() error case while converting it to dev_err_probe().

Sure, may as well.

Quoted 37 lines
---
  drivers/iommu/omap-iommu.c | 14 +++-----------
  1 file changed, 3 insertions(+), 11 deletions(-)
drivers/iommu/omap-iommu.c +3 -11
index 3c62337f43c67720a15b67e8b610da7886f6f39c..4448c0a512137c79195112eea25d762266c77bc3 100644
@@ -1123,23 +1123,15 @@ static int omap_iommu_dra7_get_dsp_system_cfg(struct platform_device *pdev,
  					      struct omap_iommu *obj)
  {
  	struct device_node *np = pdev->dev.of_node;
-	int ret;
 
  	if (!of_device_is_compatible(np, "ti,dra7-dsp-iommu"))
  		return 0;
 
-	if (!of_property_read_bool(np, "ti,syscon-mmuconfig")) {
-		dev_err(&pdev->dev, "ti,syscon-mmuconfig property is missing\n");
-		return -EINVAL;
-	}
-
  	obj->syscfg =
  		syscon_regmap_lookup_by_phandle(np, "ti,syscon-mmuconfig");
-	if (IS_ERR(obj->syscfg)) {
-		/* can fail with -EPROBE_DEFER */
-		ret = PTR_ERR(obj->syscfg);
-		return ret;
-	}
+	if (IS_ERR(obj->syscfg))
+		return dev_err_probe(&pdev->dev, PTR_ERR(obj->syscfg),
+				     "ti,syscon-mmuconfig property is missing\n");
 
  	if (of_property_read_u32_index(np, "ti,syscon-mmuconfig", 1,
  				       &obj->id)) {
#3 lore raw

PATCH v3 2/3 iommu: omap: Use syscon_regmap_lookup_by_phandle_args

In reply to Krzysztof Kozlowski

Use syscon_regmap_lookup_by_phandle_args() which is a wrapper over syscon_regmap_lookup_by_phandle() combined with getting the syscon argument. Except simpler code this annotates within one line that given phandle has arguments, so grepping for code would be easier.

There is also no real benefit in printing errors on missing syscon argument, because this is done just too late: runtime check on static/build-time data. Dtschema and Devicetree bindings offer the static/build-time check for this already.

---
 drivers/iommu/omap-iommu.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/iommu/omap-iommu.c +2 -8
index 4448c0a512137c79195112eea25d762266c77bc3..30fdbabbc9c652990e6cd31d3c0a1a06633df9e6 100644
@@ -1127,18 +1127,12 @@ static int omap_iommu_dra7_get_dsp_system_cfg(struct platform_device *pdev,
 	if (!of_device_is_compatible(np, "ti,dra7-dsp-iommu"))
 		return 0;
 
-	obj->syscfg =
-		syscon_regmap_lookup_by_phandle(np, "ti,syscon-mmuconfig");
+	obj->syscfg = syscon_regmap_lookup_by_phandle_args(np, "ti,syscon-mmuconfig",
+							   1, &obj->id);
 	if (IS_ERR(obj->syscfg))
 		return dev_err_probe(&pdev->dev, PTR_ERR(obj->syscfg),
 				     "ti,syscon-mmuconfig property is missing\n");
 
-	if (of_property_read_u32_index(np, "ti,syscon-mmuconfig", 1,
-				       &obj->id)) {
-		dev_err(&pdev->dev, "couldn't get the IOMMU instance id within subsystem\n");
-		return -EINVAL;
-	}
-
 	if (obj->id != 0 && obj->id != 1) {
 		dev_err(&pdev->dev, "invalid IOMMU instance id\n");
 		return -EINVAL;
Signature · 1 line
2.48.1
#4 lore raw

PATCH v3 3/3 iommu: mtk_iommu_v1: Simplify by dropping local 'mtk_mapping' variable

In reply to Krzysztof Kozlowski

Storing 'data->mapping' in local variable in mtk_iommu_v1_probe_finalize() does not make the code easier to read. Use the 'data->mapping' directly.

ARM64 W=1 builds also complain with:

mtk_iommu_v1.c:512:28: error: variable 'mtk_mapping' set but not used [-Werror,-Wunused-but-set-variable]

but this is not being fixed here and 'data' still won't be used in such compile test.

---

Old warning is changed now to:

error: variable 'data' set but not used [-Werror,-Wunused-but-set-variable]

---
 drivers/iommu/mtk_iommu_v1.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iommu/mtk_iommu_v1.c +1 -3
index 66824982e05fbfdda224276ad41b90f9d5f9ca4e..bbe3e9d901c69ac6405d9549a4481fc80f1adb80 100644
@@ -509,14 +509,12 @@ static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev)
 
 static void mtk_iommu_v1_probe_finalize(struct device *dev)
 {
-	struct dma_iommu_mapping *mtk_mapping;
 	struct mtk_iommu_v1_data *data;
 	int err;
 
 	data        = dev_iommu_priv_get(dev);
-	mtk_mapping = data->mapping;
 
-	err = arm_iommu_attach_device(dev, mtk_mapping);
+	err = arm_iommu_attach_device(dev, data->mapping);
 	if (err)
 		dev_err(dev, "Can't create IOMMU mapping - DMA-OPS will not work\n");
 }
Signature · 1 line
2.48.1
reviewer
#5 lore raw

Re: [PATCH v3 3/3] iommu: mtk_iommu_v1: Simplify by dropping local 'mtk_mapping' variable

Quoted 10 lines · Krzysztof Kozlowski

Storing 'data->mapping' in local variable in mtk_iommu_v1_probe_finalize() does not make the code easier to read. Use the 'data->mapping' directly.

ARM64 W=1 builds also complain with:

mtk_iommu_v1.c:512:28: error: variable 'mtk_mapping' set but not used [-Werror,-Wunused-but-set-variable]

but this is not being fixed here and 'data' still won't be used in such compile test.

Sorry, I guess that's on me for doing the COMPILE_TEST stubs the lazy way... TBH I'm still not sure this driver hasn't completely bitrotted, but if we're touching it at all we should probably actually fix the warning, e.g.:

-#define arm_iommu_attach_device(...) -ENODEV
+#define arm_iommu_attach_device(d, m) ((void)m, -ENODEV)

or perhaps make it a less lazy static inline.

Quoted 16 lines

---

Old warning is changed now to:

error: variable 'data' set but not used [-Werror,-Wunused-but-set-variable]

---
  drivers/iommu/mtk_iommu_v1.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iommu/mtk_iommu_v1.c +0 -0
index 66824982e05fbfdda224276ad41b90f9d5f9ca4e..bbe3e9d901c69ac6405d9549a4481fc80f1adb80 100644

drivers/iommu/mtk_iommu_v1.c static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev) · line 515

Quoted 8 lines
drivers/iommu/mtk_iommu_v1.c +0 -1
@@ -509,14 +509,12 @@ static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev)
 
  static void mtk_iommu_v1_probe_finalize(struct device *dev)
  {
-	struct dma_iommu_mapping *mtk_mapping;
  	struct mtk_iommu_v1_data *data;
  	int err;
 
  	data        = dev_iommu_priv_get(dev);

And for the sake of a readability cleanup you may as well fold this into the declaration line as well. And then maybe also whack a __maybe_unused on it, for even less effort than the first silly thing I thought of above... :)

Thanks,
Robin.

Quoted 8 lines
drivers/iommu/mtk_iommu_v1.c +1 -2
-	mtk_mapping = data->mapping;
 
-	err = arm_iommu_attach_device(dev, mtk_mapping);
+	err = arm_iommu_attach_device(dev, data->mapping);
  	if (err)
  		dev_err(dev, "Can't create IOMMU mapping - DMA-OPS will not work\n");
  }
maintainer Applied
#6 lore raw
In reply to Krzysztof Kozlowski
Quoted 4 lines · Krzysztof Kozlowski

Krzysztof Kozlowski (3):
iommu: omap: Drop redundant check if ti,syscon-mmuconfig exists
iommu: omap: Use syscon_regmap_lookup_by_phandle_args
iommu: mtk_iommu_v1: Simplify by dropping local 'mtk_mapping' variable

Applied patches 1 and 2 to the ti/omap branch, thanks.