Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6158100yba; Tue, 14 May 2019 02:45:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHjb+uoGKzqMxAXFsuexq0gRHLGpyUJjaBbTmQvArS8wkKZPXdvmTTGfcd5eJecgV43iKq X-Received: by 2002:a62:4607:: with SMTP id t7mr40270538pfa.138.1557827142842; Tue, 14 May 2019 02:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557827142; cv=none; d=google.com; s=arc-20160816; b=ByONMXSLvP0JCkB6v0tJhqAUodIHBq+r3koU8BgmGC7CQGkzohXNwjun5RzZa8LaNo o2f1qTBa2gRkSb1Yo/gYBij8LAQqZuCT6/wHeKPTlSexwUhlKPH4dX+dfWZSDW9G2yYw jJ8PxrQnbMGwrNRepCuwI9nXsUq1m/ynU8u5xAzD9H8GaS6NyPDsuxTasIRKVKG5wSiX XstViTAjONmffX+gJ/gOLvwCU59uWiJhFaEJL4fjVzC7qcneUupsFkp3s23MTpVvWB3F DkbT+7vSMBQ1VT4dBylxK8GWhpq1ezQXT1yfWFlrAThgK2H+jfL9q0J6eYKOwznJHfdY GwhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+E5lh96Wa9iAgQ7eR2jPUVYeIwVyby6z2wH0NC4hJag=; b=yGsxfv8DS5OpROaxeYQqaKSCHHGn/BrtKIKNzJPVvaq0BiplqDBYCAbk9QYzHjLCut puYGY0qE7TAHl5eHqxDco0B7uEiDoDSsPTZRgs83qUeimwU+qSp+1gA8CzFQMBzq8rrF AXcHOCA4yANhIt9f8eGdtyVJIJ5gYL7nUYeFNub664GdIEr4/uVoI3IwNIq+54B+EesJ zoy+chIMBRdTZAWyhIDlw3M+6u9nEzOrkkD5lfKTijarOs1drlSi0Mx1sTPVvrU4kzne y5MX039R2GoaHVJ70+C3PgSA5fxwaKv+83doaRnEQ7hMfIZG3cMeucUVq5HJsHJNYQzq Jv9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=Loj+YPx+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e8si19762021pgs.308.2019.05.14.02.45.27; Tue, 14 May 2019 02:45:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=Loj+YPx+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726466AbfENJnZ (ORCPT + 99 others); Tue, 14 May 2019 05:43:25 -0400 Received: from mail.skyhub.de ([5.9.137.197]:57444 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbfENJnY (ORCPT ); Tue, 14 May 2019 05:43:24 -0400 Received: from zn.tnic (p200300EC2F29E5000DF69AC748EB6F4C.dip0.t-ipconnect.de [IPv6:2003:ec:2f29:e500:df6:9ac7:48eb:6f4c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id A7A3A1EC0A6C; Tue, 14 May 2019 11:43:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1557827002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=+E5lh96Wa9iAgQ7eR2jPUVYeIwVyby6z2wH0NC4hJag=; b=Loj+YPx+Ulf7wwk9slTNr9YVy0suTLXN3qw8ea0NQYVS2tnVSgSy0KVLwZRsn40AnYsi46 Ksjcn6R/bGJ3Wc6FjskIG0Dd20zv6wWDnPZ9SugRvLM8CSUn/wFAU48mxxR9PLv82LnSpS pOiE1QMCuPBlVYHo1F2hoHhgL0Vas3U= Date: Tue, 14 May 2019 11:43:17 +0200 From: Borislav Petkov To: Robert Richter Cc: Mauro Carvalho Chehab , James Morse , "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] EDAC, mc: Fix edac_mc_find() in case no device is found Message-ID: <20190514094317.GB31140@zn.tnic> References: <20190514072514.312-1-rrichter@marvell.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190514072514.312-1-rrichter@marvell.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 14, 2019 at 07:25:58AM +0000, Robert Richter wrote: > 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. This patch fixes this. > > 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. > > Fixes: c73e8833bec5 ("EDAC, mc: Fix locking around mc_devices list") > Signed-off-by: Robert Richter > --- > drivers/edac/edac_mc.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c > index 13594ffadcb3..aeeaaf30b38a 100644 > --- a/drivers/edac/edac_mc.c > +++ b/drivers/edac/edac_mc.c > @@ -688,10 +688,9 @@ struct mem_ctl_info *edac_mc_find(int idx) > mci = list_entry(item, struct mem_ctl_info, link); > > if (mci->mc_idx >= idx) { > - if (mci->mc_idx == idx) { > - goto unlock; > - } > - break; > + if (mci->mc_idx != idx) > + mci = NULL; > + goto unlock; > } > } Can we simplify this silly code even more pls? I'm pasting the whole function instead of a diff for clarity: --- struct mem_ctl_info *edac_mc_find(int idx) { struct mem_ctl_info *mci = NULL; struct list_head *item; mutex_lock(&mem_ctls_mutex); list_for_each(item, &mc_devices) { mci = list_entry(item, struct mem_ctl_info, link); if (mci->mc_idx == idx) goto unlock; } mci = NULL; unlock: mutex_unlock(&mem_ctls_mutex); return mci; --- Thx. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.