All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] [PATCH 0/2] Bugfix for the fwnode smatch warning fix
@ 2017-08-14 10:31 Sakari Ailus
  2017-08-14 10:31 ` [PATCH 1/2] v4l: fwnode: Fix lane-polarities property parsing Sakari Ailus
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sakari Ailus @ 2017-08-14 10:31 UTC (permalink / raw)
  To: linux-media; +Cc: mchehab, hverkuil, laurent.pinchart

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

-- 
2.11.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] v4l: fwnode: Fix lane-polarities property parsing
  2017-08-14 10:31 [PATCH 0/2] [PATCH 0/2] Bugfix for the fwnode smatch warning fix Sakari Ailus
@ 2017-08-14 10:31 ` Sakari Ailus
  2017-08-14 10:31 ` [PATCH 2/2] v4l: fwnode: The clock lane is the first lane in lane_polarities Sakari Ailus
  2017-08-14 10:46 ` [PATCH 3/3] v4l: fwnode: Use a less clash-prone name for MAX_DATA_LANES macro Sakari Ailus
  2 siblings, 0 replies; 4+ messages in thread
From: Sakari Ailus @ 2017-08-14 10:31 UTC (permalink / raw)
  To: linux-media; +Cc: mchehab, hverkuil, laurent.pinchart

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")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index d07c54efaa99..29e41312f04a 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -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)) {
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] v4l: fwnode: The clock lane is the first lane in lane_polarities
  2017-08-14 10:31 [PATCH 0/2] [PATCH 0/2] Bugfix for the fwnode smatch warning fix Sakari Ailus
  2017-08-14 10:31 ` [PATCH 1/2] v4l: fwnode: Fix lane-polarities property parsing Sakari Ailus
@ 2017-08-14 10:31 ` Sakari Ailus
  2017-08-14 10:46 ` [PATCH 3/3] v4l: fwnode: Use a less clash-prone name for MAX_DATA_LANES macro Sakari Ailus
  2 siblings, 0 replies; 4+ messages in thread
From: Sakari Ailus @ 2017-08-14 10:31 UTC (permalink / raw)
  To: linux-media; +Cc: mchehab, hverkuil, laurent.pinchart

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")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 2 +-
 include/media/v4l2-fwnode.h           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index 29e41312f04a..c9147ec398b3 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -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);
 
diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
index b373c43f65e8..8da716a6a1b8 100644
--- a/include/media/v4l2-fwnode.h
+++ b/include/media/v4l2-fwnode.h
@@ -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];
 };
 
 /**
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] v4l: fwnode: Use a less clash-prone name for MAX_DATA_LANES macro
  2017-08-14 10:31 [PATCH 0/2] [PATCH 0/2] Bugfix for the fwnode smatch warning fix Sakari Ailus
  2017-08-14 10:31 ` [PATCH 1/2] v4l: fwnode: Fix lane-polarities property parsing Sakari Ailus
  2017-08-14 10:31 ` [PATCH 2/2] v4l: fwnode: The clock lane is the first lane in lane_polarities Sakari Ailus
@ 2017-08-14 10:46 ` Sakari Ailus
  2 siblings, 0 replies; 4+ messages in thread
From: Sakari Ailus @ 2017-08-14 10:46 UTC (permalink / raw)
  To: linux-media; +Cc: mchehab, hverkuil, laurent.pinchart

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")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 5 +++--
 include/media/v4l2-fwnode.h           | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index df7169b5ed8c..40b2fbfe8865 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -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);
diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
index 08e743fb7944..7adec9851d9e 100644
--- a/include/media/v4l2-fwnode.h
+++ b/include/media/v4l2-fwnode.h
@@ -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];
 };
 
 /**
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-08-14 10:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-14 10:31 [PATCH 0/2] [PATCH 0/2] Bugfix for the fwnode smatch warning fix Sakari Ailus
2017-08-14 10:31 ` [PATCH 1/2] v4l: fwnode: Fix lane-polarities property parsing Sakari Ailus
2017-08-14 10:31 ` [PATCH 2/2] v4l: fwnode: The clock lane is the first lane in lane_polarities Sakari Ailus
2017-08-14 10:46 ` [PATCH 3/3] v4l: fwnode: Use a less clash-prone name for MAX_DATA_LANES macro Sakari Ailus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.