public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Dmitry Baryshkov <dbaryshkov@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: Dmitry Baryshkov <dbaryshkov@gmail.com>,
	Eric Miao <eric.miao@marvell.com>
Subject: [PATCH 2/6] [MTD] sharpsl_nand: make drvdata non-static
Date: Fri, 17 Oct 2008 03:15:05 +0400	[thread overview]
Message-ID: <1224198909-17568-2-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1224198909-17568-1-git-send-email-dbaryshkov@gmail.com>

Merge mtd_info and nand_chip info special struct and
make it drvdata instead of plain static variable.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
 drivers/mtd/nand/sharpsl.c |   53 ++++++++++++++++++++++++--------------------
 1 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 0a99188..6851806 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -26,6 +26,11 @@
 #include <mach/hardware.h>
 #include <asm/mach-types.h>
 
+struct sharpsl_nand {
+	struct mtd_info		mtd;
+	struct nand_chip	chip;
+};
+
 static void __iomem *sharpsl_io_base;
 
 /* register offset */
@@ -46,11 +51,6 @@ static void __iomem *sharpsl_io_base;
 #define FLCE0		(1 << 0)
 
 /*
- * MTD structure for SharpSL
- */
-static struct mtd_info *sharpsl_mtd = NULL;
-
-/*
  * Define partitions for flash device
  */
 #define DEFAULT_NUM_PARTITIONS 3
@@ -157,10 +157,11 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
 	struct mtd_partition *sharpsl_partition_info;
 	struct resource *r;
 	int err = 0;
+	struct sharpsl_nand *sharpsl;
 
 	/* Allocate memory for MTD device structure and private data */
-	sharpsl_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
-	if (!sharpsl_mtd) {
+	sharpsl = kzalloc(sizeof(struct sharpsl_nand), GFP_KERNEL);
+	if (!sharpsl) {
 		printk("Unable to allocate SharpSL NAND MTD device structure.\n");
 		return -ENOMEM;
 	}
@@ -176,20 +177,18 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
 	sharpsl_io_base = ioremap(r->start, resource_size(r));
 	if (!sharpsl_io_base) {
 		printk("ioremap to access Sharp SL NAND chip failed\n");
-		kfree(sharpsl_mtd);
-		return -EIO;
+		err = -EIO;
+		goto err_ioremap;
 	}
 
 	/* Get pointer to private data */
-	this = (struct nand_chip *)(&sharpsl_mtd[1]);
-
-	/* Initialize structures */
-	memset(sharpsl_mtd, 0, sizeof(struct mtd_info));
-	memset(this, 0, sizeof(struct nand_chip));
+	this = (struct nand_chip *)(&sharpsl->chip);
 
 	/* Link the private data with the MTD structure */
-	sharpsl_mtd->priv = this;
-	sharpsl_mtd->owner = THIS_MODULE;
+	sharpsl->mtd.priv = this;
+	sharpsl->mtd.owner = THIS_MODULE;
+
+	platform_set_drvdata(pdev, sharpsl);
 
 	/*
 	 * PXA initialize
@@ -218,16 +217,17 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
 	this->ecc.correct = nand_correct_data;
 
 	/* Scan to find existence of the device */
-	err = nand_scan(sharpsl_mtd, 1);
+	err = nand_scan(&sharpsl->mtd, 1);
 	if (err) {
+		platform_set_drvdata(pdev, NULL);
 		iounmap(sharpsl_io_base);
-		kfree(sharpsl_mtd);
+		kfree(sharpsl);
 		return err;
 	}
 
 	/* Register the partitions */
-	sharpsl_mtd->name = "sharpsl-nand";
-	nr_partitions = parse_mtd_partitions(sharpsl_mtd, part_probes, &sharpsl_partition_info, 0);
+	sharpsl->mtd.name = "sharpsl-nand";
+	nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0);
 
 	if (nr_partitions <= 0) {
 		nr_partitions = DEFAULT_NUM_PARTITIONS;
@@ -247,13 +247,14 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
 		}
 	}
 
-	add_mtd_partitions(sharpsl_mtd, sharpsl_partition_info, nr_partitions);
+	add_mtd_partitions(&sharpsl->mtd, sharpsl_partition_info, nr_partitions);
 
 	/* Return happy */
 	return 0;
 
+err_ioremap:
 err_get_res:
-	kfree(sharpsl_mtd);
+	kfree(sharpsl);
 	return err;
 }
 
@@ -262,13 +263,17 @@ err_get_res:
  */
 static int __devexit sharpsl_nand_remove(struct platform_device *pdev)
 {
+	struct sharpsl_nand *sharpsl = platform_get_drvdata(pdev);
+
 	/* Release resources, unregister device */
-	nand_release(sharpsl_mtd);
+	nand_release(&sharpsl->mtd);
+
+	platform_set_drvdata(pdev, NULL);
 
 	iounmap(sharpsl_io_base);
 
 	/* Free the MTD device structure */
-	kfree(sharpsl_mtd);
+	kfree(sharpsl);
 
 	return 0;
 }
-- 
1.5.6.5

  reply	other threads:[~2008-10-16 23:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-16 23:11 [GIT PULL] sharpsl-nand driver model hookup Dmitry Baryshkov
2008-10-16 23:13 ` Dmitry Baryshkov
2008-10-16 23:15 ` [PATCH 1/6] [MTD] sharpsl_nand: switch to driver model usage Dmitry Baryshkov
2008-10-16 23:15   ` Dmitry Baryshkov [this message]
2008-10-16 23:15     ` [PATCH 3/6] [MTD] sharpsl_nand: move io addr to struct sharpsl_nand Dmitry Baryshkov
2008-10-16 23:15       ` [PATCH 4/6] [MTD] sharpsl-nand: cleanup partitions support Dmitry Baryshkov
2008-10-16 23:15         ` [PATCH 5/6] [MTD] sharpsl-nand: use platform_data for model-specific values Dmitry Baryshkov
2008-10-16 23:15           ` [PATCH 6/6] [MTD] sharpsl-nand: move registration to board code Dmitry Baryshkov
2008-11-25  9:05 ` [GIT PULL] sharpsl-nand driver model hookup Eric Miao
2008-12-01  2:13   ` Dmitry
2008-12-10 15:59     ` David Woodhouse
2008-12-11  1:08       ` Dmitry Eremin-Solenikov

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=1224198909-17568-2-git-send-email-dbaryshkov@gmail.com \
    --to=dbaryshkov@gmail.com \
    --cc=eric.miao@marvell.com \
    --cc=linux-mtd@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