Commit cf3e43dbe0cc4a7ee7f6ab1bb5231dcfda164e02

Authored by Jonathan Corbet
Committed by Linus Torvalds
1 parent 5785c95bae

[PATCH] cdev documentation

Add some documentation comments for the cdev interface.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Cc: Rolf Eike Beer <eike-kernel@sf-tec.de>
Acked-by: "Randy.Dunlap" <rdunlap@xenotime.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 2 changed files with 64 additions and 0 deletions Side-by-side Diff

Documentation/DocBook/kernel-api.tmpl
... ... @@ -454,6 +454,11 @@
454 454 !Eblock/ll_rw_blk.c
455 455 </chapter>
456 456  
  457 + <chapter id="chrdev">
  458 + <title>Char devices</title>
  459 +!Efs/char_dev.c
  460 + </chapter>
  461 +
457 462 <chapter id="miscdev">
458 463 <title>Miscellaneous Devices</title>
459 464 !Edrivers/char/misc.c
... ... @@ -183,6 +183,15 @@
183 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 + */
186 195 int register_chrdev_region(dev_t from, unsigned count, const char *name)
187 196 {
188 197 struct char_device_struct *cd;
... ... @@ -208,6 +217,17 @@
208 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 + */
211 231 int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
212 232 const char *name)
213 233 {
... ... @@ -277,6 +297,15 @@
277 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 + */
280 309 void unregister_chrdev_region(dev_t from, unsigned count)
281 310 {
282 311 dev_t to = from + count;
... ... @@ -414,6 +443,16 @@
414 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 + */
417 456 int cdev_add(struct cdev *p, dev_t dev, unsigned count)
418 457 {
419 458 p->dev = dev;
... ... @@ -426,6 +465,13 @@
426 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 + */
429 475 void cdev_del(struct cdev *p)
430 476 {
431 477 cdev_unmap(p->dev, p->count);
... ... @@ -454,6 +500,11 @@
454 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 + */
457 508 struct cdev *cdev_alloc(void)
458 509 {
459 510 struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
... ... @@ -465,6 +516,14 @@
465 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 + */
468 527 void cdev_init(struct cdev *cdev, const struct file_operations *fops)
469 528 {
470 529 memset(cdev, 0, sizeof *cdev);