From: ezequiel.garcia@free-electrons.com (Ezequiel Garcia)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] mtd: atmel_nand: fix the warning when CONFIG_OF is not defined
Date: Sat, 31 Aug 2013 14:04:23 -0300 [thread overview]
Message-ID: <20130831170422.GA21617@localhost> (raw)
In-Reply-To: <1377894233.22372.86.camel@shinybook.infradead.org>
On Fri, Aug 30, 2013 at 09:23:53PM +0100, David Woodhouse wrote:
> On Wed, 2013-08-07 at 11:36 +0800, Josh Wu wrote:
> > This patch fix following warning:
> >
> > drivers/mtd/nand/atmel_nand.c:2007: warning: 'atmel_nand_nfc_match' defined but not used
> >
> > This patch add '#if defined(CONFIG_OF)' block to guard around the definition of
> > atmel_nand_nfc_match, in order to avoid the warning when kernel is configurated
> > as non-dt supported.
>
> Ick. This driver is littered with CONFIG_OF checks. Yet I've just seen a
> patch to pxa3xx_nand which *removes* ifdefs, on the basis that all the
> of_match_ functions/macros will just 'do the right thing'. Can't we do
> that here too? We might just need to add __maybe_unused?
>
We can. We just need to provide a few dummy functions in linux/of_mtd.h
just like the other of_xxx() are doing. See below!
> > +#if defined(CONFIG_OF)
> > static struct of_device_id atmel_nand_nfc_match[] = {
> > { .compatible = "atmel,sama5d3-nfc" },
> > { /* sentinel */ }
> > };
> > +#endif
>
> Also, why doesn't this one appear in a MODULE_DEVICE_TABLE() ?
>
Indeed. And why doesn't it have a "const" keyword?
So, in order to remove the CONFIG_OF safely from this driver,
and avoid any stupid warnings, we need to first implement
these dummies:
--------------------------------8<-----------------------------------
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
index ed7f267..66f173e 100644
--- a/include/linux/of_mtd.h
+++ b/include/linux/of_mtd.h
@@ -14,6 +14,21 @@
int of_get_nand_ecc_mode(struct device_node *np);
int of_get_nand_bus_width(struct device_node *np);
bool of_get_nand_on_flash_bbt(struct device_node *np);
+#else
+static inline int of_get_nand_ecc_mode(struct device_node *np)
+{
+ return -ENOSYS;
+}
+
+static inline int of_get_nand_bus_width(struct device_node *np)
+{
+ return -ENOSYS;
+}
+
+static inline bool of_get_nand_on_flash_bbt(struct device_node *np)
+{
+ return false;
+}
#endif
#endif /* __LINUX_OF_MTD_H */
-------------------------------->8-----------------------------------
And then, with this little patch, we get rid of the ugly CONFIG_OF check
from the atmel_nand driver:
--------------------------------8<-----------------------------------
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 0e365da..ac58098 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -1448,7 +1448,6 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
ecc_writel(host->ecc, CR, ATMEL_ECC_RST);
}
-#if defined(CONFIG_OF)
static int atmel_of_init_port(struct atmel_nand_host *host,
struct device_node *np)
{
@@ -1456,7 +1455,7 @@ static int atmel_of_init_port(struct atmel_nand_host *host,
u32 offset[2];
int ecc_mode;
struct atmel_nand_data *board = &host->board;
- enum of_gpio_flags flags;
+ enum of_gpio_flags flags = 0;
if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
if (val >= 32) {
@@ -1539,13 +1538,6 @@ static int atmel_of_init_port(struct atmel_nand_host *host,
return 0;
}
-#else
-static int atmel_of_init_port(struct atmel_nand_host *host,
- struct device_node *np)
-{
- return -EINVAL;
-}
-#endif
static int __init atmel_hw_nand_init_params(struct platform_device *pdev,
struct atmel_nand_host *host)
@@ -2205,14 +2197,12 @@ static int __exit atmel_nand_remove(struct platform_device *pdev)
return 0;
}
-#if defined(CONFIG_OF)
static const struct of_device_id atmel_nand_dt_ids[] = {
{ .compatible = "atmel,at91rm9200-nand" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
-#endif
static int atmel_nand_nfc_probe(struct platform_device *pdev)
{
@@ -2251,12 +2241,11 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev)
return 0;
}
-#if defined(CONFIG_OF)
-static struct of_device_id atmel_nand_nfc_match[] = {
+static const struct of_device_id atmel_nand_nfc_match[] = {
{ .compatible = "atmel,sama5d3-nfc" },
{ /* sentinel */ }
};
-#endif
+MODULE_DEVICE_TABLE(of, atmel_nand_nfc_match);
static struct platform_driver atmel_nand_nfc_driver = {
.driver = {
-------------------------------->8-----------------------------------
Of course, these are untested. If they look OK and don't cause any trouble,
then I'll prepare proper patches.
--
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
next prev parent reply other threads:[~2013-08-31 17:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-07 3:36 [PATCH] mtd: atmel_nand: fix the warning when CONFIG_OF is not defined Josh Wu
2013-08-07 6:30 ` Artem Bityutskiy
2013-08-30 20:23 ` David Woodhouse
2013-08-31 17:04 ` Ezequiel Garcia [this message]
2013-09-02 7:02 ` Josh Wu
2013-09-02 17:13 ` Ezequiel Garcia
2013-09-03 3:57 ` Josh Wu
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=20130831170422.GA21617@localhost \
--to=ezequiel.garcia@free-electrons.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).