Skip to contentSkip to conversation

media: v4l2-fwnode: Allow passing NULL fwnode to endpoint parsers

PATCH Superseded Sakari Ailus 2 participants 3 messages Nov 12, 2025 – Nov 13, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

PATCH 1/1 media: v4l2-fwnode: Allow passing NULL fwnode to endpoint parsers

v4l2_fwnode_endpoint_parse() and v4l2_fwnode_endpoint_alloc_parse() take a fwnode as the first argument and leave it up to the caller to check a valid fwnode has been obtained through various means. Instead, add a check here so the callers won't need to do that anymore.

---
 drivers/media/v4l2-core/v4l2-fwnode.c | 3 +++
 include/media/v4l2-fwnode.h           | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +3 -0
index cb153ce42c45..22ec702a4567 100644
@@ -465,6 +465,9 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 	enum v4l2_mbus_type mbus_type;
 	int rval;
 
+	if (!fwnode)
+		return -EINVAL;
+
 	pr_debug("===== begin parsing endpoint %pfw\n", fwnode);
 
 	fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
include/media/v4l2-fwnode.h +2 -2
index f7c57c776589..299b60ce960b 100644
@@ -182,7 +182,7 @@ enum v4l2_fwnode_bus_type {
 
 /**
  * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
- * @fwnode: pointer to the endpoint's fwnode handle
+ * @fwnode: pointer to the endpoint's fwnode handle (may be NULL)
  * @vep: pointer to the V4L2 fwnode data structure
  *
  * This function parses the V4L2 fwnode endpoint specific parameters from the
@@ -236,7 +236,7 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
 
 /**
  * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
- * @fwnode: pointer to the endpoint's fwnode handle
+ * @fwnode: pointer to the endpoint's fwnode handle (may be NULL)
  * @vep: pointer to the V4L2 fwnode data structure
  *
  * This function parses the V4L2 fwnode endpoint specific parameters from the
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw

Hi Sakari,

Thanks for the patch!

Quoted 6 lines · Sakari Ailus

v4l2_fwnode_endpoint_parse() and v4l2_fwnode_endpoint_alloc_parse() take a fwnode as the first argument and leave it up to the caller to check a valid fwnode has been obtained through various means. Instead, add a check here so the callers won't need to do that anymore.

LGTM, just one question...

Quoted 24 lines
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 3 +++
 include/media/v4l2-fwnode.h           | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +3 -0
index cb153ce42c45..22ec702a4567 100644
@@ -465,6 +465,9 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 	enum v4l2_mbus_type mbus_type;
 	int rval;
 
+	if (!fwnode)
+		return -EINVAL;
+
 	pr_debug("===== begin parsing endpoint %pfw\n", fwnode);
 
 	fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
include/media/v4l2-fwnode.h +0 -0
index f7c57c776589..299b60ce960b 100644

include/media/v4l2-fwnode.h enum v4l2_fwnode_bus_type { · line 185

Quoted 5 lines
include/media/v4l2-fwnode.h +1 -1
@@ -182,7 +182,7 @@ enum v4l2_fwnode_bus_type {
 
 /**
  * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
- * @fwnode: pointer to the endpoint's fwnode handle
+ * @fwnode: pointer to the endpoint's fwnode handle (may be NULL)

... isn't that addition a bit misleading? It says it may be NULL, but it returns an error in this case?

Checking for pointer == NULL in public functions is excellent practice, but I wouldn't say this needs to be emphasized in the argument documentation. But that's just my €0.02, I am fine either way.

Best regards,
Michael

include/media/v4l2-fwnode.h void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep); · line 239

Quoted 9 lines
include/media/v4l2-fwnode.h +1 -1
  * @vep: pointer to the V4L2 fwnode data structure
  *
  * This function parses the V4L2 fwnode endpoint specific parameters from the
@@ -236,7 +236,7 @@ void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep);
 
 /**
  * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
- * @fwnode: pointer to the endpoint's fwnode handle
+ * @fwnode: pointer to the endpoint's fwnode handle (may be NULL)

PS.: Same here of course

Quoted 3 lines
include/media/v4l2-fwnode.h +0 -0
  * @vep: pointer to the V4L2 fwnode data structure
  *
  * This function parses the V4L2 fwnode endpoint specific parameters from the
author maintainer
#2 lore raw

Hi Michael,

Quoted 5 lines · Michael Riesch

Hi Sakari,

Thanks for the patch!

On 11/12/25 11:03, Sakari Ailus wrote:

Quoted 8 lines
Quoted 6 lines

v4l2_fwnode_endpoint_parse() and v4l2_fwnode_endpoint_alloc_parse() take a fwnode as the first argument and leave it up to the caller to check a valid fwnode has been obtained through various means. Instead, add a check here so the callers won't need to do that anymore.

Thank you.

Quoted 36 lines

LGTM, just one question...

Quoted 24 lines
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 3 +++
 include/media/v4l2-fwnode.h           | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +3 -0
index cb153ce42c45..22ec702a4567 100644
@@ -465,6 +465,9 @@ static int __v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
 	enum v4l2_mbus_type mbus_type;
 	int rval;
 
+	if (!fwnode)
+		return -EINVAL;
+
 	pr_debug("===== begin parsing endpoint %pfw\n", fwnode);
 
 	fwnode_property_read_u32(fwnode, "bus-type", &bus_type);
include/media/v4l2-fwnode.h +0 -0
index f7c57c776589..299b60ce960b 100644

include/media/v4l2-fwnode.h enum v4l2_fwnode_bus_type { · line 185

Quoted 5 lines
include/media/v4l2-fwnode.h +1 -1
@@ -182,7 +182,7 @@ enum v4l2_fwnode_bus_type {
 
 /**
  * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
- * @fwnode: pointer to the endpoint's fwnode handle
+ * @fwnode: pointer to the endpoint's fwnode handle (may be NULL)

... isn't that addition a bit misleading? It says it may be NULL, but it returns an error in this case?

Quoted 3 lines

Checking for pointer == NULL in public functions is excellent practice, but I wouldn't say this needs to be emphasized in the argument documentation. But that's just my €0.02, I am fine either way.

Such wording is used elsewhere to signal NULL for something is acceptable. Obviously this leads to parsing failure in this case. I'll add an explicit note on this for -EINVAL code, how about that?

Signature · 3 lines
Kind regards,

Sakari Ailus