Re: [PATCH v4 0/1] printf: add support for printing symbolic error names

From: Petr Mladek
Date: Wed Nov 27 2019 - 03:54:55 EST


On Tue 2019-11-26 15:04:06, Geert Uytterhoeven wrote:
> Hi Rasmus,
>
> Nice idea!
>
> On Fri, Oct 11, 2019 at 3:38 PM Rasmus Villemoes
> <linux@xxxxxxxxxxxxxxxxxx> wrote:
> > This is a bit much for under the ---, so a separate cover letter for
> > this single patch.
> >
> > v4: Dropped Uwe's ack since it's changed quite a bit. Change
> > errcode->errname as suggested by Petr. Make it 'default y if PRINTK'
> > so it's available in the common case, while those who have gone to
> > great lengths to shave their kernel to the bare minimum are not
> > affected.
> >
> > Also require the caller to use %pe instead of printing all ERR_PTRs
> > symbolically. I can see some value in having the call site explicitly
> > indicate that they're printing an ERR_PTR (i.e., having the %pe), but
> > I also still believe it would make sense to print ordinary %p,
> > ERR_PTR() symbolically instead of as a random hash value that's not
> > stable across reboots. But in the interest of getting this in, I'll
> > leave that for now. It's easy enough to do later by just changing the
> > "case 'e'" to do a break (with an updated comment), then do an
> > IS_ERR() check after the switch.
> >
> > Something I've glossed over in previous versions, and nobody has
> > commented on, is that I produced "ENOSPC" while the 'fallback' would
> > print "-28" (i.e., there's no minus in the symbolic case). I don't
> > care much either way, but here I've tried to show how I'd do it if we
> > want the minus also in the symbolic case. At first, I tried just using
> > the standard idiom
> >
> > if (buf < end)
> > *buf = '-';
> > buf++;
> >
> > followed by string(sym, ...). However, that doesn't work very well if
> > one wants to honour field width - for that to work, the whole string
> > including - must come from the errname() lookup and be handled by
> > string(). The simplest seemed to be to just unconditionally prefix all
> > strings with "-" when building the tables, and then change errname()
> > back to supporting both positive and negative error numbers.
>
> Still, it looks a bit wasteful to me to include the dash in each and every
> string value.
>
> Do you think you can code the +/- logic in string_nocheck() in less than
> the gain achieved by dropping the dashes from the tables?
> (e.g. by using the SIGN spec.flags? ;-)
> Or, do we need it? IS_ERR() doesn't consider positive values errors.
>
> Oh, what about the leading "E"? That one looks harder to get rid of,
> though ;-)

It would be nice. But too big hack is not worth it. Anybody who cares
about saving 0.2kB would likely disable this feature completely.

Feel to provide a patch so that we could see how good/bad it is.

Best Regards,
Petr