OSDN Git Service

EDAC/mc: Fix edac_mc_find() in case no device is found
authorRobert Richter <rrichter@marvell.com>
Tue, 14 May 2019 10:49:09 +0000 (10:49 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Jan 2020 13:50:48 +0000 (14:50 +0100)
commita0a4643f1899b6f9339957d3c7c8e749735be494
treec51661b17eb233b5797cc5c8e824de0cd03e0af4
parent60b6fd81e218f2dcecd0590670a377e59bd6c34c
EDAC/mc: Fix edac_mc_find() in case no device is found

[ Upstream commit 29a0c843973bc385918158c6976e4dbe891df969 ]

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: c73e8833bec5 ("EDAC, mc: Fix locking around mc_devices list")
Signed-off-by: Robert Richter <rrichter@marvell.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: "linux-edac@vger.kernel.org" <linux-edac@vger.kernel.org>
Cc: James Morse <james.morse@arm.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Link: https://lkml.kernel.org/r/20190514104838.15065-1-rrichter@marvell.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/edac/edac_mc.c