[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-doc
Subject:    Re: [PATCH 3/3] lib/vsprintf: Add %pC{,n,r} format specifiers for clocks
From:       Geert Uytterhoeven <geert () linux-m68k ! org>
Date:       2015-02-28 14:56:45
Message-ID: CAMuHMdXogR3+usv9BqsF7sa53Y-Pz2ZmsdfFX3Th-YeyEx5B9w () mail ! gmail ! com
[Download RAW message or body]

Hi Andrew,

On Fri, Feb 27, 2015 at 11:18 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Thu, 26 Feb 2015 12:13:03 +0100 Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
>> From: Geert Uytterhoeven <geert+renesas@glider.be>
>>
>> Add format specifiers for printing struct clk:
>>   - '%pC' or '%pCn': name (Common Clock Framework) or address (legacy
>>     clock framework) of the clock,
>>   - '%pCr': rate of the clock.
>>
>> ...
>>
>> +static noinline_for_stack
>> +char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
>> +         const char *fmt)
>> +{
>> +     if (!clk)
>> +             return string(buf, end, NULL, spec);
>> +
>> +     switch (fmt[1]) {
>> +     case 'r':
>> +             return number(buf, end, clk_get_rate(clk), spec);
>> +
>> +     case 'n':
>> +     default:
>> +#ifdef CONFIG_COMMON_CLK
>> +             return string(buf, end, __clk_get_name(clk), spec);
>> +#else
>> +             spec.base = 16;
>> +             spec.field_width = sizeof(unsigned long) * 2 + 2;
>> +             spec.flags |= SPECIAL | SMALL | ZEROPAD;
>> +             return number(buf, end, (unsigned long)clk, spec);
>> +#endif
>> +     }
>> +}
>
> Seems a bit cruel to teeny systems which don't implement clock.  How does
> this look?  Saves 160 bytes in each powerpc build!

> diff -puN lib/vsprintf.c~lib-vsprintf-add-%pcnr-format-specifiers-for-clocks-fix lib/vsprintf.c
> --- a/lib/vsprintf.c~lib-vsprintf-add-%pcnr-format-specifiers-for-clocks-fix
> +++ a/lib/vsprintf.c
> @@ -1320,24 +1320,27 @@ static noinline_for_stack
>  char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
>             const char *fmt)
>  {
> -       if (!clk)
> -               return string(buf, end, NULL, spec);
> +#ifdef CONFIG_HAVE_CLK
> +       if (clk) {

On second thought, you can achieve the same result without #ifdef
with this 2-line change:

-       if (!clk)
+       if (!IS_ENABLED(CONFIG_HAVE_CLK) || !clk)

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
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic