public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Brian Norris <computersforpeace@gmail.com>
Cc: Richard Weinberger <richard@nod.at>,
	"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Jesper Nilsson <jespern@axis.com>,
	linux-cris-kernel@axis.com
Subject: Problems with 'mtd: warn when registering the same master many times'
Date: Mon, 2 Nov 2015 07:41:48 -0800	[thread overview]
Message-ID: <5637843C.10307@roeck-us.net> (raw)

Brian,

I see the following warnings in recent mips qemu tests on linux-next.

WARNING: CPU: 0 PID: 1 at drivers/mtd/mtdcore.c:619 mtd_device_parse_register+0x160/0x16c()
MTD already registered

Looking into the code, this is the result of your patch 'mtd: warn when registering
the same master many times'.

This patch is supposed to warn if mtd_device_parse_register is called multiple times
with the same mtd_info structure pointer as parameter.

At the surface, the check appears to make sense. However, it has a problem.
The output of "git grep reboot_notifier.notifier_call" in drivers/mtd results in

chips/cfi_cmdset_0001.c:        mtd->reboot_notifier.notifier_call = cfi_intelext_reboot;
chips/cfi_cmdset_0002.c:        mtd->reboot_notifier.notifier_call = cfi_amdstd_reboot;
mtdcore.c:      WARN_ONCE(mtd->reboot_notifier.notifier_call, "MTD already registered\n");
mtdcore.c:      if (mtd->_reboot && !mtd->reboot_notifier.notifier_call) {
mtdcore.c:              mtd->reboot_notifier.notifier_call = mtd_reboot_notifier;

As it turns out, the observed warning is not seen because mtd_device_parse_register()
is called multiple times. It is seen because mtd->reboot_notifier.notifier_call
is already set to cfi_intelext_reboot by the time it is checked.

I don't know if this is a bug in the mtd code, or if this is a valid use case.
Whatever it is, the warning does not warn about the driver, it warns about a potential
inconsistency in the mtd code itself (and if it is is a valid use case, the warning
is inappropriate). Maybe it would make sense to change the warning as follows ?

WARN_ONCE(mtd->_reboot && mtd->reboot_notifier.notifier_call, "MTD already registered\n");

I am not sure, though, if that is correct, since even that might be a valid use case
(a caller registering a cfi based mtd device with a _reboot callback).

I also see the warning in crisv32 runtime tests. This is because the code in
arch/cris/arch-v32/drivers/axisflashmap.c calls mtd_device_register() multiple times
with the same mtd_info argument, each time to register a different partition.
I am not sure if the check is appropriate for this case either, since the code calls
mtd_device_register(), both 'type' and 'parser_data' are NULL, parse_mtd_partitions()
does not do anything, and the problem you are concerned about does not apply.

How about changing the warning to something like the following ?

WARN_ONCE(types && mtd->_reboot && mtd->reboot_notifier.notifier_call, "MTD already registered\n");

This would eliminate (what I think are) false positives and only warn if there
is a real problem.

Thanks,
Guenter

             reply	other threads:[~2015-11-02 15:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02 15:41 Guenter Roeck [this message]
2015-11-02 17:43 ` Problems with 'mtd: warn when registering the same master many times' Brian Norris
2015-11-02 20:09   ` Guenter Roeck
2015-11-02 20:51     ` Jesper Nilsson

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=5637843C.10307@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=computersforpeace@gmail.com \
    --cc=jespern@axis.com \
    --cc=linux-cris-kernel@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    /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