mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 12:11:40 +00:00
char: misc: remove usage of list iterator past the loop body
In preparation to limit the scope of the list iterator to the list traversal loop, use a dedicated pointer pointing to the found element [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com> Link: https://lore.kernel.org/r/20220319201454.2511733-1-jakobkoschel@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
a8a570c6d0
commit
3a5e65023f
@ -100,17 +100,18 @@ static const struct seq_operations misc_seq_ops = {
|
||||
static int misc_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
int minor = iminor(inode);
|
||||
struct miscdevice *c;
|
||||
struct miscdevice *c = NULL, *iter;
|
||||
int err = -ENODEV;
|
||||
const struct file_operations *new_fops = NULL;
|
||||
|
||||
mutex_lock(&misc_mtx);
|
||||
|
||||
list_for_each_entry(c, &misc_list, list) {
|
||||
if (c->minor == minor) {
|
||||
new_fops = fops_get(c->fops);
|
||||
break;
|
||||
}
|
||||
list_for_each_entry(iter, &misc_list, list) {
|
||||
if (iter->minor != minor)
|
||||
continue;
|
||||
c = iter;
|
||||
new_fops = fops_get(iter->fops);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!new_fops) {
|
||||
@ -118,11 +119,12 @@ static int misc_open(struct inode *inode, struct file *file)
|
||||
request_module("char-major-%d-%d", MISC_MAJOR, minor);
|
||||
mutex_lock(&misc_mtx);
|
||||
|
||||
list_for_each_entry(c, &misc_list, list) {
|
||||
if (c->minor == minor) {
|
||||
new_fops = fops_get(c->fops);
|
||||
break;
|
||||
}
|
||||
list_for_each_entry(iter, &misc_list, list) {
|
||||
if (iter->minor != minor)
|
||||
continue;
|
||||
c = iter;
|
||||
new_fops = fops_get(iter->fops);
|
||||
break;
|
||||
}
|
||||
if (!new_fops)
|
||||
goto fail;
|
||||
|
Loading…
Reference in New Issue
Block a user