linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gabriel L. Somlo" <gsomlo@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"robh+dt@kernel.org" <robh+dt@kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"ulf.hansson@linaro.org" <ulf.hansson@linaro.org>,
	"linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>,
	"kgugala@antmicro.com" <kgugala@antmicro.com>,
	"mholenko@antmicro.com" <mholenko@antmicro.com>,
	"krakoczy@antmicro.com" <krakoczy@antmicro.com>,
	"mdudek@internships.antmicro.com"
	<mdudek@internships.antmicro.com>,
	"paulus@ozlabs.org" <paulus@ozlabs.org>,
	"joel@jms.id.au" <joel@jms.id.au>,
	"shorne@gmail.com" <shorne@gmail.com>,
	"geert@linux-m68k.org" <geert@linux-m68k.org>,
	"david.abdurachmanov@sifive.com" <david.abdurachmanov@sifive.com>,
	"florent@enjoy-digital.fr" <florent@enjoy-digital.fr>,
	"rdunlap@infradead.org" <rdunlap@infradead.org>
Subject: Re: [PATCH v8 3/3] mmc: Add driver for LiteX's LiteSDCard interface
Date: Sat, 8 Jan 2022 08:20:06 -0500	[thread overview]
Message-ID: <YdmPho2GpVcvWUgU@errol.ini.cmu.edu> (raw)
In-Reply-To: <CAHp75Vf7o1g0FTAd+Zo6TMzDN3C2nGLhbDo0OJ9Cmwcxm=Kc8Q@mail.gmail.com>

On Sat, Jan 08, 2022 at 01:26:08PM +0200, Andy Shevchenko wrote:
> On Sat, Jan 8, 2022 at 3:57 AM Gabriel L. Somlo <gsomlo@gmail.com> wrote:
> > On Sat, Jan 08, 2022 at 01:54:07AM +0200, Andy Shevchenko wrote:
> > > On Saturday, January 8, 2022, Gabriel Somlo <gsomlo@gmail.com> wrote:
> 
> > >     +       u32 div;
> > >     +
> > >     +       div = freq ? host->ref_clk / freq : 256U;
> > >
> > >     +       div = roundup_pow_of_two(div);
> > >     +       div = clamp(div, 2U, 256U);
> > >
> > > Logically seems to me that you may join these two together, because clamped
> > > range is power-of-2 one.
> >
> > `div` needs to be a power-of-2 when written to the LITEX_PHY_CLOCKERDIV
> > register (below). And clamp() will just enforce a min/max range, so if
> > (div = ref_clk / freq) ends up e.g., 5, I need both roundup_pow_of_two()
> > to bump it to 8, and clamp() to enforce that it's between 2 and 256.
> >
> > Unless you mean I should simply write it like:
> >
> >         div = clamp(roundup_pow_of_two(div), 2U, 256U);
> >
> > ... as a single line?
> 
> Yes, that's what I meant.

Turns out, clamp really hates being passed roundup_pow_of_two()
directly (see below). I think it's probably better if we leave
them as-is, to avoid going the explicit cast route which Geert
recommended against.

I'll send out v9 later today with everything else, including
devm_add_action_or_reset().

Thanks,
--Gabriel

drivers/mmc/host/litex_mmc.c: In function 'litex_mmc_setclk':
./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast
   20 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
      |                                   ^~
./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                  ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
   45 | #define min(x, y)       __careful_cmp(x, y, <)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:28: note: in expansion of macro 'min'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                            ^~~
./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                  ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:52:25: note: in expansion of macro '__careful_cmp'
   52 | #define max(x, y)       __careful_cmp(x, y, >)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:45: note: in expansion of macro 'max'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                                             ^~~
drivers/mmc/host/litex_mmc.c:448:15: note: in expansion of macro 'clamp'
  448 |         div = clamp(roundup_pow_of_two(div), 2U, 256U);
      |               ^~~~~
./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast
   20 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
      |                                   ^~
./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                  ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
   45 | #define min(x, y)       __careful_cmp(x, y, <)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:28: note: in expansion of macro 'min'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                            ^~~
drivers/mmc/host/litex_mmc.c:448:15: note: in expansion of macro 'clamp'
  448 |         div = clamp(roundup_pow_of_two(div), 2U, 256U);
      |               ^~~~~
In file included from ./include/linux/bits.h:5,
                 from drivers/mmc/host/litex_mmc.c:12:
./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast
   20 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
      |                                   ^~
./include/linux/const.h:12:55: note: in definition of macro '__is_constexpr'
   12 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
      |                                                       ^
./include/linux/minmax.h:26:39: note: in expansion of macro '__no_side_effects'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                                       ^~~~~~~~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
   45 | #define min(x, y)       __careful_cmp(x, y, <)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:28: note: in expansion of macro 'min'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                            ^~~
./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                  ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:52:25: note: in expansion of macro '__careful_cmp'
   52 | #define max(x, y)       __careful_cmp(x, y, >)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:45: note: in expansion of macro 'max'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                                             ^~~
drivers/mmc/host/litex_mmc.c:448:15: note: in expansion of macro 'clamp'
  448 |         div = clamp(roundup_pow_of_two(div), 2U, 256U);
      |               ^~~~~
In file included from ./include/linux/kernel.h:17,
                 from ./include/linux/clk.h:13,
                 from drivers/mmc/host/litex_mmc.c:13:
