diff mbox

[02/62] mtd: introduce mtd_device_(un)register()

Message ID 1306142623-24952-3-git-send-email-jamie@jamieiles.com
State New, archived
Headers show

Commit Message

Jamie Iles May 23, 2011, 9:22 a.m. UTC
To prepare for the removal of add_mtd_device and add_mtd_partitions(),
introduce mtd_device_register().  This will create partitions if they
are supplied or register the whole device if there are no partitions.

Once all drivers are converted to use mtd_device_register(),
add_mtd_device() and add_mtd_partitions() will be made internal only.

Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Signed-off-by: Jamie Iles <jamie@jamieiles.com>
---
 drivers/mtd/mtdcore.c          |   25 +++++++++++++++++++++++++
 include/linux/mtd/mtd.h        |   28 ++++++++++++++++++++++++++++
 include/linux/mtd/partitions.h |    2 +-
 3 files changed, 54 insertions(+), 1 deletions(-)

Comments

Artem Bityutskiy May 23, 2011, 3:17 p.m. UTC | #1
On Mon, 2011-05-23 at 10:22 +0100, Jamie Iles wrote:
> +/**
> + * mtd_device_register() - register an MTD device
> + *
> + * Register an MTD device with the system and optionally, a number of
> + * partitions.  If nr_parts is 0 then the whole device is registered,
> + * otherwise only the partitions are registered.  To register both the full
> + * device *and* the partitions, call mtd_device_register() twice, once with
> + * nr_parts == 0 and once equal to the number of partitions.
> + *
> + * @master	The MTD device to register.
> + * @parts	The partitions to register - only valid if nr_parts > 0.
> + * @nr_parts	The number of partitions in parts.  If zero then the full
> + *		MTD device is registered.
> + */
> +extern int mtd_device_register(struct mtd_info *master,
> +			       const struct mtd_partition *parts,
> +			       int nr_parts);

It does make sense to describe the function in the "interface" file, but
in the kernel we add the kernel-doc comments above the function
implementation, this is just the established practice. You may find some
examples where the description is in the .h file, but this is rare (yes,
the kernel is fare from being consistent).

So please, move the descriptive comments to mtdcore.c.

Also, please, check the kernel-doc comments buy feeding your file to
scripts kernel-doc and make sure it does not generate errors or
warnings. 

Please, do not re-send all patches, just this one, if possible. Note, if
something requires a minor conflict resolution - I can do this.
Mike Frysinger May 23, 2011, 10:55 p.m. UTC | #2
On Mon, May 23, 2011 at 05:22, Jamie Iles wrote:
> To prepare for the removal of add_mtd_device and add_mtd_partitions(),
> introduce mtd_device_register().  This will create partitions if they
> are supplied or register the whole device if there are no partitions.
>
> Once all drivers are converted to use mtd_device_register(),
> add_mtd_device() and add_mtd_partitions() will be made internal only.

i vaguely recall attempting to submit new functions like this a while
ago, but ultimately it was rejected due to the different behavior mtd
drivers had wrt partitions and whole devices
-mike
Jamie Iles May 23, 2011, 11:06 p.m. UTC | #3
On Mon, May 23, 2011 at 06:55:49PM -0400, Mike Frysinger wrote:
> On Mon, May 23, 2011 at 05:22, Jamie Iles wrote:
> > To prepare for the removal of add_mtd_device and add_mtd_partitions(),
> > introduce mtd_device_register().  This will create partitions if they
> > are supplied or register the whole device if there are no partitions.
> >
> > Once all drivers are converted to use mtd_device_register(),
> > add_mtd_device() and add_mtd_partitions() will be made internal only.
> 
> i vaguely recall attempting to submit new functions like this a while
> ago, but ultimately it was rejected due to the different behavior mtd
> drivers had wrt partitions and whole devices

I think these cases can still be covered - mtd_device_register() can be 
called twice - once with partitions and once without so it's just like 
calling add_mtd_device() then add_mtd_partitions().  The unregistering 
code deletes all registered partitions then only the master if it has 
been registered.

I don't believe these patches should have changed the behaviour of any 
of the drivers (other than it's now not possible to select whether the 
device is partitioned or not by a Kconfig option), but that can be done 
at runtime through command line partitioning perhaps.

Jamie
diff mbox

Patch

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index da69bc8..6af7ad9 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -37,6 +37,7 @@ 
 #include <linux/gfp.h>
 
 #include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
 
 #include "mtdcore.h"
 /*
@@ -426,6 +427,30 @@  out_error:
 	return ret;
 }
 
+int mtd_device_register(struct mtd_info *master,
+			const struct mtd_partition *parts,
+			int nr_parts)
+{
+	return parts ? add_mtd_partitions(master, parts, nr_parts) :
+		add_mtd_device(master);
+}
+EXPORT_SYMBOL_GPL(mtd_device_register);
+
+int mtd_device_unregister(struct mtd_info *master)
+{
+	int err;
+
+	err = del_mtd_partitions(master);
+	if (err)
+		return err;
+
+	if (!device_is_registered(&master->dev))
+		return 0;
+
+	return del_mtd_device(master);
+}
+EXPORT_SYMBOL_GPL(mtd_device_unregister);
+
 /**
  *	register_mtd_user - register a 'user' of MTD devices.
  *	@new: pointer to notifier info structure
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 9d5306b..fcb6e62 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -325,6 +325,34 @@  static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
 extern int add_mtd_device(struct mtd_info *mtd);
 extern int del_mtd_device (struct mtd_info *mtd);
 
+struct mtd_partition;
+
+/**
+ * mtd_device_register() - register an MTD device
+ *
+ * Register an MTD device with the system and optionally, a number of
+ * partitions.  If nr_parts is 0 then the whole device is registered,
+ * otherwise only the partitions are registered.  To register both the full
+ * device *and* the partitions, call mtd_device_register() twice, once with
+ * nr_parts == 0 and once equal to the number of partitions.
+ *
+ * @master	The MTD device to register.
+ * @parts	The partitions to register - only valid if nr_parts > 0.
+ * @nr_parts	The number of partitions in parts.  If zero then the full
+ *		MTD device is registered.
+ */
+extern int mtd_device_register(struct mtd_info *master,
+			       const struct mtd_partition *parts,
+			       int nr_parts);
+
+/**
+ * mtd_device_unregister() - unregister an existing MTD device.
+ *
+ * @master	The MTD device to unregister.  This will unregister both the
+ *		master and any partitions if registered.
+ */
+extern int mtd_device_unregister(struct mtd_info *master);
+
 extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
 extern int __get_mtd_device(struct mtd_info *mtd);
 extern void __put_mtd_device(struct mtd_info *mtd);
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 4a0a8ba..998a6cf 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -16,7 +16,7 @@ 
  * Partition definition structure:
  *
  * An array of struct partition is passed along with a MTD object to
- * add_mtd_partitions() to create them.
+ * mtd_device_register() to create them.
  *
  * For each partition, these fields are available:
  * name: string that will be used to label the partition's MTD device.