Skip to contentSkip to conversation

v4l: fwnode: Remove now-redundant loop from v4l2_fwnode_parse_reference()

PATCH In review Sakari Ailus 3 participants 3 messages Feb 23, 2022

Subsystems (2)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

PATCH 1/1 v4l: fwnode: Remove now-redundant loop from v4l2_fwnode_parse_reference()

v4l2_fwnode_parse_reference() relied on counting the number of references for async array memory allocation. The array is long gone so remove counting the references now.

This also changes how the function arrives in different unsuccessful return values but the functionality remains unchanged.

Also the check for -ENODATA is removed, it was made redundant by commit c343bc2ce2c6 ("ACPI: properties: Align return codes of __acpi_node_get_property_reference()").

---
 drivers/media/v4l2-core/v4l2-fwnode.c | 28 ++++++++-------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +8 -20
index 71dcc9a96535..fe2dfc8f9d56 100644
@@ -894,25 +894,8 @@ static int v4l2_fwnode_reference_parse(struct device *dev,
 	int ret;
 
 	for (index = 0;
-	     !(ret = fwnode_property_get_reference_args(dev_fwnode(dev),
-							prop, NULL, 0,
-							index, &args));
-	     index++)
-		fwnode_handle_put(args.fwnode);
-
-	if (!index)
-		return -ENOENT;
-
-	/*
-	 * Note that right now both -ENODATA and -ENOENT may signal
-	 * out-of-bounds access. Return the error in cases other than that.
-	 */
-	if (ret != -ENOENT && ret != -ENODATA)
-		return ret;
-
-	for (index = 0;
-	     !fwnode_property_get_reference_args(dev_fwnode(dev), prop, NULL,
-						 0, index, &args);
+	     !(ret = fwnode_property_get_reference_args(dev_fwnode(dev), prop,
+							NULL, 0, index, &args));
 	     index++) {
 		struct v4l2_async_subdev *asd;
 
@@ -928,7 +911,12 @@ static int v4l2_fwnode_reference_parse(struct device *dev,
 		}
 	}
 
-	return 0;
+	/* -ENOENT here means successful parsing */
+	if (ret != -ENOENT)
+		return ret;
+
+	/* Return -ENOENT if no references were found */
+	return index ?: -ENOENT;
 }
 
 /*
Signature · 1 line
2.30.2
#1 lore raw

Hi Sakari,

Thank you for the patch.

Quoted 10 lines · Sakari Ailus

v4l2_fwnode_parse_reference() relied on counting the number of references for async array memory allocation. The array is long gone so remove counting the references now.

This also changes how the function arrives in different unsuccessful return values but the functionality remains unchanged.

Also the check for -ENODATA is removed, it was made redundant by commit c343bc2ce2c6 ("ACPI: properties: Align return codes of __acpi_node_get_property_reference()").

I would have done this first in a separate patch.

Quoted 38 lines
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 28 ++++++++-------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +2 -19
index 71dcc9a96535..fe2dfc8f9d56 100644
@@ -894,25 +894,8 @@ static int v4l2_fwnode_reference_parse(struct device *dev,
 	int ret;
 
 	for (index = 0;
-	     !(ret = fwnode_property_get_reference_args(dev_fwnode(dev),
-							prop, NULL, 0,
-							index, &args));
-	     index++)
-		fwnode_handle_put(args.fwnode);
-
-	if (!index)
-		return -ENOENT;
-
-	/*
-	 * Note that right now both -ENODATA and -ENOENT may signal
-	 * out-of-bounds access. Return the error in cases other than that.
-	 */
-	if (ret != -ENOENT && ret != -ENODATA)
-		return ret;
-
-	for (index = 0;
-	     !fwnode_property_get_reference_args(dev_fwnode(dev), prop, NULL,
-						 0, index, &args);
+	     !(ret = fwnode_property_get_reference_args(dev_fwnode(dev), prop,
+							NULL, 0, index, &args));
 	     index++) {
 		struct v4l2_async_subdev *asd;
 

drivers/media/v4l2-core/v4l2-fwnode.c static int v4l2_fwnode_reference_parse(struct device *dev, · line 919

Quoted 10 lines
drivers/media/v4l2-core/v4l2-fwnode.c +6 -1
@@ -928,7 +911,12 @@ static int v4l2_fwnode_reference_parse(struct device *dev,
 		}
 	}
 
-	return 0;
+	/* -ENOENT here means successful parsing */
+	if (ret != -ENOENT)
+		return ret;
+
+	/* Return -ENOENT if no references were found */
+	return index ?: -ENOENT;

The function now returns index on success, while it used to return 0. Is it intentional ?

Quoted 3 lines
drivers/media/v4l2-core/v4l2-fwnode.c +0 -0
 }
 
 /*
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

Hi Laurent,

Thanks for the review.

Quoted 9 lines · Laurent Pinchart

Hi Sakari,

Thank you for the patch.

Quoted 4 lines · Sakari Ailus

v4l2_fwnode_parse_reference() relied on counting the number of references for async array memory allocation. The array is long gone so remove counting the references now.

Quoted 8 lines
Quoted 6 lines

This also changes how the function arrives in different unsuccessful return values but the functionality remains unchanged.

Also the check for -ENODATA is removed, it was made redundant by commit c343bc2ce2c6 ("ACPI: properties: Align return codes of __acpi_node_get_property_reference()").

I would have done this first in a separate patch.

I'll split this.

Quoted 42 lines
Quoted 42 lines
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 28 ++++++++-------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +2 -19
index 71dcc9a96535..fe2dfc8f9d56 100644
@@ -894,25 +894,8 @@ static int v4l2_fwnode_reference_parse(struct device *dev,
 	int ret;
 
 	for (index = 0;
-	     !(ret = fwnode_property_get_reference_args(dev_fwnode(dev),
-							prop, NULL, 0,
-							index, &args));
-	     index++)
-		fwnode_handle_put(args.fwnode);
-
-	if (!index)
-		return -ENOENT;
-
-	/*
-	 * Note that right now both -ENODATA and -ENOENT may signal
-	 * out-of-bounds access. Return the error in cases other than that.
-	 */
-	if (ret != -ENOENT && ret != -ENODATA)
-		return ret;
-
-	for (index = 0;
-	     !fwnode_property_get_reference_args(dev_fwnode(dev), prop, NULL,
-						 0, index, &args);
+	     !(ret = fwnode_property_get_reference_args(dev_fwnode(dev), prop,
+							NULL, 0, index, &args));
 	     index++) {
 		struct v4l2_async_subdev *asd;
 
@@ -928,7 +911,12 @@ static int v4l2_fwnode_reference_parse(struct device *dev,
 		}
 	}
 
Quoted 10 lines

drivers/media/v4l2-core/v4l2-fwnode.c static int v4l2_fwnode_reference_parse(struct device *dev, · line 919

Quoted 7 lines
drivers/media/v4l2-core/v4l2-fwnode.c +6 -1
-	return 0;
+	/* -ENOENT here means successful parsing */
+	if (ret != -ENOENT)
+		return ret;
+
+	/* Return -ENOENT if no references were found */
+	return index ?: -ENOENT;

The function now returns index on success, while it used to return 0. Is it intentional ?

No, I'll fix that for v2.

Signature · 3 lines
Regards,

Sakari Ailus