mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sandeep Jain <Sandeep_Jain@mentor.com>
To: <dwmw2@infradead.org>, <computersforpeace@gmail.com>
Cc: <linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	Steve Longerbeam <steve_longerbeam@mentor.com>,
	Jim Baxter <jim_baxter@mentor.com>,
	Sandeep Jain <Sandeep_Jain@mentor.com>
Subject: [PATCH] mtd: Allocate bdi objects dynamically
Date: Thu, 4 Aug 2016 19:31:15 +0530	[thread overview]
Message-ID: <1470319275-9465-1-git-send-email-Sandeep_Jain@mentor.com> (raw)
In-Reply-To: <Sandeep Jain <Sandeep_Jain@mentor.com>

From: Steve Longerbeam <steve_longerbeam@mentor.com>

The MTD backing dev info objects mtd_bdi was statically allocated.
So when MTD is built as a loadable module, this object fall in the
vmalloc address space.

The problem with that, is that the BDI APIs use wake_up_bit(), which calls
virt_to_page() to retrieve the memory zone of the page containing the
wait_queue to wake up, and virt_to_page() is not valid for vmalloc or
highmem addresses.

Fix this by allocating the BDI objects dynamically with kmalloc. The
objects now fall in the logical address space so that BDI APIs will
work in all cases (mtd builtin or module).

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
Signed-off-by: Jim Baxter <jim_baxter@mentor.com>
Signed-off-by: Sandeep Jain <Sandeep_Jain@mentor.com>
---
 drivers/mtd/mtdcore.c |   30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index e3936b8..9015b94 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -47,8 +47,7 @@
 
 #include "mtdcore.h"
 
-static struct backing_dev_info mtd_bdi = {
-};
+static struct backing_dev_info *mtd_bdi;
 
 #ifdef CONFIG_PM_SLEEP
 
@@ -397,7 +396,7 @@ int add_mtd_device(struct mtd_info *mtd)
 	if (WARN_ONCE(mtd->backing_dev_info, "MTD already registered\n"))
 		return -EEXIST;
 
-	mtd->backing_dev_info = &mtd_bdi;
+	mtd->backing_dev_info = mtd_bdi;
 
 	BUG_ON(mtd->writesize == 0);
 	mutex_lock(&mtd_table_mutex);
@@ -1668,18 +1667,20 @@ static const struct file_operations mtd_proc_ops = {
 /*====================================================================*/
 /* Init code */
 
-static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name)
+static struct backing_dev_info * __init mtd_bdi_init(char *name)
 {
+	struct backing_dev_info *bdi;
 	int ret;
 
-	ret = bdi_init(bdi);
-	if (!ret)
-		ret = bdi_register(bdi, NULL, "%s", name);
+	bdi = kzalloc(sizeof(*bdi), GFP_KERNEL);
+	if (!bdi)
+		return ERR_PTR(-ENOMEM);
 
+	ret = bdi_setup_and_register(bdi, name);
 	if (ret)
-		bdi_destroy(bdi);
+		kfree(bdi);
 
-	return ret;
+	return ret ? ERR_PTR(ret) : bdi;
 }
 
 static struct proc_dir_entry *proc_mtd;
@@ -1692,9 +1693,11 @@ static int __init init_mtd(void)
 	if (ret)
 		goto err_reg;
 
-	ret = mtd_bdi_init(&mtd_bdi, "mtd");
-	if (ret)
+	mtd_bdi = mtd_bdi_init("mtd");
+	if (IS_ERR(mtd_bdi)) {
+		ret = PTR_ERR(mtd_bdi);
 		goto err_bdi;
+	}
 
 	proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
 
@@ -1707,6 +1710,8 @@ static int __init init_mtd(void)
 out_procfs:
 	if (proc_mtd)
 		remove_proc_entry("mtd", NULL);
+	bdi_destroy(mtd_bdi);
+	kfree(mtd_bdi);
 err_bdi:
 	class_unregister(&mtd_class);
 err_reg:
@@ -1720,7 +1725,8 @@ static void __exit cleanup_mtd(void)
 	if (proc_mtd)
 		remove_proc_entry("mtd", NULL);
 	class_unregister(&mtd_class);
-	bdi_destroy(&mtd_bdi);
+	bdi_destroy(mtd_bdi);
+	kfree(mtd_bdi);
 	idr_destroy(&mtd_idr);
 }
 
-- 
1.7.9.5

       reply	other threads:[~2016-08-04 14:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Sandeep Jain <Sandeep_Jain@mentor.com>
2016-08-04 14:01 ` Sandeep Jain [this message]
2016-09-17 14:41   ` Richard Weinberger
2016-11-03 11:34     ` Sandeep Jain
2016-11-05  7:22       ` Marek Vasut
2016-11-29  8:12         ` Sandeep Jain
2016-12-01 15:39           ` Marek Vasut
2016-12-01 18:14             ` Brian Norris
2016-12-01 18:18               ` Marek Vasut
2016-08-04 14:16 ` [PATCH v1 0/2] mtd: lock module while used Sandeep Jain
2016-08-04 14:16   ` [PATCH v1 1/2] mtd: m25p80: " Sandeep Jain
2016-11-03 11:39     ` Sandeep Jain
2016-11-05  7:24       ` Marek Vasut
2016-12-01 19:10         ` Brian Norris
2016-08-04 14:16   ` [PATCH v1 2/2] mtd: Add hooks to call get and put on mtd devices Sandeep Jain
2016-08-04 17:32     ` Richard Weinberger
2016-08-05 11:54       ` Baxter, Jim
2016-08-05 12:13         ` Richard Weinberger

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=1470319275-9465-1-git-send-email-Sandeep_Jain@mentor.com \
    --to=sandeep_jain@mentor.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=jim_baxter@mentor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=steve_longerbeam@mentor.com \
    /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

all inboxes | Powered by JetHome®