Re: [PATCH v2] vsprintf: introduce %dE for error constants
From: Petr Mladek
Date: Fri Aug 30 2019 - 05:06:33 EST
On Thu 2019-08-29 19:39:45, Uwe Kleine-König wrote:
> On 8/29/19 11:09 AM, Rasmus Villemoes wrote:
> > On 29/08/2019 10.27, Juergen Gross wrote:
> >> On 29.08.19 10:12, Petr Mladek wrote:
> >>> On Wed 2019-08-28 21:18:37, Uwe Kleine-König wrote:
> >>>>
> >>>> I'd like to postpone the discussion about "how" until we agreed about
> >>>> the "if at all".
> >>>
> >>> It seems that all people like this feature.
> >>
> >> Hmm, what about already existing format strings conatining "%dE"?
> >>
> >> Yes, I could find only one (drivers/staging/speakup/speakup_bns.c), but
> >> nevertheless...
> >
> > Indeed, Uwe still needs to respond to how he wants to handle that. I
>
> This is indeed bad and I didn't expect that. I just took a quick look
> and this string is indeed used as sprintf format string.
Hmm, it seems that solving this might be pretty tricky.
I see this as a warning that we should not play with fire.
There might be a reason why all format modifiers are put
between % and the format identifier.
> > still prefer making it %pE, both because it's easier to convert integers
> > to ERR_PTRs than having to worry about the type of PTR_ERR() being long
> > and not int, and because alphanumerics after %p have been ignored for a
> > long time (10 years?) whether or not those characters have been
> > recognized as a %p extension, so nobody relies on %pE putting an E after
> > the %p output. It also keeps the non-standard extensions in the same
> > "namespace", so to speak.
>
> > Oh, 'E' is taken, well, make it 'e' then.
>
> I like having %pe to print error valued pointers. Then maybe we could
> have both %de for ints and %pe for pointers. :-)
I would prefer to avoid %pe. It would make sense only when the value
really contains error id. It means that it has to be used as:
if (IS_ERR(p)) {
pr_warn(...);
The error path might handle the error using PTR_ERR() also
on other locations. Also PTR_ERR() will make it clear that we
are trying to print the error code.
Best Regards,
Petr