All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm: rcar-du: dsi: Fix hsfreq range matching
@ 2021-12-06 14:06 Laurent Pinchart
  2021-12-06 15:36 ` Kieran Bingham
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Pinchart @ 2021-12-06 14:06 UTC (permalink / raw)
  To: dri-devel; +Cc: linux-renesas-soc, Kieran Bingham, LUU HOAI, Dan Carpenter

When iterating over hsfreqrange_table, rcar_mipi_dsi_parameters_calc()
may dereference the sentinel table entry. Fix the loop condition to
break as soon as a suitable entry is found, defined by the lower bound
of the frequency range stored in the table being equal to or higher than
the target frequency.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
I will squash this with "drm: rcar-du: Add R-Car DSI driver", but I'm
posting it separately to ease review.
---
 drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c b/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
index faf993eae564..891bb956fd61 100644
--- a/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
+++ b/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
@@ -219,9 +219,8 @@ static void rcar_mipi_dsi_parameters_calc(struct rcar_mipi_dsi *dsi,
 	/* Find hsfreqrange */
 	hsfreq = fout_target * 2;
 	for (i = 0; i < ARRAY_SIZE(hsfreqrange_table); i++) {
-		if (hsfreq > hsfreqrange_table[i][0] &&
-			hsfreq <= hsfreqrange_table[i+1][0]) {
-			setup_info->hsfreqrange = hsfreqrange_table[i+1][1];
+		if (hsfreqrange_table[i][0] >= hsfreq) {
+			setup_info->hsfreqrange = hsfreqrange_table[i][1];
 			break;
 		}
 	}

base-commit: c18c8891111bb5e014e144716044991112f16833
prerequisite-patch-id: dc9121a1b85ea05bf3eae2b0ac2168d47101ee87
prerequisite-patch-id: 6754b2ec4caec03e235550004003fe63c1cc793b
prerequisite-patch-id: d69c605df34d40934fa5d4e00f23d5785105099d
prerequisite-patch-id: 7d9edfb4758cafe8aec92d32709c0ad25a50942c
prerequisite-patch-id: 86c526fb41f9f9cbe95c50ba8a140e20484f187f
prerequisite-patch-id: a9649b53b55858f023b8d3d29afb9be7ad39ea3b
-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH] drm: rcar-du: dsi: Fix hsfreq range matching
  2021-12-06 14:06 [PATCH] drm: rcar-du: dsi: Fix hsfreq range matching Laurent Pinchart
@ 2021-12-06 15:36 ` Kieran Bingham
  0 siblings, 0 replies; 2+ messages in thread
From: Kieran Bingham @ 2021-12-06 15:36 UTC (permalink / raw)
  To: Laurent Pinchart, dri-devel; +Cc: linux-renesas-soc, LUU HOAI, Dan Carpenter

Quoting Laurent Pinchart (2021-12-06 14:06:01)
> When iterating over hsfreqrange_table, rcar_mipi_dsi_parameters_calc()
> may dereference the sentinel table entry. Fix the loop condition to
> break as soon as a suitable entry is found, defined by the lower bound
> of the frequency range stored in the table being equal to or higher than
> the target frequency.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> ---
> I will squash this with "drm: rcar-du: Add R-Car DSI driver", but I'm
> posting it separately to ease review.
> ---
>  drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c b/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
> index faf993eae564..891bb956fd61 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
> @@ -219,9 +219,8 @@ static void rcar_mipi_dsi_parameters_calc(struct rcar_mipi_dsi *dsi,
>         /* Find hsfreqrange */
>         hsfreq = fout_target * 2;
>         for (i = 0; i < ARRAY_SIZE(hsfreqrange_table); i++) {
> -               if (hsfreq > hsfreqrange_table[i][0] &&
> -                       hsfreq <= hsfreqrange_table[i+1][0]) {
> -                       setup_info->hsfreqrange = hsfreqrange_table[i+1][1];
> +               if (hsfreqrange_table[i][0] >= hsfreq) {

It's hard to tell from this patch, or this point alone, but I see that
fout_target is already limited at 1250000000, so hsfreq can never be
bigger than 2500000000U.

So ... this is fine (as long as the table and validation check are kept
in sync if anyone updates this).

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

Also validated that it still boots/probes and displays pictures with
kmstest and kmstest --flip.

--
Kieran


> +                       setup_info->hsfreqrange = hsfreqrange_table[i][1];
>                         break;
>                 }
>         }
> 
> base-commit: c18c8891111bb5e014e144716044991112f16833
> prerequisite-patch-id: dc9121a1b85ea05bf3eae2b0ac2168d47101ee87
> prerequisite-patch-id: 6754b2ec4caec03e235550004003fe63c1cc793b
> prerequisite-patch-id: d69c605df34d40934fa5d4e00f23d5785105099d
> prerequisite-patch-id: 7d9edfb4758cafe8aec92d32709c0ad25a50942c
> prerequisite-patch-id: 86c526fb41f9f9cbe95c50ba8a140e20484f187f
> prerequisite-patch-id: a9649b53b55858f023b8d3d29afb9be7ad39ea3b
> -- 
> Regards,
> 
> Laurent Pinchart
>

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

end of thread, other threads:[~2021-12-06 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-06 14:06 [PATCH] drm: rcar-du: dsi: Fix hsfreq range matching Laurent Pinchart
2021-12-06 15:36 ` Kieran Bingham

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.