Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:fs\char_dev.c Create Date:2022-07-28 20:02:45
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Register a single major with a specified minor range.* If major == 0 this function will dynamically allocate an unused major.* If major > 0 this function will attempt to reserve the range of minors* with given major.

Proto:static struct char_device_struct *__register_chrdev_region(unsigned int major, unsigned int baseminor, int minorct, const char *name)

Type:struct char_device_struct

Parameter:

TypeParameterName
unsigned intmajor
unsigned intbaseminor
intminorct
const char *name
100  struct char_device_struct * cd, * curr, * prev = NULL
104  If major >= s/char_dev.c Then
105  pr_err("CHRDEV \"%s\" major requested (%u) is greater than the maximum (%u)\n", name, major, s/char_dev.c - 1)
107  Return ERR_PTR( - EINVAL)
110  If minorct > MINORMASK + 1 - baseminor Then
111  pr_err("CHRDEV \"%s\" minor range requested (%u-%u) is out of range of maximum range (%u-%u) for a single major\n", name, baseminor, baseminor + minorct - 1, 0, MINORMASK)
113  Return ERR_PTR( - EINVAL)
116  cd = kzalloc - allocate memory. The memory is set to zero.*@size: how many bytes of memory are required.*@flags: the type of memory to allocate (see kmalloc).
117  If (cd == NULL) Then Return ERR_PTR( - ENOMEM)
120  mutex_lock( & chrdevs_lock)
122  If major == 0 Then
123  ret = find_dynamic_major()
124  If ret < 0 Then
125  pr_err("CHRDEV \"%s\" dynamic allocation region is full\n", name)
127  Go to out
129  major = ret
132  ret = -EBUSY
133  i = dex in the above
134  When curr cycle
135  If major < major Then Continue
138  If major > major Then Break
141  If baseminor + minorct <= baseminor Then Continue
144  If baseminor >= baseminor + minorct Then Break
147  Go to out
150  major = major
151  baseminor = baseminor
152  minorct = minorct
153  Copy a NUL terminated string into a sized buffer
155  If Not prev Then
156  next = curr
157  chrdevs[i] = cd
158  Else
159  next = next
160  next = cd
163  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
164  Return cd
165  out :
166  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
167  kfree(cd)
168  Return ERR_PTR(ret)
Caller
NameDescribe
register_chrdev_regiongister_chrdev_region() - register a range of device numbers*@from: the first in the desired range of device numbers; must include* the major number.*@count: the number of consecutive device numbers required*@name: the name of the device or driver.
alloc_chrdev_regionalloc_chrdev_region() - register a range of char device numbers*@dev: output parameter for first assigned number*@baseminor: first of the requested range of minor numbers*@count: the number of minor numbers required*@name: the name of the associated
__register_chrdev__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