mirror of
https://github.com/sysprog21/lkmpg.git
synced 2024-11-22 09:27:58 +08:00
Fix a logic error in examples/ioctl.c (#137)
Change the "alloc_ret" and "cdev_ret" initial values to non-zero. According to the source code, "alloc_chrdev_region" and "cdev_add" return zero on success, and negative code on failure. So, if the "alloc_chrdev_region" failed, the if condition becomes true, then we will jump to the label "error" by goto, checking each return value whether is a success state from both functions mentioned above and dealing with it properly for exiting the process. However, it checks the success state by comparing the return value with zero (means success), and we got "cdev_ret == 0" is true from the initial value zero, while we didn't execute "cdev_add" yet. Hence, there was a logic error when the initial value is zero. Co-authored-by: NOVBobLee <defru04002@gamil.com>
This commit is contained in:
parent
d8216ff7b6
commit
844beed5d7
|
@ -149,8 +149,8 @@ static struct file_operations fops = {
|
||||||
static int ioctl_init(void)
|
static int ioctl_init(void)
|
||||||
{
|
{
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
int alloc_ret = 0;
|
int alloc_ret = -1;
|
||||||
int cdev_ret = 0;
|
int cdev_ret = -1;
|
||||||
alloc_ret = alloc_chrdev_region(&dev, 0, num_of_dev, DRIVER_NAME);
|
alloc_ret = alloc_chrdev_region(&dev, 0, num_of_dev, DRIVER_NAME);
|
||||||
|
|
||||||
if (alloc_ret)
|
if (alloc_ret)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user