Re: [PATCH] printf: Emit "SUCCESS" if NULL is passed for %pe

From: Petr Mladek
Date: Fri Sep 30 2022 - 08:14:25 EST


On Fri 2022-09-30 13:10:50, Uwe Kleine-König wrote:
> For code that emits a string representing a usual return value it's
> convenient to have a 0 result in a string representation of success
> instead of "00000000".

Does it really always mean success, please?

IMHO, if a function returns a pointer then typically only a valid
pointer means success. Error code means some reasonable explanation
of the failure. And NULL should never happen.

For example:

struct bla *find_bla(int key)
{
struct bla *b;

/* Try to get bla using the given key */
...

if (succeded)
return b;

/* Did not find bla for the given key */
return -EINVAL;

}

It might be used:

int process_bla()
{
struct bla *b;

b = get_bla();
if (IS_ERR(b))
return PTR_ERR(b);

/* do something with b */
...
}

If get_bla() returns NULL then it means a super fault. It means
that get_bla() failed and did not know why.

IMHO, this patch might do more harm than good.

Best Regards,
Petr