Skip to content

Commit cf3e43d

Browse files
Jonathan CorbetLinus Torvalds
authored andcommitted
[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>
1 parent 5785c95 commit cf3e43d

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

‎Documentation/DocBook/kernel-api.tmpl‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ X!Edrivers/pnp/system.c
454454
!Eblock/ll_rw_blk.c
455455
</chapter>
456456

457+
<chapter id="chrdev">
458+
<title>Char devices</title>
459+
!Efs/char_dev.c
460+
</chapter>
461+
457462
<chapter id="miscdev">
458463
<title>Miscellaneous Devices</title>
459464
!Edrivers/char/misc.c

‎fs/char_dev.c‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ __unregister_chrdev_region(unsigned major, unsigned baseminor, int minorct)
183183
return cd;
184184
}
185185

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+
*/
186195
int register_chrdev_region(dev_t from, unsigned count, const char *name)
187196
{
188197
struct char_device_struct *cd;
@@ -208,6 +217,17 @@ int register_chrdev_region(dev_t from, unsigned count, const char *name)
208217
return PTR_ERR(cd);
209218
}
210219

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+
*/
211231
int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,
212232
const char *name)
213233
{
@@ -277,6 +297,15 @@ int register_chrdev(unsigned int major, const char *name,
277297
return err;
278298
}
279299

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+
*/
280309
void unregister_chrdev_region(dev_t from, unsigned count)
281310
{
282311
dev_t to = from + count;
@@ -414,6 +443,16 @@ static int exact_lock(dev_t dev, void *data)
414443
return cdev_get(p) ? 0 : -1;
415444
}
416445

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+
*/
417456
int cdev_add(struct cdev *p, dev_t dev, unsigned count)
418457
{
419458
p->dev = dev;
@@ -426,6 +465,13 @@ static void cdev_unmap(dev_t dev, unsigned count)
426465
kobj_unmap(cdev_map, dev, count);
427466
}
428467

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+
*/
429475
void cdev_del(struct cdev *p)
430476
{
431477
cdev_unmap(p->dev, p->count);
@@ -454,6 +500,11 @@ static struct kobj_type ktype_cdev_dynamic = {
454500
.release = cdev_dynamic_release,
455501
};
456502

503+
/**
504+
* cdev_alloc() - allocate a cdev structure
505+
*
506+
* Allocates and returns a cdev structure, or NULL on failure.
507+
*/
457508
struct cdev *cdev_alloc(void)
458509
{
459510
struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
@@ -465,6 +516,14 @@ struct cdev *cdev_alloc(void)
465516
return p;
466517
}
467518

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+
*/
468527
void cdev_init(struct cdev *cdev, const struct file_operations *fops)
469528
{
470529
memset(cdev, 0, sizeof *cdev);

0 commit comments

Comments
 (0)