[PATCH 01/23] add register_chrdev_ids() to char_dev.c, API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <jim.cromie@xxxxxxxxx>

cc: Alessandro Zummo <a.zummo@xxxxxxxxxxxx>
cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
cc: Anil Ravindranath <anil_ravindranath@xxxxxxxxxxxxxx>
cc: Benny Halevy <bhalevy@xxxxxxxxxxx>
cc: Boaz Harrosh <bharrosh@xxxxxxxxxxx>
cc: Chris Metcalf <cmetcalf@xxxxxxxxxx>
cc: David Brownell <dbrownell@xxxxxxxxxxxxxxxxxxxxx>
cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
cc: David Woodhouse <dwmw2@xxxxxxxxxxxxx>
cc: devel@xxxxxxxxxxxxxxxxxxxx
cc: Doug Gilbert <dgilbert@xxxxxxxxxxxx>
cc: Greg Kroah-Hartman <gregkh@xxxxxxx>
cc: Hal Rosenstock <hal.rosenstock@xxxxxxxxx>
cc: "Hans J. Koch" <hjk@xxxxxxxxxxxx>
cc: Heiko Carstens <heiko.carstens@xxxxxxxxxx>
cc: Jens Axboe <axboe@xxxxxxxxx>
cc: Jim Cromie <jim.cromie@xxxxxxxxx>
cc: Jiri Kosina <jkosina@xxxxxxx>
cc: Jiri Slaby <jirislaby@xxxxxxxxx>
cc: linux390@xxxxxxxxxx
cc: linux-fsdevel@xxxxxxxxxxxxxxx
cc: linux-input@xxxxxxxxxxxxxxx
cc: linux-kernel@xxxxxxxxxxxxxxx
cc: linux-media@xxxxxxxxxxxxxxx
cc: linux-mtd@xxxxxxxxxxxxxxxxxxx
cc: linuxpps@xxxxxxxxxxxxxxx (subscribers-only)
cc: linux-rdma@xxxxxxxxxxxxxxx
cc: linux-s390@xxxxxxxxxxxxxxx
cc: linux-scsi@xxxxxxxxxxxxxxx
cc: linux-sh@xxxxxxxxxxxxxxx
cc: linux-usb@xxxxxxxxxxxxxxx
cc: Martin Schwidefsky <schwidefsky@xxxxxxxxxx>
cc: Matthew Wilcox <matthew@xxxxxx>
cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxxxxx>
cc: netdev@xxxxxxxxxxxxxxx
cc: osd-dev@xxxxxxxxxxxx
cc: osst-users@xxxxxxxxxxxxxxxxxxxxx
cc: Paul Mundt <lethal@xxxxxxxxxxxx>
cc: Rodolfo Giometti <giometti@xxxxxxxxxxxx>
cc: Roland Dreier <roland@xxxxxxxxxx>
cc: rtc-linux@xxxxxxxxxxxxxxxx
cc: Sean Hefty <sean.hefty@xxxxxxxxx>
cc: Willem Riede <osst@xxxxxxxxx>
---
 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
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux