Skip to content

Commit 29a0c84

Browse files
Robert Richtersuryasaimadhu
authored andcommitted
EDAC/mc: Fix edac_mc_find() in case no device is found
The function should return NULL in case no device is found, but it always returns the last checked mc device from the list even if the index did not match. Fix that. I did some analysis why this did not raise any issues for about 3 years and the reason is that edac_mc_find() is mostly used to search for existing devices. Thus, the bug is not triggered. [ bp: Drop the if (mci->mc_idx > idx) test in favor of readability. ] Fixes: c73e883 ("EDAC, mc: Fix locking around mc_devices list") Signed-off-by: Robert Richter <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: "[email protected]" <[email protected]> Cc: James Morse <[email protected]> Cc: Mauro Carvalho Chehab <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 2b8358a commit 29a0c84

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

drivers/edac/edac_mc.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,22 +679,18 @@ static int del_mc_from_global_list(struct mem_ctl_info *mci)
679679

680680
struct mem_ctl_info *edac_mc_find(int idx)
681681
{
682-
struct mem_ctl_info *mci = NULL;
682+
struct mem_ctl_info *mci;
683683
struct list_head *item;
684684

685685
mutex_lock(&mem_ctls_mutex);
686686

687687
list_for_each(item, &mc_devices) {
688688
mci = list_entry(item, struct mem_ctl_info, link);
689-
690-
if (mci->mc_idx >= idx) {
691-
if (mci->mc_idx == idx) {
692-
goto unlock;
693-
}
694-
break;
695-
}
689+
if (mci->mc_idx == idx)
690+
goto unlock;
696691
}
697692

693+
mci = NULL;
698694
unlock:
699695
mutex_unlock(&mem_ctls_mutex);
700696
return mci;

0 commit comments

Comments
 (0)