Skip to contentSkip to conversation

Cleanup scrap in v4l2_fwnode_reference_parse()

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

Subsystems (2)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

cover Cleanup scrap in v4l2_fwnode_reference_parse()

Hi,

This set removes a redundant return value check and an extra loop in v4l2_fwnode_reference_parse().

Since v1:

- Split the patch in two, prepending the patch with another that just removes -ENODATA check.

- Fix return value of v4l2_fwnode_reference_parse() that was unintentionally changed in the process.

Sakari Ailus (2):
v4l: fwnode: Drop redunant -ENODATA check in property reference
parsing
v4l: fwnode: Remove now-redundant loop from
v4l2_fwnode_parse_reference()

 drivers/media/v4l2-core/v4l2-fwnode.c | 28 ++++++++-------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 1/2 v4l: fwnode: Drop redunant -ENODATA check in property reference parsing

The check of -ENODATA return value from fwnode_property_get_reference_args() was made redundant by commit c343bc2ce2c6 ("ACPI: properties: Align return codes of __acpi_node_get_property_reference()"). -ENOENT remains to be used to signal there are no further entries.

Remove the check for -ENODATA.

---
 drivers/media/v4l2-core/v4l2-fwnode.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +1 -5
index 71dcc9a96535..ae140443847b 100644
@@ -903,11 +903,7 @@ static int v4l2_fwnode_reference_parse(struct device *dev,
 	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)
+	if (ret != -ENOENT)
 		return ret;
 
 	for (index = 0;
Signature · 1 line
2.30.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] v4l: fwnode: Drop redunant -ENODATA check in property reference parsing

Hi Sakari,

Thank you for the patch.

Quoted 9 lines · Sakari Ailus

The check of -ENODATA return value from fwnode_property_get_reference_args() was made redundant by commit c343bc2ce2c6 ("ACPI: properties: Align return codes of __acpi_node_get_property_reference()"). -ENOENT remains to be used to signal there are no further entries.

Remove the check for -ENODATA.

Quoted 21 lines
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +1 -5
index 71dcc9a96535..ae140443847b 100644
@@ -903,11 +903,7 @@ static int v4l2_fwnode_reference_parse(struct device *dev,
 	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)
+	if (ret != -ENOENT)
 		return ret;
 
 	for (index = 0;
Signature · 3 lines
Regards,

Laurent Pinchart
author maintainer
#3 lore raw

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

In reply to 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()").

---
 drivers/media/v4l2-core/v4l2-fwnode.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +8 -16
index ae140443847b..afceb35e500c 100644
@@ -894,21 +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;
-
-	if (ret != -ENOENT)
-		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;
 
@@ -924,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 ? 0 : -ENOENT;
 }
 
 /*
Signature · 1 line
2.30.2
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] v4l: fwnode: Remove now-redundant loop from v4l2_fwnode_parse_reference()

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()").

This paragraph should be dropped.

Quoted 1 line
Quoted 46 lines
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +8 -16
index ae140443847b..afceb35e500c 100644
@@ -894,21 +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;
-
-	if (ret != -ENOENT)
-		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;
 
@@ -924,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 ? 0 : -ENOENT;
 }
 
 /*
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

Re: [PATCH 2/2] v4l: fwnode: Remove now-redundant loop from v4l2_fwnode_parse_reference()

Quoted 16 lines · Laurent Pinchart

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()").

Quoted 5 lines

This paragraph should be dropped.

Quoted 1 line

Thanks for the review.

I'll drop it when applying.

Signature · 1 line
Sakari Ailus