From patchwork Tue May 14 07:25:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 164114 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2287919ili; Tue, 14 May 2019 00:26:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFlYinegNOMdTW5/trGcNKFVdGMiofvphJDdyi0OQ8uIWS16VlB3KBWYi6sUTFVjFrg+g7 X-Received: by 2002:a17:902:a5ca:: with SMTP id t10mr22877101plq.98.1557818779317; Tue, 14 May 2019 00:26:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557818779; cv=none; d=google.com; s=arc-20160816; b=loKYXvcjLbTx/FkVqRy1wGBmSiywUok3dr6LCspxbzBwUfbK1DTxtijtfO4MfwzJGJ paESDJ9GY7hqPvDmRe40E+A/tDHl3eKfnH6D7iHbrqZyOSHdUtOgcJvTMxrplvEmgAHU TGWJfxTk4FjKhg7OnNEdV1iynXYBf1Cw68muNFF/8fH+pSRll81+Ngi69TMbYdZPMQpK wuYj3L/diB2jOz06D9Eu12R07H1AzslyGiGgurlwo9SjE1jBKM4jXPpavaoAzfTfcnjq oTo61hBT2EMRMw1OW3TAiG6nXrjysD0psSoD2jaLD9aqfTeSc/uOoSLGxSEyt3BFXl7R UWkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature:dkim-signature; bh=lJDALEBoXZOxu7jdHp+EtBTiZcrrDMVR/lTDNVXUQT4=; b=QqYK7FGgBoP5rNkCraJqiQIObta4K1KoEWZgmZu1yFBCsXch0AeeKROOpSSJwC/oEf 1JkyFsRo7P4I2t+T3QAkNxvX27j+RfaejUR1bqpM76nb2Lp3yFhpDSJ4e/gVThflNwes IvhGjAA2IFEM/a5zVC6r5tcZNjzyTYlmBLT56VB2FKGlKzyvuMvoSvN9kbj4vEwQUD4i 3d4gicCVrh6/p+8qJVrMukmYVO/wAyasPkWQv4f/hdwQ+2w/XjQ887OzgTe5KLqpo/uo eDRM5HRi3m9vyC8idyav5SXJlDoRTYVSKvYBgLq4Z3H9Yr7eUq/Vcs3PbnU/cDb/X/Do kYMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0818 header.b=cOPqymd1; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector2-marvell-onmicrosoft-com header.b=G5ztEwwU; 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=marvell.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p188si20863581pfp.112.2019.05.14.00.26.19; Tue, 14 May 2019 00:26:19 -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=@marvell.com header.s=pfpt0818 header.b=cOPqymd1; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector2-marvell-onmicrosoft-com header.b=G5ztEwwU; 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=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726619AbfENH0R (ORCPT + 30 others); Tue, 14 May 2019 03:26:17 -0400 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:57802 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726335AbfENH0R (ORCPT ); Tue, 14 May 2019 03:26:17 -0400 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4E7JlDQ029523; Tue, 14 May 2019 00:26:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=lJDALEBoXZOxu7jdHp+EtBTiZcrrDMVR/lTDNVXUQT4=; b=cOPqymd1+c6o0Cljb/Oqll7wTnYxu7OG8zriC+SyZ837jwMSUOwGcLL8zRfQcvkvM3ns E+iC6JikMjfGzJjrg/vLAxH9i/VAA8O/10r6skUea2a6aeBrQeXdH4/9ZlkJZsRyh2QM iN3hKknvjowlKcVHTwtfnkz/YOrDh3qkqrGJ7CVAUv+md9kt7M6olLo+85EBhfr0sNS4 iZZXHUP+rSrwa1w/Gv8drTVuiw0kAGUFE7PnYdF8qgcVZJgO10oj8e7pR3ZGNpkRD64s WSVdYnDyQpH7bGgazF2dvgqvOUxKEYpE88iOkwXj1RmqngvtSnte+Yr0WPmNXc/1tzHG pQ== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0a-0016f401.pphosted.com with ESMTP id 2sfppxgn9v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 14 May 2019 00:26:03 -0700 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 14 May 2019 00:26:02 -0700 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (104.47.34.50) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Tue, 14 May 2019 00:26:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector2-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lJDALEBoXZOxu7jdHp+EtBTiZcrrDMVR/lTDNVXUQT4=; b=G5ztEwwUJcfqqvByQf0F8eb+wm36SXB2Nprn9RbBO/t0sRDojZHj/RKzDKNKE/M8/06tLOtFU5opgwYjcvwIbqH8QibxEyi0EzcVcEGih0jIFy6ocBLXhh65TFeGm7OjG6vWMPM+Bl40BqQuArb8X9vUMXb31FmfiWGIuXwz8nQ= Received: from MN2PR18MB3408.namprd18.prod.outlook.com (10.255.238.217) by MN2PR18MB3360.namprd18.prod.outlook.com (10.255.238.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.16; Tue, 14 May 2019 07:25:58 +0000 Received: from MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::7147:4fd1:1542:6b30]) by MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::7147:4fd1:1542:6b30%4]) with mapi id 15.20.1878.024; Tue, 14 May 2019 07:25:58 +0000 From: Robert Richter To: Borislav Petkov , Mauro Carvalho Chehab , James Morse CC: Robert Richter , "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH] EDAC, mc: Fix edac_mc_find() in case no device is found Thread-Topic: [PATCH] EDAC, mc: Fix edac_mc_find() in case no device is found Thread-Index: AQHVCiZGzxn6C4ySO0ahQavpHnPilw== Date: Tue, 14 May 2019 07:25:58 +0000 Message-ID: <20190514072514.312-1-rrichter@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR0502CA0017.eurprd05.prod.outlook.com (2603:10a6:209:1::30) To MN2PR18MB3408.namprd18.prod.outlook.com (2603:10b6:208:16c::25) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [78.54.174.73] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d6d1849c-6e33-4b26-a006-08d6d83d6875 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328)(7193020); SRVR:MN2PR18MB3360; x-ms-traffictypediagnostic: MN2PR18MB3360: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0037FD6480 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(136003)(346002)(39860400002)(366004)(199004)(189003)(26005)(68736007)(6512007)(36756003)(53936002)(54906003)(110136005)(6486002)(2906002)(316002)(6436002)(4326008)(8676002)(25786009)(50226002)(478600001)(14454004)(81156014)(81166006)(8936002)(52116002)(305945005)(66066001)(1076003)(186003)(6506007)(386003)(476003)(2616005)(99286004)(6116002)(3846002)(486006)(102836004)(5660300002)(66556008)(66946007)(64756008)(66476007)(73956011)(66446008)(4744005)(71200400001)(71190400001)(86362001)(256004)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB3360; H:MN2PR18MB3408.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: oLpryPEL+8c99J4xPKAYccuXG9ythC0RS+6iNCtrGznm0cngYXHKThBSoH8UQXgoeFW4tTpSBY34eyOPGmjdrC1lcp+aEk1WkTazVoCSwCmH28khnhmlkwM+LaN0widMF680GMzj2RemjTSLfFB2Cv9J++RLSyP4tmsEnhPI8pNHbhlrTjtmL5VI5jTuGuUzeKDSo5/W8knXDhhTaLcS7FOu3Jine4pc4Gk3xrz/1om9+COc/xlE0TH258IemlGwCjXSWlzr7TMLuKWBvFIfW8V4BgXxE8Yo2KMqORi0gLyjSBqOSxz6z2XQXqFlIgjyxfavYxo6thGiNkx/CUuMfejGNJwBLWD9908xegogMsNGZ2AHM4JS+URnEFbY+lNHYDgunvi1Cs2632DEiN4henI+0lxaWBO/IU9insJ9T4Y= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: d6d1849c-6e33-4b26-a006-08d6d83d6875 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 May 2019 07:25:58.1140 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB3360 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-05-14_04:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.20.1 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; } }