* [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes
@ 2017-01-26 13:12 Niklas Söderlund
2017-01-26 13:31 ` Geert Uytterhoeven
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Niklas Söderlund @ 2017-01-26 13:12 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Laurent Pinchart
Cc: linux-media, linux-renesas-soc, Niklas Söderlund
All lines in data-lanes and clock-lanes properties must be unique.
Instead of drivers checking for this add it to the generic parser.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
drivers/media/v4l2-core/v4l2-of.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c
index 93b33681776c..1042db6bb996 100644
--- a/drivers/media/v4l2-core/v4l2-of.c
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -32,12 +32,19 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node,
prop = of_find_property(node, "data-lanes", NULL);
if (prop) {
const __be32 *lane = NULL;
- unsigned int i;
+ unsigned int i, n;
for (i = 0; i < ARRAY_SIZE(bus->data_lanes); i++) {
lane = of_prop_next_u32(prop, lane, &v);
if (!lane)
break;
+ for (n = 0; n < i; n++) {
+ if (bus->data_lanes[n] == v) {
+ pr_warn("%s: duplicated lane %u in data-lanes\n",
+ node->full_name, v);
+ return -EINVAL;
+ }
+ }
bus->data_lanes[i] = v;
}
bus->num_data_lanes = i;
@@ -63,6 +70,15 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node,
}
if (!of_property_read_u32(node, "clock-lanes", &v)) {
+ unsigned int n;
+
+ for (n = 0; n < bus->num_data_lanes; n++) {
+ if (bus->data_lanes[n] == v) {
+ pr_warn("%s: duplicated lane %u in clock-lanes\n",
+ node->full_name, v);
+ return -EINVAL;
+ }
+ }
bus->clock_lane = v;
have_clk_lane = true;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes
2017-01-26 13:12 [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes Niklas Söderlund
@ 2017-01-26 13:31 ` Geert Uytterhoeven
2017-01-27 9:31 ` Sakari Ailus
2017-01-28 16:26 ` Laurent Pinchart
2 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2017-01-26 13:31 UTC (permalink / raw)
To: Niklas Söderlund
Cc: Mauro Carvalho Chehab, Laurent Pinchart,
Linux Media Mailing List, Linux-Renesas
Hi Niklas,
On Thu, Jan 26, 2017 at 2:12 PM, Niklas Söderlund
<niklas.soderlund+renesas@ragnatech.se> wrote:
> diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c
> index 93b33681776c..1042db6bb996 100644
> --- a/drivers/media/v4l2-core/v4l2-of.c
> +++ b/drivers/media/v4l2-core/v4l2-of.c
> @@ -32,12 +32,19 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node,
> prop = of_find_property(node, "data-lanes", NULL);
> if (prop) {
> const __be32 *lane = NULL;
> - unsigned int i;
> + unsigned int i, n;
Not "j"?
> for (i = 0; i < ARRAY_SIZE(bus->data_lanes); i++) {
> lane = of_prop_next_u32(prop, lane, &v);
> if (!lane)
> break;
> + for (n = 0; n < i; n++) {
I'm not used seeing for loops with an index named "n", and limit named "i" ;-)
> + if (bus->data_lanes[n] == v) {
> + pr_warn("%s: duplicated lane %u in data-lanes\n",
> + node->full_name, v);
> + return -EINVAL;
> + }
> + }
> bus->data_lanes[i] = v;
> }
> bus->num_data_lanes = i;
> @@ -63,6 +70,15 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node,
> }
>
> if (!of_property_read_u32(node, "clock-lanes", &v)) {
> + unsigned int n;
Likewise.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes
2017-01-26 13:12 [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes Niklas Söderlund
@ 2017-01-27 9:31 ` Sakari Ailus
2017-01-27 9:31 ` Sakari Ailus
2017-01-28 16:26 ` Laurent Pinchart
2 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2017-01-27 9:31 UTC (permalink / raw)
To: Niklas Söderlund
Cc: Mauro Carvalho Chehab, Laurent Pinchart, linux-media, linux-renesas-soc
Hi Niklas,
On Thu, Jan 26, 2017 at 02:12:59PM +0100, Niklas Söderlund wrote:
> All lines in data-lanes and clock-lanes properties must be unique.
> Instead of drivers checking for this add it to the generic parser.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> drivers/media/v4l2-core/v4l2-of.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c
> index 93b33681776c..1042db6bb996 100644
> --- a/drivers/media/v4l2-core/v4l2-of.c
> +++ b/drivers/media/v4l2-core/v4l2-of.c
> @@ -32,12 +32,19 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node,
> prop = of_find_property(node, "data-lanes", NULL);
> if (prop) {
> const __be32 *lane = NULL;
> - unsigned int i;
> + unsigned int i, n;
>
> for (i = 0; i < ARRAY_SIZE(bus->data_lanes); i++) {
> lane = of_prop_next_u32(prop, lane, &v);
> if (!lane)
> break;
> + for (n = 0; n < i; n++) {
> + if (bus->data_lanes[n] == v) {
> + pr_warn("%s: duplicated lane %u in data-lanes\n",
> + node->full_name, v);
> + return -EINVAL;
> + }
> + }
In some cases it's just the number of lanes that matter, not their order, as
the hardware cannot reorder them. I might still just print a warning but not
return an error. Same below.
Although then hardware that actually can reorder the lanes might have issues
if such a bug exists in DTB. Presumably the DTB would have been tested at
some point though.
> bus->data_lanes[i] = v;
> }
> bus->num_data_lanes = i;
> @@ -63,6 +70,15 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node,
> }
>
> if (!of_property_read_u32(node, "clock-lanes", &v)) {
> + unsigned int n;
> +
> + for (n = 0; n < bus->num_data_lanes; n++) {
> + if (bus->data_lanes[n] == v) {
> + pr_warn("%s: duplicated lane %u in clock-lanes\n",
> + node->full_name, v);
> + return -EINVAL;
> + }
> + }
> bus->clock_lane = v;
> have_clk_lane = true;
> }
--
Kind regards,
Sakari Ailus
e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes
@ 2017-01-27 9:31 ` Sakari Ailus
0 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2017-01-27 9:31 UTC (permalink / raw)
To: Niklas Söderlund
Cc: Mauro Carvalho Chehab, Laurent Pinchart, linux-media, linux-renesas-soc
Hi Niklas,
On Thu, Jan 26, 2017 at 02:12:59PM +0100, Niklas S�derlund wrote:
> All lines in data-lanes and clock-lanes properties must be unique.
> Instead of drivers checking for this add it to the generic parser.
>
> Signed-off-by: Niklas S�derlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> drivers/media/v4l2-core/v4l2-of.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c
> index 93b33681776c..1042db6bb996 100644
> --- a/drivers/media/v4l2-core/v4l2-of.c
> +++ b/drivers/media/v4l2-core/v4l2-of.c
> @@ -32,12 +32,19 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node,
> prop = of_find_property(node, "data-lanes", NULL);
> if (prop) {
> const __be32 *lane = NULL;
> - unsigned int i;
> + unsigned int i, n;
>
> for (i = 0; i < ARRAY_SIZE(bus->data_lanes); i++) {
> lane = of_prop_next_u32(prop, lane, &v);
> if (!lane)
> break;
> + for (n = 0; n < i; n++) {
> + if (bus->data_lanes[n] == v) {
> + pr_warn("%s: duplicated lane %u in data-lanes\n",
> + node->full_name, v);
> + return -EINVAL;
> + }
> + }
In some cases it's just the number of lanes that matter, not their order, as
the hardware cannot reorder them. I might still just print a warning but not
return an error. Same below.
Although then hardware that actually can reorder the lanes might have issues
if such a bug exists in DTB. Presumably the DTB would have been tested at
some point though.
> bus->data_lanes[i] = v;
> }
> bus->num_data_lanes = i;
> @@ -63,6 +70,15 @@ static int v4l2_of_parse_csi_bus(const struct device_node *node,
> }
>
> if (!of_property_read_u32(node, "clock-lanes", &v)) {
> + unsigned int n;
> +
> + for (n = 0; n < bus->num_data_lanes; n++) {
> + if (bus->data_lanes[n] == v) {
> + pr_warn("%s: duplicated lane %u in clock-lanes\n",
> + node->full_name, v);
> + return -EINVAL;
> + }
> + }
> bus->clock_lane = v;
> have_clk_lane = true;
> }
--
Kind regards,
Sakari Ailus
e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes
2017-01-26 13:12 [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes Niklas Söderlund
2017-01-26 13:31 ` Geert Uytterhoeven
2017-01-27 9:31 ` Sakari Ailus
@ 2017-01-28 16:26 ` Laurent Pinchart
2 siblings, 0 replies; 5+ messages in thread
From: Laurent Pinchart @ 2017-01-28 16:26 UTC (permalink / raw)
To: Niklas Söderlund
Cc: Mauro Carvalho Chehab, linux-media, linux-renesas-soc
Hi Niklas,
Thank you for the patch.
On Thursday 26 Jan 2017 14:12:59 Niklas Söderlund wrote:
> All lines in data-lanes and clock-lanes properties must be unique.
> Instead of drivers checking for this add it to the generic parser.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> drivers/media/v4l2-core/v4l2-of.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-of.c
> b/drivers/media/v4l2-core/v4l2-of.c index 93b33681776c..1042db6bb996 100644
> --- a/drivers/media/v4l2-core/v4l2-of.c
> +++ b/drivers/media/v4l2-core/v4l2-of.c
> @@ -32,12 +32,19 @@ static int v4l2_of_parse_csi_bus(const struct
> device_node *node, prop = of_find_property(node, "data-lanes", NULL);
> if (prop) {
> const __be32 *lane = NULL;
> - unsigned int i;
> + unsigned int i, n;
>
> for (i = 0; i < ARRAY_SIZE(bus->data_lanes); i++) {
> lane = of_prop_next_u32(prop, lane, &v);
> if (!lane)
> break;
> + for (n = 0; n < i; n++) {
> + if (bus->data_lanes[n] == v) {
> + pr_warn("%s: duplicated lane %u in
data-lanes\n",
> + node->full_name, v);
> + return -EINVAL;
> + }
If you used a bitmask to store the already used lanes you could avoid the
nested loops.
Apart from that,
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + }
> bus->data_lanes[i] = v;
> }
> bus->num_data_lanes = i;
> @@ -63,6 +70,15 @@ static int v4l2_of_parse_csi_bus(const struct device_node
> *node, }
>
> if (!of_property_read_u32(node, "clock-lanes", &v)) {
> + unsigned int n;
> +
> + for (n = 0; n < bus->num_data_lanes; n++) {
> + if (bus->data_lanes[n] == v) {
> + pr_warn("%s: duplicated lane %u in clock-
lanes\n",
> + node->full_name, v);
> + return -EINVAL;
> + }
> + }
> bus->clock_lane = v;
> have_clk_lane = true;
> }
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-01-28 16:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-26 13:12 [PATCH] v4l: of: check for unique lanes in data-lanes and clock-lanes Niklas Söderlund
2017-01-26 13:31 ` Geert Uytterhoeven
2017-01-27 9:31 ` Sakari Ailus
2017-01-27 9:31 ` Sakari Ailus
2017-01-28 16:26 ` Laurent Pinchart
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.