public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-kernel@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH] printf: Emit "SUCCESS" if NULL is passed for %pe
Date: Fri, 30 Sep 2022 14:14:16 +0200	[thread overview]
Message-ID: <YzbdmJvcPiYAIalt@alley> (raw)
In-Reply-To: <20220930111050.1296018-1-u.kleine-koenig@pengutronix.de>

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

  reply	other threads:[~2022-09-30 12:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 11:10 [PATCH] printf: Emit "SUCCESS" if NULL is passed for %pe Uwe Kleine-König
2022-09-30 12:14 ` Petr Mladek [this message]
2022-09-30 13:24   ` Uwe Kleine-König
2022-09-30 13:42     ` Andy Shevchenko
2022-09-30 13:48       ` Uwe Kleine-König
2022-09-30 13:41 ` Andy Shevchenko
2022-09-30 14:05   ` Uwe Kleine-König
2022-10-03 13:26     ` Petr Mladek

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=YzbdmJvcPiYAIalt@alley \
    --to=pmladek@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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