./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast
   20 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
      |                                   ^~
./include/linux/minmax.h:28:27: note: in definition of macro '__cmp'
   28 | #define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
      |                           ^
./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
   45 | #define min(x, y)       __careful_cmp(x, y, <)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:28: note: in expansion of macro 'min'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                            ^~~
./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                  ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:52:25: note: in expansion of macro '__careful_cmp'
   52 | #define max(x, y)       __careful_cmp(x, y, >)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:45: note: in expansion of macro 'max'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                                             ^~~
drivers/mmc/host/litex_mmc.c:448:15: note: in expansion of macro 'clamp'
  448 |         div = clamp(roundup_pow_of_two(div), 2U, 256U);
      |               ^~~~~
./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast
   20 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
      |                                   ^~
./include/linux/minmax.h:28:40: note: in definition of macro '__cmp'
   28 | #define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
      |                                        ^
./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
   45 | #define min(x, y)       __careful_cmp(x, y, <)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:28: note: in expansion of macro 'min'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                            ^~~
./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                  ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:52:25: note: in expansion of macro '__careful_cmp'
   52 | #define max(x, y)       __careful_cmp(x, y, >)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:45: note: in expansion of macro 'max'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                                             ^~~
drivers/mmc/host/litex_mmc.c:448:15: note: in expansion of macro 'clamp'
  448 |         div = clamp(roundup_pow_of_two(div), 2U, 256U);
      |               ^~~~~
./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast
   20 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
      |                                   ^~
./include/linux/minmax.h:31:24: note: in definition of macro '__cmp_once'
   31 |                 typeof(x) unique_x = (x);               \
      |                        ^
./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
   45 | #define min(x, y)       __careful_cmp(x, y, <)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:28: note: in expansion of macro 'min'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                            ^~~
./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                  ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:52:25: note: in expansion of macro '__careful_cmp'
   52 | #define max(x, y)       __careful_cmp(x, y, >)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:45: note: in expansion of macro 'max'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                                             ^~~
drivers/mmc/host/litex_mmc.c:448:15: note: in expansion of macro 'clamp'
  448 |         div = clamp(roundup_pow_of_two(div), 2U, 256U);
      |               ^~~~~
./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast
   20 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
      |                                   ^~
./include/linux/minmax.h:31:39: note: in definition of macro '__cmp_once'
   31 |                 typeof(x) unique_x = (x);               \
      |                                       ^
./include/linux/minmax.h:45:25: note: in expansion of macro '__careful_cmp'
   45 | #define min(x, y)       __careful_cmp(x, y, <)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:28: note: in expansion of macro 'min'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                            ^~~
./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck'
   26 |                 (__typecheck(x, y) && __no_side_effects(x, y))
      |                  ^~~~~~~~~~~
./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp'
   36 |         __builtin_choose_expr(__safe_cmp(x, y), \
      |                               ^~~~~~~~~~
./include/linux/minmax.h:52:25: note: in expansion of macro '__careful_cmp'
   52 | #define max(x, y)       __careful_cmp(x, y, >)
      |                         ^~~~~~~~~~~~~
./include/linux/minmax.h:89:45: note: in expansion of macro 'max'
   89 | #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
      |                                             ^~~
drivers/mmc/host/litex_mmc.c:448:15: note: in expansion of macro 'clamp'
  448 |         div = clamp(roundup_pow_of_two(div), 2U, 256U);
      |               ^~~~~


  reply	other threads:[~2022-01-08 13:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07 23:34 [PATCH v8 0/3] mmc: Add LiteSDCard mmc driver Gabriel Somlo
2022-01-07 23:34 ` [PATCH v8 1/3] MAINTAINERS: co-maintain LiteX platform Gabriel Somlo
2022-01-07 23:34 ` [PATCH v8 2/3] dt-bindings: mmc: Add bindings for LiteSDCard Gabriel Somlo
2022-01-07 23:34 ` [PATCH v8 3/3] mmc: Add driver for LiteX's LiteSDCard interface Gabriel Somlo
     [not found]   ` <CAHp75VcHnHpX1=ojmFnujqkf55aS1ePiVW4kKydTJQe=dXbwbQ@mail.gmail.com>
2022-01-08  1:57     ` Gabriel L. Somlo
2022-01-08  2:31       ` Gabriel L. Somlo
2022-01-08 11:29         ` Andy Shevchenko
2022-01-08 11:26       ` Andy Shevchenko
2022-01-08 13:20         ` Gabriel L. Somlo [this message]
2022-01-08 17:47           ` Andy Shevchenko
2022-01-08 23:51             ` Gabriel L. Somlo
2022-01-09 11:36               ` Andy Shevchenko

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=YdmPho2GpVcvWUgU@errol.ini.cmu.edu \
    --to=gsomlo@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=david.abdurachmanov@sifive.com \
    --cc=devicetree@vger.kernel.org \
    --cc=florent@enjoy-digital.fr \
    --cc=geert@linux-m68k.org \
    --cc=joel@jms.id.au \
    --cc=kgugala@antmicro.com \
    --cc=krakoczy@antmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=mdudek@internships.antmicro.com \
    --cc=mholenko@antmicro.com \
    --cc=paulus@ozlabs.org \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=shorne@gmail.com \
    --cc=ulf.hansson@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).