Skip to contentSkip to conversation

Bugfix for the fwnode smatch warning fix

PATCH New Sakari Ailus 1 participant 4 messages Aug 14, 2017

Subsystems (2)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

cover Bugfix for the fwnode smatch warning fix

Hi folks,

Here's a few patches to address a subtle but serious bug introduced in the fwnode smatch warning fix. The first patch fixes a bug whereas the second one returns the way the lane polarity array size is calculatated consistent across V4L2 fwnode.

Sakari Ailus (2):
v4l: fwnode: Fix lane-polarities property parsing
v4l: fwnode: The clock lane is the first lane in lane_polarities

 drivers/media/v4l2-core/v4l2-fwnode.c | 12 ++++++++----
 include/media/v4l2-fwnode.h           |  2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 1/2 v4l: fwnode: Fix lane-polarities property parsing

fwnode_property_read_u32_array() only returns the number of array elements if the array argument is NULL. The assumption that it always did so lead to lane-polarities properties never being read.

Fixes 4ee236219f6d ("media: v4l2-fwnode: suppress a warning at OF parsing logic")
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +7 -3
index d07c54efaa99..29e41312f04a 100644
@@ -65,19 +65,23 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 		}
 
 		rval = fwnode_property_read_u32_array(fwnode,
-						      "lane-polarities", array,
-						      1 + bus->num_data_lanes);
+						      "lane-polarities", NULL,
+						      0);
 		if (rval > 0) {
-			if (rval != 1 + bus->num_data_lanes /* clock + data */) {
+			if (rval != 1 + bus->num_data_lanes /* clock+data */) {
 				pr_warn("invalid number of lane-polarities entries (need %u, got %u)\n",
 					1 + bus->num_data_lanes, rval);
 				return -EINVAL;
 			}
 
+			fwnode_property_read_u32_array(fwnode,
+						       "lane-polarities", array,
+						       1 + bus->num_data_lanes);
 
 			for (i = 0; i < 1 + bus->num_data_lanes; i++)
 				bus->lane_polarities[i] = array[i];
 		}
+
 	}
 
 	if (!fwnode_property_read_u32(fwnode, "clock-lanes", &v)) {
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH 2/2 v4l: fwnode: The clock lane is the first lane in lane_polarities

In reply to Sakari Ailus

The clock lane is the first lane in the lane_polarities array. Reflect this consistently by putting the number of data lanes after the number of clock lanes.

Fixes 4ee236219f6d ("media: v4l2-fwnode: suppress a warning at OF parsing logic")
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 2 +-
 include/media/v4l2-fwnode.h           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +1 -1
index 29e41312f04a..c9147ec398b3 100644
@@ -48,7 +48,7 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 
 	rval = fwnode_property_read_u32_array(fwnode, "data-lanes", NULL, 0);
 	if (rval > 0) {
-		u32 array[MAX_DATA_LANES + 1];
+		u32 array[1 + MAX_DATA_LANES];
 
 		bus->num_data_lanes = min_t(int, MAX_DATA_LANES, rval);
 
include/media/v4l2-fwnode.h +1 -1
index b373c43f65e8..8da716a6a1b8 100644
@@ -42,7 +42,7 @@ struct v4l2_fwnode_bus_mipi_csi2 {
 	unsigned char data_lanes[MAX_DATA_LANES];
 	unsigned char clock_lane;
 	unsigned short num_data_lanes;
-	bool lane_polarities[MAX_DATA_LANES + 1];
+	bool lane_polarities[1 + MAX_DATA_LANES];
 };
 
 /**
Signature · 1 line
2.11.0
author maintainer
#3 lore raw

PATCH 3/3 v4l: fwnode: Use a less clash-prone name for MAX_DATA_LANES macro

In reply to Sakari Ailus

Avoid using a generic name such as MAX_DATA_LANES in a header file widely included in drivers. Instead, call it V4L2_FWNODE_CSI2_MAX_DATA_LANES.

Fixes 4ee236219f6d ("media: v4l2-fwnode: suppress a warning at OF parsing logic")
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 5 +++--
 include/media/v4l2-fwnode.h           | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +3 -2
index df7169b5ed8c..40b2fbfe8865 100644
@@ -48,9 +48,10 @@ static int v4l2_fwnode_endpoint_parse_csi2_bus(struct fwnode_handle *fwnode,
 
 	rval = fwnode_property_read_u32_array(fwnode, "data-lanes", NULL, 0);
 	if (rval > 0) {
-		u32 array[1 + MAX_DATA_LANES];
+		u32 array[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES];
 
-		bus->num_data_lanes = min_t(int, MAX_DATA_LANES, rval);
+		bus->num_data_lanes =
+			min_t(int, V4L2_FWNODE_CSI2_MAX_DATA_LANES, rval);
 
 		fwnode_property_read_u32_array(fwnode, "data-lanes", array,
 					       bus->num_data_lanes);
include/media/v4l2-fwnode.h +3 -3
index 08e743fb7944..7adec9851d9e 100644
@@ -26,7 +26,7 @@
 
 struct fwnode_handle;
 
-#define MAX_DATA_LANES	4
+#define V4L2_FWNODE_CSI2_MAX_DATA_LANES	4
 
 /**
  * struct v4l2_fwnode_bus_mipi_csi2 - MIPI CSI-2 bus data structure
@@ -39,10 +39,10 @@ struct fwnode_handle;
  */
 struct v4l2_fwnode_bus_mipi_csi2 {
 	unsigned int flags;
-	unsigned char data_lanes[MAX_DATA_LANES];
+	unsigned char data_lanes[V4L2_FWNODE_CSI2_MAX_DATA_LANES];
 	unsigned char clock_lane;
 	unsigned short num_data_lanes;
-	bool lane_polarities[1 + MAX_DATA_LANES];
+	bool lane_polarities[1 + V4L2_FWNODE_CSI2_MAX_DATA_LANES];
 };
 
 /**
Signature · 1 line
2.11.0