diff mbox

[2/3] drm/sun4i: rgb: Fix potential division by zero

Message ID 20180221125703.4595-2-maxime.ripard@bootlin.com (mailing list archive)
State New, archived
Headers show

Commit Message

Maxime Ripard Feb. 21, 2018, 12:57 p.m. UTC
In the case where mode_valid callback of our RGB connector was called
before mode_set was being called, the range of dividers would not be set,
resulting in a division by zero later on in the clk_round_rate logic.

Set the range of dividers before calling clk_round_rate to fix this.

Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
---
 drivers/gpu/drm/sun4i/sun4i_rgb.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Giulio Benetti Feb. 28, 2018, 5:09 p.m. UTC | #1
Il 21/02/2018 13:57, Maxime Ripard ha scritto:
> In the case where mode_valid callback of our RGB connector was called
> before mode_set was being called, the range of dividers would not be set,
> resulting in a division by zero later on in the clk_round_rate logic.
> 
> Set the range of dividers before calling clk_round_rate to fix this.
> 
> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
Tested-by: Giulio Benetti <giulio.benetti@micronovasrl.com>

Before crtc couldn't be added because of min=0 and max=0.
Now they're initiliazed and crtc is added correctly.
> ---
>   drivers/gpu/drm/sun4i/sun4i_rgb.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpu/drm/sun4i/sun4i_rgb.c b/drivers/gpu/drm/sun4i/sun4i_rgb.c
> index 832f8f9bc47f..b8da5a50a61d 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_rgb.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_rgb.c
> @@ -92,6 +92,8 @@ static int sun4i_rgb_mode_valid(struct drm_connector *connector,
>   
>   	DRM_DEBUG_DRIVER("Vertical parameters OK\n");
>   
> +	tcon->dclk_min_div = 6;
> +	tcon->dclk_max_div = 127;
>   	rounded_rate = clk_round_rate(tcon->dclk, rate);
>   	if (rounded_rate < rate)
>   		return MODE_CLOCK_LOW;
>
Chen-Yu Tsai March 6, 2018, 7:42 a.m. UTC | #2
On Wed, Feb 21, 2018 at 8:57 PM, Maxime Ripard
<maxime.ripard@bootlin.com> wrote:
> In the case where mode_valid callback of our RGB connector was called
> before mode_set was being called, the range of dividers would not be set,
> resulting in a division by zero later on in the clk_round_rate logic.
>
> Set the range of dividers before calling clk_round_rate to fix this.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
diff mbox

Patch

diff --git a/drivers/gpu/drm/sun4i/sun4i_rgb.c b/drivers/gpu/drm/sun4i/sun4i_rgb.c
index 832f8f9bc47f..b8da5a50a61d 100644
--- a/drivers/gpu/drm/sun4i/sun4i_rgb.c
+++ b/drivers/gpu/drm/sun4i/sun4i_rgb.c
@@ -92,6 +92,8 @@  static int sun4i_rgb_mode_valid(struct drm_connector *connector,
 
 	DRM_DEBUG_DRIVER("Vertical parameters OK\n");
 
+	tcon->dclk_min_div = 6;
+	tcon->dclk_max_div = 127;
 	rounded_rate = clk_round_rate(tcon->dclk, rate);
 	if (rounded_rate < rate)
 		return MODE_CLOCK_LOW;