All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Turquette <mturquette@baylibre.com>
To: Rob Herring <robh+dt@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Daniel Vetter <daniel.vetter@intel.com>,
	David Airlie <airlied@linux.ie>
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Maxime Ripard <maxime.ripard@free-electrons.com>,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 02/20] clk: multiplier: Prevent the multiplier from under / over flowing
Date: Mon, 20 Jun 2016 13:50:30 -0700	[thread overview]
Message-ID: <20160620205030.24587.98159@quark.deferred.io> (raw)
In-Reply-To: <1463402840-17062-3-git-send-email-maxime.ripard@free-electrons.com>

Quoting Maxime Ripard (2016-05-16 05:47:02)
> In the current multiplier base clock implementation, if the
> CLK_SET_RATE_PARENT flag isn't set, the code will not make sure that the
> multiplier computed remains within the boundaries of our clock.
> 
> This means that if the clock we want to reach is below the parent rate,
> or if the multiplier is above the maximum that we can reach, we will end up
> with a completely bogus one that the clock cannot achieve.
> 
> Fixes: f2e0a53271a4 ("clk: Add a basic multiplier clock")
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Applied.

Regards,
Mike

> ---
>  drivers/clk/clk-multiplier.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/clk-multiplier.c b/drivers/clk/clk-multiplier.c
> index 9e449c7b751c..dc037c957acd 100644
> --- a/drivers/clk/clk-multiplier.c
> +++ b/drivers/clk/clk-multiplier.c
> @@ -52,14 +52,28 @@ static unsigned long __bestmult(struct clk_hw *hw, unsigned long rate,
>                                 unsigned long *best_parent_rate,
>                                 u8 width, unsigned long flags)
>  {
> +       struct clk_multiplier *mult = to_clk_multiplier(hw);
>         unsigned long orig_parent_rate = *best_parent_rate;
>         unsigned long parent_rate, current_rate, best_rate = ~0;
>         unsigned int i, bestmult = 0;
> +       unsigned int maxmult = (1 << width) - 1;
> +
> +       if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) {
> +               bestmult = rate / orig_parent_rate;
> +
> +               /* Make sure we don't end up with a 0 multiplier */
> +               if ((bestmult == 0) &&
> +                   !(mult->flags & CLK_MULTIPLIER_ZERO_BYPASS))
> +                       bestmult = 1;
>  
> -       if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT))
> -               return rate / *best_parent_rate;
> +               /* Make sure we don't overflow the multiplier */
> +               if (bestmult > maxmult)
> +                       bestmult = maxmult;
> +
> +               return bestmult;
> +       }
>  
> -       for (i = 1; i < ((1 << width) - 1); i++) {
> +       for (i = 1; i < maxmult; i++) {
>                 if (rate == orig_parent_rate * i) {
>                         /*
>                          * This is the best case for us if we have a
> -- 
> 2.8.2
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Michael Turquette <mturquette@baylibre.com>
To: Maxime Ripard <maxime.ripard@free-electrons.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Chen-Yu Tsai" <wens@csie.org>,
	"Stephen Boyd" <sboyd@codeaurora.org>,
	"Daniel Vetter" <daniel.vetter@intel.com>,
	"David Airlie" <airlied@linux.ie>
Cc: "Boris Brezillon" <boris.brezillon@free-electrons.com>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
	dri-devel@lists.freedesktop.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-clk@vger.kernel.org,
	"Maxime Ripard" <maxime.ripard@free-electrons.com>
Subject: Re: [PATCH 02/20] clk: multiplier: Prevent the multiplier from under / over flowing
Date: Mon, 20 Jun 2016 13:50:30 -0700	[thread overview]
Message-ID: <20160620205030.24587.98159@quark.deferred.io> (raw)
In-Reply-To: <1463402840-17062-3-git-send-email-maxime.ripard@free-electrons.com>

Quoting Maxime Ripard (2016-05-16 05:47:02)
> In the current multiplier base clock implementation, if the
> CLK_SET_RATE_PARENT flag isn't set, the code will not make sure that the
> multiplier computed remains within the boundaries of our clock.
> =

> This means that if the clock we want to reach is below the parent rate,
> or if the multiplier is above the maximum that we can reach, we will end =
up
> with a completely bogus one that the clock cannot achieve.
> =

> Fixes: f2e0a53271a4 ("clk: Add a basic multiplier clock")
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Applied.

Regards,
Mike

> ---
>  drivers/clk/clk-multiplier.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> =

> diff --git a/drivers/clk/clk-multiplier.c b/drivers/clk/clk-multiplier.c
> index 9e449c7b751c..dc037c957acd 100644
> --- a/drivers/clk/clk-multiplier.c
> +++ b/drivers/clk/clk-multiplier.c
> @@ -52,14 +52,28 @@ static unsigned long __bestmult(struct clk_hw *hw, un=
signed long rate,
>                                 unsigned long *best_parent_rate,
>                                 u8 width, unsigned long flags)
>  {
> +       struct clk_multiplier *mult =3D to_clk_multiplier(hw);
>         unsigned long orig_parent_rate =3D *best_parent_rate;
>         unsigned long parent_rate, current_rate, best_rate =3D ~0;
>         unsigned int i, bestmult =3D 0;
> +       unsigned int maxmult =3D (1 << width) - 1;
> +
> +       if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) {
> +               bestmult =3D rate / orig_parent_rate;
> +
> +               /* Make sure we don't end up with a 0 multiplier */
> +               if ((bestmult =3D=3D 0) &&
> +                   !(mult->flags & CLK_MULTIPLIER_ZERO_BYPASS))
> +                       bestmult =3D 1;
>  =

> -       if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT))
> -               return rate / *best_parent_rate;
> +               /* Make sure we don't overflow the multiplier */
> +               if (bestmult > maxmult)
> +                       bestmult =3D maxmult;
> +
> +               return bestmult;
> +       }
>  =

