Skip to content

Commit c14faab

Browse files
Xiaomeng Tongvireshk
authored andcommitted
opp: use list iterator only inside the loop
To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate dedicated pointer variable [1]. In this case, use a new variable 'iter' as the list iterator, while use the old variable 'new_dev' as a dedicated pointer to point to the found entry. And BUG_ON(!new_dev);. [1]: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 95073b7 commit c14faab

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/opp/debugfs.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,18 @@ void opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table)
195195
static void opp_migrate_dentry(struct opp_device *opp_dev,
196196
struct opp_table *opp_table)
197197
{
198-
struct opp_device *new_dev;
198+
struct opp_device *new_dev = NULL, *iter;
199199
const struct device *dev;
200200
struct dentry *dentry;
201201

202202
/* Look for next opp-dev */
203-
list_for_each_entry(new_dev, &opp_table->dev_list, node)
204-
if (new_dev != opp_dev)
203+
list_for_each_entry(iter, &opp_table->dev_list, node)
204+
if (iter != opp_dev) {
205+
new_dev = iter;
205206
break;
207+
}
208+
209+
BUG_ON(!new_dev);
206210

207211
/* new_dev is guaranteed to be valid here */
208212
dev = new_dev->dev;

0 commit comments

Comments
 (0)