Bugfix for the fwnode smatch warning fix
Subsystems (2)
Sakari Ailus
maintainercover 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
Sakari Ailus
maintainerPATCH 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.
--- drivers/media/v4l2-core/v4l2-fwnode.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/media/v4l2-core/v4l2-fwnode.c +7 -3
@@ -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
Sakari Ailus
maintainerPATCH 2/2 v4l: fwnode: The clock lane is the first lane in lane_polarities
In reply to Sakari AilusThe 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.
--- 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
@@ -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
@@ -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
Sakari Ailus
maintainerPATCH 3/3 v4l: fwnode: Use a less clash-prone name for MAX_DATA_LANES macro
In reply to Sakari AilusAvoid 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.
--- 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
@@ -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
@@ -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