提交 652d703b 编写于 作者: S Srivatsa S. Bhat 提交者: Greg Kroah-Hartman

char_dev: Fix off-by-one bugs in find_dynamic_major()

CHRDEV_MAJOR_DYN_END and CHRDEV_MAJOR_DYN_EXT_END are valid major
numbers. So fix the loop iteration to include them in the search for
free major numbers.

While at it, also remove a redundant if condition ("cd->major != i"),
as it will never be true.
Signed-off-by: NSrivatsa S. Bhat <srivatsa@csail.mit.edu>
Reviewed-by: NLogan Gunthorpe <logang@deltatee.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 bd329f02
...@@ -67,18 +67,18 @@ static int find_dynamic_major(void) ...@@ -67,18 +67,18 @@ static int find_dynamic_major(void)
int i; int i;
struct char_device_struct *cd; struct char_device_struct *cd;
for (i = ARRAY_SIZE(chrdevs)-1; i > CHRDEV_MAJOR_DYN_END; i--) { for (i = ARRAY_SIZE(chrdevs)-1; i >= CHRDEV_MAJOR_DYN_END; i--) {
if (chrdevs[i] == NULL) if (chrdevs[i] == NULL)
return i; return i;
} }
for (i = CHRDEV_MAJOR_DYN_EXT_START; for (i = CHRDEV_MAJOR_DYN_EXT_START;
i > CHRDEV_MAJOR_DYN_EXT_END; i--) { i >= CHRDEV_MAJOR_DYN_EXT_END; i--) {
for (cd = chrdevs[major_to_index(i)]; cd; cd = cd->next) for (cd = chrdevs[major_to_index(i)]; cd; cd = cd->next)
if (cd->major == i) if (cd->major == i)
break; break;
if (cd == NULL || cd->major != i) if (cd == NULL)
return i; return i;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册