register_chrdev_ids() replaces and deprecates register_chrdev_region()
and alloc_chrdev_region() with a single function that works for both
dynamic and static major numbers.

Like alloc_chrdev_region(), 1st arg is a dev_t*, but its an in/out
parameter, and expects both major and minor to be preset, and thus the
separate minor arg is dropped.  If major == 0, a dynamic major is
reserved, saved into 1st arg, and thus available to caller afterwards.

Signed-off-by: Jim Cromie <[email protected]>

cc: Alessandro Zummo <[email protected]>
cc: Alexander Viro <[email protected]>
cc: Anil Ravindranath <[email protected]>
cc: Benny Halevy <[email protected]>
cc: Boaz Harrosh <[email protected]>
cc: Chris Metcalf <[email protected]>
cc: David Brownell <[email protected]>
cc: "David S. Miller" <[email protected]>
cc: David Woodhouse <[email protected]>
cc: [email protected]
cc: Doug Gilbert <[email protected]>
cc: Greg Kroah-Hartman <[email protected]>
cc: Hal Rosenstock <[email protected]>
cc: "Hans J. Koch" <[email protected]>
cc: Heiko Carstens <[email protected]>
cc: Jens Axboe <[email protected]>
cc: Jim Cromie <[email protected]>
cc: Jiri Kosina <[email protected]>
cc: Jiri Slaby <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected] (subscribers-only)
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: Martin Schwidefsky <[email protected]>
cc: Matthew Wilcox <[email protected]>
cc: Mauro Carvalho Chehab <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: Paul Mundt <[email protected]>
cc: Rodolfo Giometti <[email protected]>
cc: Roland Dreier <[email protected]>
cc: [email protected]
cc: Sean Hefty <[email protected]>
cc: Willem Riede <[email protected]>
---
 fs/char_dev.c      |   33 +++++++++++++++++++++++++++++----
 include/linux/fs.h |    6 ++++--
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/fs/char_dev.c b/fs/char_dev.c
index dca9e5e..9149b7c 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -93,7 +93,7 @@ void chrdev_show(struct seq_file *f, off_t offset)
  */
 static struct char_device_struct *
 __register_chrdev_region(unsigned int major, unsigned int baseminor,
-                          int minorct, const char *name)
+                        int minorct, const char *name)
 {
        struct char_device_struct *cd, **cp;
        int ret = 0;
@@ -193,7 +193,8 @@ __unregister_chrdev_region(unsigned major, unsigned 
baseminor, int minorct)
  *
  * Return value is zero on success, a negative error code on failure.
  */
-int register_chrdev_region(dev_t from, unsigned count, const char *name)
+int __deprecated
+register_chrdev_region(dev_t from, unsigned count, const char *name)
 {
        struct char_device_struct *cd;
        dev_t to = from + count;
@@ -229,8 +230,9 @@ fail:
  * chosen dynamically, and returned (along with the first minor number)
  * in @dev.  Returns zero or a negative error code.
  */
-int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
-                       const char *name)
+int __deprecated
+alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
+                   const char *name)
 {
        struct char_device_struct *cd;
        cd = __register_chrdev_region(0, baseminor, count, name);
@@ -241,6 +243,28 @@ int alloc_chrdev_region(dev_t *dev, unsigned baseminor, 
unsigned count,
 }
 
 /**
+ * register_chrdev_ids() - register a range of char device numbers
+ * @dev: in/output parameter for requested/claimed device major, minor
+ * @count: the number of minor numbers required
+ * @name: the name of the associated device or driver
+ *
+ * Allocates a range of char device numbers.  The major number will be
+ * chosen dynamically if passed as 0, or reserved specifically otherwize,
+ * with reserved numbers written into @dev.
+ * Returns zero, or a negative error code.
+ */
+int register_chrdev_ids(dev_t *dev, unsigned count, const char *name)
+{
+       struct char_device_struct *cd;
+
+       cd = __register_chrdev_region(MAJOR(*dev), MINOR(*dev), count, name);
+       if (IS_ERR(cd))
+               return PTR_ERR(cd);
+       *dev = MKDEV(cd->major, cd->baseminor);
+       return 0;
+}
+
+/**
  * __register_chrdev() - create and register a cdev occupying a range of minors
  * @major: major device number or 0 for dynamic allocation
  * @baseminor: first of the requested range of minor numbers
@@ -566,6 +590,7 @@ void __init chrdev_init(void)
 EXPORT_SYMBOL(register_chrdev_region);
 EXPORT_SYMBOL(unregister_chrdev_region);
 EXPORT_SYMBOL(alloc_chrdev_region);
+EXPORT_SYMBOL(register_chrdev_ids);
 EXPORT_SYMBOL(cdev_init);
 EXPORT_SYMBOL(cdev_alloc);
 EXPORT_SYMBOL(cdev_del);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index cdf9495..e72de48 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2075,8 +2075,10 @@ static inline void bd_unlink_disk_holder(struct 
block_device *bdev,
 
 /* fs/char_dev.c */
 #define CHRDEV_MAJOR_HASH_SIZE 255
-extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
-extern int register_chrdev_region(dev_t, unsigned, const char *);
+extern int register_chrdev_ids(dev_t *, unsigned, const char *);
+extern int __deprecated alloc_chrdev_region(dev_t *, unsigned, unsigned,
+                                           const char *);
+extern int __deprecated register_chrdev_region(dev_t, unsigned, const char *);
 extern int __register_chrdev(unsigned int major, unsigned int baseminor,
                             unsigned int count, const char *name,
                             const struct file_operations *fops);
-- 
1.7.4.4

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

Reply via email to