aboutsummaryrefslogtreecommitdiffstats
path: root/fs/char_dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/char_dev.c')
-rw-r--r--fs/char_dev.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/fs/char_dev.c b/fs/char_dev.c
index 33b95af89da4..1f3285affa39 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -183,6 +183,15 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct)
183 return cd; 183 return cd;
184} 184}
185 185
186/**
187 * register_chrdev_region() - register a range of device numbers
188 * @from: the first in the desired range of device numbers; must include
189 * the major number.
190 * @count: the number of consecutive device numbers required
191 * @name: the name of the device or driver.
192 *
193 * Return value is zero on success, a negative error code on failure.
194 */
186int register_chrdev_region(dev_t from, unsigned count, const char *name) 195int register_chrdev_region(dev_t from, unsigned count, const char *name)
187{ 196{
188 struct char_device_struct *cd; 197 struct char_device_struct *cd;
@@ -208,6 +217,17 @@ fail:
208 return PTR_ERR(cd); 217 return PTR_ERR(cd);
209} 218}
210 219
220/**
221 * alloc_chrdev_region() - register a range of char device numbers
222 * @dev: output parameter for first assigned number
223 * @baseminor: first of the requested range of minor numbers
224 * @count: the number of minor numbers required
225 * @name: the name of the associated device or driver
226 *
227 * Allocates a range of char device numbers. The major number will be
228 * chosen dynamically, and returned (along with the first minor number)
229 * in @dev. Returns zero or a negative error code.
230 */
211int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, 231int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
212 const char *name) 232 const char *name)
213{ 233{
@@ -277,6 +297,15 @@ out2:
277 return err; 297 return err;
278} 298}
279 299
300/**
301 * unregister_chrdev_region() - return a range of device numbers
302 * @from: the first in the range of numbers to unregister
303 * @count: the number of device numbers to unregister
304 *
305 * This function will unregister a range of @count device numbers,
306 * starting with @from. The caller should normally be the one who
307 * allocated those numbers in the first place...
308 */
280void unregister_chrdev_region(dev_t from, unsigned count) 309void unregister_chrdev_region(dev_t from, unsigned count)
281{ 310{
282 dev_t to = from + count; 311 dev_t to = from + count;
@@ -414,6 +443,16 @@ static int exact_lock(dev_t dev, void *data)
414 return cdev_get(p) ? 0 : -1; 443 return cdev_get(p) ? 0 : -1;
415} 444}
416 445
446/**
447 * cdev_add() - add a char device to the system
448 * @p: the cdev structure for the device
449 * @dev: the first device number for which this device is responsible
450 * @count: the number of consecutive minor numbers corresponding to this
451 * device
452 *
453 * cdev_add() adds the device represented by @p to the system, making it
454 * live immediately. A negative error code is returned on failure.
455 */
417int cdev_add(struct cdev *p, dev_t dev, unsigned count) 456int cdev_add(struct cdev *p, dev_t dev, unsigned count)
418{ 457{
419 p->dev = dev; 458 p->dev = dev;
@@ -426,6 +465,13 @@ static void cdev_unmap(dev_t dev, unsigned count)
426 kobj_unmap(cdev_map, dev, count); 465 kobj_unmap(cdev_map, dev, count);
427} 466}
428 467
468/**
469 * cdev_del() - remove a cdev from the system
470 * @p: the cdev structure to be removed
471 *
472 * cdev_del() removes @p from the system, possibly freeing the structure
473 * itself.
474 */
429void cdev_del(struct cdev *p) 475void cdev_del(struct cdev *p)
430{ 476{
431 cdev_unmap(p->dev, p->count); 477 cdev_unmap(p->dev, p->count);
@@ -454,6 +500,11 @@ static struct kobj_type ktype_cdev_dynamic = {
454 .release = cdev_dynamic_release, 500 .release = cdev_dynamic_release,
455}; 501};
456 502
503/**
504 * cdev_alloc() - allocate a cdev structure
505 *
506 * Allocates and returns a cdev structure, or NULL on failure.
507 */
457struct cdev *cdev_alloc(void) 508struct cdev *cdev_alloc(void)
458{ 509{
459 struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL); 510 struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
@@ -465,6 +516,14 @@ struct cdev *cdev_alloc(void)
465 return p; 516 return p;
466} 517}
467 518
519/**
520 * cdev_init() - initialize a cdev structure
521 * @cdev: the structure to initialize
522 * @fops: the file_operations for this device
523 *
524 * Initializes @cdev, remembering @fops, making it ready to add to the
525 * system with cdev_add().
526 */
468void cdev_init(struct cdev *cdev, const struct file_operations *fops) 527void cdev_init(struct cdev *cdev, const struct file_operations *fops)
469{ 528{
470 memset(cdev, 0, sizeof *cdev); 529 memset(cdev, 0, sizeof *cdev);