[PATCH 01/23] add register_chrdev_ids() to char_dev.c, API
Jim Cromie
jim.cromie at gmail.com
Thu May 19 14:33:04 PDT 2011
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 at gmail.com>
cc: Alessandro Zummo <a.zummo at towertech.it>
cc: Alexander Viro <viro at zeniv.linux.org.uk>
cc: Anil Ravindranath <anil_ravindranath at pmc-sierra.com>
cc: Benny Halevy <bhalevy at panasas.com>
cc: Boaz Harrosh <bharrosh at panasas.com>
cc: Chris Metcalf <cmetcalf at tilera.com>
cc: David Brownell <dbrownell at users.sourceforge.net>
cc: "David S. Miller" <davem at davemloft.net>
cc: David Woodhouse <dwmw2 at infradead.org>
cc: devel at driverdev.osuosl.org
cc: Doug Gilbert <dgilbert at interlog.com>
cc: Greg Kroah-Hartman <gregkh at suse.de>
cc: Hal Rosenstock <hal.rosenstock at gmail.com>
cc: "Hans J. Koch" <hjk at hansjkoch.de>
cc: Heiko Carstens <heiko.carstens at de.ibm.com>
cc: Jens Axboe <axboe at kernel.dk>
cc: Jim Cromie <jim.cromie at gmail.com>
cc: Jiri Kosina <jkosina at suse.cz>
cc: Jiri Slaby <jirislaby at gmail.com>
cc: linux390 at de.ibm.com
cc: linux-fsdevel at vger.kernel.org
cc: linux-input at vger.kernel.org
cc: linux-kernel at vger.kernel.org
cc: linux-media at vger.kernel.org
cc: linux-mtd at lists.infradead.org
cc: linuxpps at ml.enneenne.com (subscribers-only)
cc: linux-rdma at vger.kernel.org
cc: linux-s390 at vger.kernel.org
cc: linux-scsi at vger.kernel.org
cc: linux-sh at vger.kernel.org
cc: linux-usb at vger.kernel.org
cc: Martin Schwidefsky <schwidefsky at de.ibm.com>
cc: Matthew Wilcox <matthew at wil.cx>
cc: Mauro Carvalho Chehab <mchehab at infradead.org>
cc: netdev at vger.kernel.org
cc: osd-dev at open-osd.org
cc: osst-users at lists.sourceforge.net
cc: Paul Mundt <lethal at linux-sh.org>
cc: Rodolfo Giometti <giometti at enneenne.com>
cc: Roland Dreier <roland at kernel.org>
cc: rtc-linux at googlegroups.com
cc: Sean Hefty <sean.hefty at intel.com>
cc: Willem Riede <osst at riede.org>
---
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
More information about the devel
mailing list