> -       for (i =3D 1; i < ((1 << width) - 1); i++) {
> +       for (i =3D 1; i < maxmult; i++) {
>                 if (rate =3D=3D orig_parent_rate * i) {
>                         /*
>                          * This is the best case for us if we have a
> -- =

> 2.8.2
>=20

WARNING: multiple messages have this Message-ID (diff)
From: mturquette@baylibre.com (Michael Turquette)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 02/20] clk: multiplier: Prevent the multiplier from under / over flowing
Date: Mon, 20 Jun 2016 13:50:30 -0700	[thread overview]
Message-ID: <20160620205030.24587.98159@quark.deferred.io> (raw)
In-Reply-To: <1463402840-17062-3-git-send-email-maxime.ripard@free-electrons.com>

Quoting Maxime Ripard (2016-05-16 05:47:02)
> In the current multiplier base clock implementation, if the
> CLK_SET_RATE_PARENT flag isn't set, the code will not make sure that the
> multiplier computed remains within the boundaries of our clock.
> 
> This means that if the clock we want to reach is below the parent rate,
> or if the multiplier is above the maximum that we can reach, we will end up
> with a completely bogus one that the clock cannot achieve.
> 
> Fixes: f2e0a53271a4 ("clk: Add a basic multiplier clock")
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Applied.

Regards,
Mike

> ---
>  drivers/clk/clk-multiplier.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/clk-multiplier.c b/drivers/clk/clk-multiplier.c
> index 9e449c7b751c..dc037c957acd 100644
> --- a/drivers/clk/clk-multiplier.c
> +++ b/drivers/clk/clk-multiplier.c
> @@ -52,14 +52,28 @@ static unsigned long __bestmult(struct clk_hw *hw, unsigned long rate,
>                                 unsigned long *best_parent_rate,
>                                 u8 width, unsigned long flags)
>  {
> +       struct clk_multiplier *mult = to_clk_multiplier(hw);
>         unsigned long orig_parent_rate = *best_parent_rate;
>         unsigned long parent_rate, current_rate, best_rate = ~0;
>         unsigned int i, bestmult = 0;
> +       unsigned int maxmult = (1 << width) - 1;
> +
> +       if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) {
> +               bestmult = rate / orig_parent_rate;
> +
> +               /* Make sure we don't end up with a 0 multiplier */
> +               if ((bestmult == 0) &&
> +                   !(mult->flags & CLK_MULTIPLIER_ZERO_BYPASS))
> +                       bestmult = 1;
>  
> -       if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT))
> -               return rate / *best_parent_rate;
> +               /* Make sure we don't overflow the multiplier */
> +               if (bestmult > maxmult)
> +                       bestmult = maxmult;
> +
> +               return bestmult;
> +       }
>  
> -       for (i = 1; i < ((1 << width) - 1); i++) {
> +       for (i = 1; i < maxmult; i++) {
>                 if (rate == orig_parent_rate * i) {
>                         /*
>                          * This is the best case for us if we have a
> -- 
> 2.8.2
> 

  parent reply	other threads:[~2016-06-20 20:50 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-16 12:47 [PATCH 00/20] drm: Add Support for Passive RGB to VGA bridges Maxime Ripard
2016-05-16 12:47 ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 01/20] clk: fixed-factor: Pass clk rates change to the parent Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-06-10 12:30   ` Maxime Ripard
2016-06-10 12:30     ` Maxime Ripard
     [not found]   ` <1463402840-17062-2-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-17 23:05     ` Michael Turquette
2016-06-17 23:05       ` Michael Turquette
2016-06-17 23:05       ` Michael Turquette
2016-06-20  8:54       ` Maxime Ripard
2016-06-20  8:54         ` Maxime Ripard
2016-06-20  8:54         ` Maxime Ripard
2016-06-20 19:57         ` Michael Turquette
2016-06-20 19:57           ` Michael Turquette
2016-06-20 19:57           ` Michael Turquette
2016-05-16 12:47 ` [PATCH 03/20] clk: sunxi: tcon-ch1: Do not return a negative error in get_parent Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 16:05   ` Chen-Yu Tsai
2016-05-16 16:05     ` Chen-Yu Tsai
2016-06-10  9:50     ` Maxime Ripard
2016-06-10  9:50       ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 04/20] clk: sunxi: display: Add per-clock flags Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 15:21   ` Chen-Yu Tsai
2016-05-16 15:21     ` Chen-Yu Tsai
2016-06-10  9:50     ` Maxime Ripard
2016-06-10  9:50       ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 05/20] drm/sun4i: request exact rates to our parents Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 06/20] drm/sun4i: allow dclk to modify its parent rate Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 17:18   ` Chen-Yu Tsai
2016-05-16 17:18     ` Chen-Yu Tsai
2016-05-25 12:01     ` Maxime Ripard
2016-05-25 12:01       ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 07/20] drm/sun4i: rgb: Validate the clock rate Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 08/20] drm/sun4i: rgb: panel is an error pointer Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-17  3:51   ` Chen-Yu Tsai
2016-05-17  3:51     ` Chen-Yu Tsai
2016-05-25 12:06     ` Maxime Ripard
2016-05-25 12:06       ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 09/20] drm/sun4i: defer only if we didn't find our panel Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
     [not found]   ` <1463402840-17062-10-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-05-17  3:52     ` Chen-Yu Tsai
2016-05-17  3:52       ` Chen-Yu Tsai
2016-05-17  3:52       ` Chen-Yu Tsai
2016-05-25 12:09       ` Maxime Ripard
2016-05-25 12:09         ` Maxime Ripard
2016-05-25 12:09         ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 10/20] drm/sun4i: remove simplefb at probe Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 11/20] drm/sun4i: Convert to connector register helpers Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 12/20] drm/sun4i: Add bridge support Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 13:12   ` Daniel Vetter
2016-05-16 13:12     ` Daniel Vetter
2016-05-25 16:29     ` Maxime Ripard
2016-05-25 16:29       ` Maxime Ripard
2016-05-25 16:29       ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 13/20] drm/bridge: Add RGB to VGA " Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 13:24   ` Laurent Pinchart
2016-05-16 13:24     ` Laurent Pinchart
2016-05-16 13:24     ` Laurent Pinchart
2016-05-26  8:53     ` Maxime Ripard
2016-05-26  8:53       ` Maxime Ripard
2016-05-26  9:16       ` Russell King - ARM Linux
2016-05-26  9:16         ` Russell King - ARM Linux
2016-05-16 14:07   ` Rob Herring
2016-05-16 14:07     ` Rob Herring
2016-05-16 14:07     ` Rob Herring
2016-05-26  9:38     ` Maxime Ripard
2016-05-26  9:38       ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 14/20] ARM: sun5i: a13: Add LCD pins Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 17:13   ` Chen-Yu Tsai
2016-05-16 17:13     ` Chen-Yu Tsai
2016-05-25 12:33     ` Maxime Ripard
2016-05-25 12:33       ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 16/20] ARM: sun5i: a13-olinuxino: Enable VGA bridge Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-16 12:47 ` [PATCH 17/20] ARM: multi_v7: Enable sun4i DRM driver Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
2016-05-17  3:36   ` Chen-Yu Tsai
2016-05-17  3:36     ` Chen-Yu Tsai
2016-05-16 12:47 ` [PATCH 18/20] ARM: multi_v7: enable VGA bridge Maxime Ripard
2016-05-16 12:47   ` Maxime Ripard
     [not found] ` <1463402840-17062-1-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-05-16 12:47   ` [PATCH 02/20] clk: multiplier: Prevent the multiplier from under / over flowing Maxime Ripard
2016-05-16 12:47     ` Maxime Ripard
2016-05-16 12:47     ` Maxime Ripard
2016-06-10 12:31     ` Maxime Ripard
2016-06-10 12:31       ` Maxime Ripard
2016-06-20 20:50     ` Michael Turquette [this message]
2016-06-20 20:50       ` Michael Turquette
2016-06-20 20:50       ` Michael Turquette
2016-06-21  9:20       ` Maxime Ripard
2016-06-21  9:20         ` Maxime Ripard
2016-06-21  9:20         ` Maxime Ripard
2016-05-16 12:47   ` [PATCH 15/20] ARM: sun5i: Move display blocks to A13 Maxime Ripard
2016-05-16 12:47     ` Maxime Ripard
2016-05-16 12:47     ` Maxime Ripard
2016-05-16 12:47   ` [PATCH 19/20] ARM: sunxi: Enable sun4i DRM driver Maxime Ripard
2016-05-16 12:47     ` Maxime Ripard
2016-05-16 12:47     ` Maxime Ripard
2016-05-16 15:01     ` Chen-Yu Tsai
2016-05-16 15:01       ` Chen-Yu Tsai
2016-05-16 12:47   ` [PATCH 20/20] ARM: sunxi: Enable VGA bridge Maxime Ripard
2016-05-16 12:47     ` Maxime Ripard
2016-05-16 12:47     ` Maxime Ripard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160620205030.24587.98159@quark.deferred.io \
    --to=mturquette@baylibre.com \
    --cc=airlied@linux.ie \
    --cc=daniel.vetter@intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=maxime.ripard@free-electrons.com \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@codeaurora.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.