All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: Wolfgang Denk <wd@denx.de>
Cc: u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>,
	Stefan Roese <sr@denx.de>, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH v6 10/12] watchdog: add gpio watchdog driver
Date: Fri, 20 Aug 2021 08:22:20 +0200	[thread overview]
Message-ID: <5cceb902-a4c1-d714-1685-2d4a9667e33c@prevas.dk> (raw)
In-Reply-To: <61767.1629376321@gemini.denx.de>

On 19/08/2021 14.32, Wolfgang Denk wrote:

> The existence of bad code is not a justification to add more of it.

Obviously true and I agree.

However, it is at the same time completely irrelevant in this context,
because the pattern of using the return value of dev_get_priv() without
a NULL check is neither bad or wrong, as has now been explained to you
several times.

If you really think checking the return value of dev_get_priv() must be
done religiously, perhaps you could tap Stefan (737c3de09984), Marek
(7e1f1e16fe75), or Heiko (6e31c62a175c) on the shoulder and tell them to
stop cranking out "bad" code.

On 19/08/2021 16.16, Wolfgang Denk wrote:

> I mean, look at the implementation of dev_get_priv():
>
>  628 void *dev_get_priv(const struct udevice *dev)
>  629 {
>  630         if (!dev) {
>  631                 dm_warn("%s: null device\n", __func__);
>  632                 return NULL;
>  633         }
>  634
>  635         return dm_priv_to_rw(dev->priv_);
>  636 }
>
> If there is guaranteed no way that dev_get_priv() can return a NULL
> pointer, that means that it must be guaranteed that the "dev"
> argument can never be a NULL pointer, either.

There's another logical fallacy right here. Sure, you've found an input
value for which dev_get_priv() would return NULL. But any caller who
knows they're not passing a NULL dev also know they won't follow that
code path.

A driver which doesn't populate the priv field by via a non-zero
.priv_auto field may need to check the return value of dev_get_priv().
I'm not claiming that checking that is always redundant. However,
neither is it anywhere near true that checking is always required.

Rasmus

  parent reply	other threads:[~2021-08-20  6:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19  9:56 [PATCH v6 00/12] handling all DM watchdogs in watchdog_reset() Rasmus Villemoes
2021-08-19  9:56 ` [PATCH v6 01/12] watchdog: wdt-uclass.c: use wdt_start() in wdt_expire_now() Rasmus Villemoes
2021-08-19  9:56 ` [PATCH v6 02/12] watchdog: wdt-uclass.c: introduce struct wdt_priv Rasmus Villemoes
2021-08-19  9:56 ` [PATCH v6 03/12] watchdog: wdt-uclass.c: neaten UCLASS_DRIVER definition Rasmus Villemoes
2021-08-19  9:56 ` [PATCH v6 04/12] watchdog: wdt-uclass.c: refactor initr_watchdog() Rasmus Villemoes
2021-08-19  9:56 ` [PATCH v6 05/12] watchdog: wdt-uclass.c: keep track of each device's running state Rasmus Villemoes
2021-08-19 11:35   ` Wolfgang Denk
2021-08-19  9:57 ` [PATCH v6 06/12] sandbox: disable CONFIG_WATCHDOG_AUTOSTART Rasmus Villemoes
2021-08-19  9:57 ` [PATCH v6 07/12] watchdog: wdt-uclass.c: add wdt_stop_all() helper Rasmus Villemoes
2021-08-19 11:37   ` Wolfgang Denk
2021-08-19  9:57 ` [PATCH v6 08/12] board: x530: switch to wdt_stop_all() Rasmus Villemoes
2021-08-19  9:57 ` [PATCH v6 09/12] watchdog: wdt-uclass.c: handle all DM watchdogs in watchdog_reset() Rasmus Villemoes
2021-08-19 11:43   ` Wolfgang Denk
2021-08-19  9:57 ` [PATCH v6 10/12] watchdog: add gpio watchdog driver Rasmus Villemoes
2021-08-19 11:46   ` Wolfgang Denk
2021-08-19 12:09     ` Rasmus Villemoes
2021-08-19 12:32       ` Wolfgang Denk
2021-08-19 12:35         ` Tom Rini
2021-08-19 13:03           ` Wolfgang Denk
2021-08-19 13:08             ` Tom Rini
2021-08-19 14:16               ` Wolfgang Denk
2021-08-19 14:44                 ` Simon Glass
2021-08-19 14:57                   ` Wolfgang Denk
2021-08-20 15:02                     ` Simon Glass
2021-08-23 11:07                       ` Wolfgang Denk
2021-08-23 17:25                         ` Simon Glass
2021-08-20  6:22         ` Rasmus Villemoes [this message]
2021-08-20 18:22           ` Simon Glass
2021-08-19  9:57 ` [PATCH v6 11/12] sandbox: add test of wdt_gpio driver Rasmus Villemoes
2021-08-19  9:57 ` [PATCH v6 12/12] sandbox: add test of wdt-uclass' watchdog_reset() Rasmus Villemoes
2021-08-31  8:17   ` Stefan Roese
2021-08-31  9:29     ` Rasmus Villemoes
2021-08-31 12:44       ` Tom Rini
2021-08-31 15:03       ` Stefan Roese

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=5cceb902-a4c1-d714-1685-2d4a9667e33c@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=wd@denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.