From: Tejun Heo <tj@kernel.org>
To: Greg KH <greg@kroah.com>, Al Viro <viro@ftp.linux.org.uk>,
Takashi Iwai <tiwai@suse.de>,
Linux Kernel <linux-kernel@vger.kernel.org>
Cc: cguthrie@mandriva.org
Subject: [PATCH 1/2] chrdev: implement __[un]register_chrdev()
Date: Wed, 05 Aug 2009 15:35:42 +0900 [thread overview]
Message-ID: <4A79283E.7030202@kernel.org> (raw)
[un]register_chrdev() assume minor range 0-255. This patch adds __
prefixed versions which take @minorbase and @count explicitly.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
---
Hello,
These two patches make sound_core grabbing OSS device number optional.
If there's no objection, I think it would be easiest to push this
through Takashi's tree.
Thanks.
fs/char_dev.c | 63 +++++++++++++++++++++++++++++++++++++++++++----------
include/linux/fs.h | 11 ++++++---
2 files changed, 60 insertions(+), 14 deletions(-)
Index: work/fs/char_dev.c
===================================================================
--- work.orig/fs/char_dev.c
+++ work/fs/char_dev.c
@@ -237,8 +237,10 @@ int alloc_chrdev_region(dev_t *dev, unsi
}
/**
- * register_chrdev() - Register a major number for character devices.
+ * __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
+ * @count: the number of minor numbers required
* @name: name of this range of devices
* @fops: file operations associated with this devices
*
@@ -254,19 +256,17 @@ int alloc_chrdev_region(dev_t *dev, unsi
* /dev. It only helps to keep track of the different owners of devices. If
* your module name has only one type of devices it's ok to use e.g. the name
* of the module here.
- *
- * This function registers a range of 256 minor numbers. The first minor number
- * is 0.
*/
-int register_chrdev(unsigned int major, const char *name,
- const struct file_operations *fops)
+int __register_chrdev(unsigned int major, unsigned int baseminor,
+ unsigned int count, const char *name,
+ const struct file_operations *fops)
{
struct char_device_struct *cd;
struct cdev *cdev;
char *s;
int err = -ENOMEM;
- cd = __register_chrdev_region(major, 0, 256, name);
+ cd = __register_chrdev_region(major, baseminor, count, name);
if (IS_ERR(cd))
return PTR_ERR(cd);
@@ -280,7 +280,7 @@ int register_chrdev(unsigned int major,
for (s = strchr(kobject_name(&cdev->kobj),'/'); s; s = strchr(s, '/'))
*s = '!';
- err = cdev_add(cdev, MKDEV(cd->major, 0), 256);
+ err = cdev_add(cdev, MKDEV(cd->major, baseminor), count);
if (err)
goto out;
@@ -290,11 +290,26 @@ int register_chrdev(unsigned int major,
out:
kobject_put(&cdev->kobj);
out2:
- kfree(__unregister_chrdev_region(cd->major, 0, 256));
+ kfree(__unregister_chrdev_region(cd->major, baseminor, count));
return err;
}
/**
+ * register_chrdev() - create and register a cdev occupying a full major
+ * @major: major device number or 0 for dynamic allocation
+ * @name: name of this range of devices
+ * @fops: file operations associated with this devices
+ *
+ * Wrapper around __register_chrdev() which always allocates full
+ * minor range from 0 to 256.
+ */
+int register_chrdev(unsigned int major, const char *name,
+ const struct file_operations *fops)
+{
+ return __register_chrdev(major, 0, 256, name, fops);
+}
+
+/**
* unregister_chrdev_region() - return a range of device numbers
* @from: the first in the range of numbers to unregister
* @count: the number of device numbers to unregister
@@ -316,15 +331,41 @@ void unregister_chrdev_region(dev_t from
}
}
-void unregister_chrdev(unsigned int major, const char *name)
+/**
+ * __unregister_chrdev - unregister and destroy a cdev
+ * @major: major device number
+ * @baseminor: first of the range of minor numbers
+ * @count: the number of minor numbers this cdev is occupying
+ * @name: name of this range of devices
+ *
+ * Unregister and destroy the cdev occupying the region described by
+ * @major, @baseminor and @count. This function undoes what
+ * __register_chrdev() did.
+ */
+void __unregister_chrdev(unsigned int major, unsigned int baseminor,
+ unsigned int count, const char *name)
{
struct char_device_struct *cd;
- cd = __unregister_chrdev_region(major, 0, 256);
+
+ cd = __unregister_chrdev_region(major, baseminor, count);
if (cd && cd->cdev)
cdev_del(cd->cdev);
kfree(cd);
}
+/**
+ * unregister_chrdev - unregister and destroy a cdev
+ * @major: major device number
+ * @name: name of this range of devices
+ *
+ * Wrapper around __unregister_chrdev() which assumes full minor range
+ * from 0 to 256.
+ */
+void unregister_chrdev(unsigned int major, const char *name)
+{
+ __unregister_chrdev(major, 0, 256, name);
+}
+
static DEFINE_SPINLOCK(cdev_lock);
static struct kobject *cdev_get(struct cdev *p)
Index: work/include/linux/fs.h
===================================================================
--- work.orig/include/linux/fs.h
+++ work/include/linux/fs.h
@@ -1998,9 +1998,14 @@ extern void bd_release_from_disk(struct
#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(unsigned int, const char *,
- const struct file_operations *);
-extern void unregister_chrdev(unsigned int, const char *);
+extern int __register_chrdev(unsigned int major, unsigned int baseminor,
+ unsigned int count, const char *name,
+ const struct file_operations *fops);
+extern int register_chrdev(unsigned int major, const char *name,
+ const struct file_operations *fops);
+extern void __unregister_chrdev(unsigned int major, unsigned int baseminor,
+ unsigned int count, const char *name);
+extern void unregister_chrdev(unsigned int major, const char *name);
extern void unregister_chrdev_region(dev_t, unsigned);
extern void chrdev_show(struct seq_file *,off_t);
next reply other threads:[~2009-08-05 6:36 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-05 6:35 Tejun Heo [this message]
2009-08-05 6:40 ` [PATCH 2/2] sound: make OSS device number claiming optional Tejun Heo
2009-08-05 9:15 ` Alan Cox
2009-08-05 9:24 ` Colin Guthrie
2009-08-05 9:59 ` Alan Cox
2009-08-05 10:14 ` Takashi Iwai
2009-08-05 10:26 ` Alan Cox
2009-08-05 10:45 ` Takashi Iwai
2009-08-05 11:15 ` Alan Cox
2009-08-05 11:34 ` Tejun Heo
2009-08-05 12:35 ` Tejun Heo
2009-08-05 13:11 ` Alan Cox
2009-08-05 14:16 ` Tejun Heo
2009-08-05 9:32 ` Tejun Heo
2009-08-05 10:00 ` Alan Cox
2009-08-05 11:27 ` Tejun Heo
2009-08-05 12:48 ` Alan Cox
2009-08-05 14:13 ` Tejun Heo
2009-08-05 14:29 ` Alan Cox
2009-08-05 16:02 ` Tejun Heo
2009-08-05 16:33 ` Alan Cox
2009-08-05 16:38 ` Alan Cox
2009-08-05 16:52 ` Tejun Heo
2009-08-05 17:01 ` Alan Cox
2009-08-06 5:55 ` Tejun Heo
2009-08-05 7:04 ` [PATCH 1/2] chrdev: implement __[un]register_chrdev() Takashi Iwai
2009-08-05 7:11 ` Tejun Heo
2009-08-05 7:20 ` Takashi Iwai
2009-08-05 7:30 ` Tejun Heo
2009-08-05 9:01 ` [PATCH 1/2 UPDATED] " Tejun Heo
2009-08-05 16:16 ` [PATCH 1/2] " Greg KH
2009-08-05 16:30 ` Tejun Heo
2009-08-05 16:49 ` Greg KH
2009-08-05 17:01 ` Tejun Heo
2009-08-05 17:15 ` Greg KH
2009-08-06 5:52 ` Tejun Heo
2009-08-06 8:13 ` Tejun Heo
2009-08-06 19:58 ` Greg KH
2009-08-07 2:34 ` Tejun Heo
2009-08-07 4:05 ` Greg KH
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=4A79283E.7030202@kernel.org \
--to=tj@kernel.org \
--cc=cguthrie@mandriva.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tiwai@suse.de \
--cc=viro@ftp.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.