Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp622652ybz; Wed, 22 Apr 2020 05:01:04 -0700 (PDT) X-Google-Smtp-Source: APiQypLdJLoVEYkfwcOBTnRb/LQtbsUB2+/LRKDRT41BxtDbRZSr3OKgUQGmjDruCFjJNZh9dta1 X-Received: by 2002:a05:6402:1651:: with SMTP id s17mr10501904edx.173.1587556864266; Wed, 22 Apr 2020 05:01:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1587556864; cv=pass; d=google.com; s=arc-20160816; b=HLRAPYEwDESG6vZ7jDhN0HrwmckCjUtXrLv2VmrHcKfsaSP8s2NGWg8Cm9P3yp/a3N Yl3HQUvXaLpWbY3ePfd/pN6LcYb9WXjGuf8+DVd8mu2G1aCaoHlr9sAAoFbI38cKWXvw 6fyGXkL4/vSKT0IEXNqdP7O1ozWDrxkFhz3IF999dIC3Jqt73mbW0d5MpqE37wgNC9HM U03N4qw56TK+0BhI864Xp2366eZ5vLOKNGfD8i49e5f1gVn8RpZ0bLtXLmVEq2UEDGEq sRnAgNr1t/6GF+vu32bHKX5Ggc4RsM5bnUFpskOT0soMs7vSHGLjwFl6//5NAexWtq0M Ai2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=y9OSyDZiDyHUyPp0nql0h+G17NB5aioZk3SV919nq50=; b=aaKm+Kd2JswzGDK7hBRiBtmsWGCpY9EjK5u/WvNH7VxFo1qc3dScCYyNku/4GXkNBk aFewZRV1HqcTgcwiJxZLVlFDNtMDZ1zFkVnEPBuF+vLhUP2ex3IojOUkfCC24J+BYufu /9GQgPcjIbE7RGedm2HKikxPOGp4diV+FlZNEC/r4XrpZTVFDe3YyLAj2znxRxUSC7sf 2jcQNAzEMDe8eHIAe/R+1cz95pQsZMdgHlFFNqh7pf/qVLCkhDFkOeymdeDnbiGKtauK jCI6w5+5JiG09m5qB+ZI9AC5jFxT+hn0ZXlr3GaiyLcVDq8H8PLUvq5JosfahJoDBhO3 yMJQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=temperror (no key for signature) header.i=@marvell.com header.s=pfpt0818 header.b=xAX6UH70; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector1-marvell-onmicrosoft-com header.b=dEZtbG2Z; arc=pass (i=1 spf=pass spfdomain=marvell.com dkim=pass dkdomain=marvell.com dmarc=pass fromdomain=marvell.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=marvell.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si3433227ejk.157.2020.04.22.05.00.40; Wed, 22 Apr 2020 05:01:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@marvell.com header.s=pfpt0818 header.b=xAX6UH70; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector1-marvell-onmicrosoft-com header.b=dEZtbG2Z; arc=pass (i=1 spf=pass spfdomain=marvell.com dkim=pass dkdomain=marvell.com dmarc=pass fromdomain=marvell.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728242AbgDVL7b (ORCPT + 99 others); Wed, 22 Apr 2020 07:59:31 -0400 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:29342 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728203AbgDVL73 (ORCPT ); Wed, 22 Apr 2020 07:59:29 -0400 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03MBpS8v031960; Wed, 22 Apr 2020 04:58:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=pfpt0818; bh=y9OSyDZiDyHUyPp0nql0h+G17NB5aioZk3SV919nq50=; b=xAX6UH70Cabev7GVYwRo8bWikpq3BoCVnMaCCK39yxgdKfW27uJEZgWkWYYlk4uhxSaW F2uDVI0TdYa0W45KO+T7LsS28hvjdfZNFyVMrF1PvGRFdcELMht4s9W7R3DOgjM3E+s3 9JxuWyWI+jnt9cYPAHNPlffqaZ11At+C73e6rQXLLOXnh77cTFbH0qpa0QOxXQG8xp6r cPnbnqouD28gFOywcM620klmUhaSWc5ceQ/pswyTd+lMVhf7KmREz41SRYPj/Xlk9Yri xS6OqOwzVDtypaGV0oqft7V19/711D7v9FKc+HDgeu0zCtg+ITzC4qNzKuVDBb+fi9I+ /A== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 30jd011w43-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 22 Apr 2020 04:58:51 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 22 Apr 2020 04:58:48 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 22 Apr 2020 04:58:48 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.175) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Wed, 22 Apr 2020 04:58:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kg2Ck1YrdoXSYW5MRFUEQ1cGeu2oP9dh5TwgWz8hg+RdrdD4KHMgpA0fL/sOEFQ/Ld3oadw1NNi3fc1M97/ahjzvpj0eII1r793GVzFMvV3QOOlDRQAR7TXSpTaPm//ZZzcgeqa8NXJ8cvyaHNkPbLIM7ZVytS4B5J137DU2xXSoW5cDIiDynF2pR9HmSHEgSAqVHgdwwL6GZDQVHuYJjlTlwIrwxmnboMi+ALNHJZCtY2ubQKZdzGwq0eLRbIb9pc8vCLfRGv3Iq077zzh3DUwADAK7jHfm88Ek1S2Vx+qQ6j7hzbJ7DCLWFprm8+4NRqSfzHWmxO0Uhnc57RR89Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y9OSyDZiDyHUyPp0nql0h+G17NB5aioZk3SV919nq50=; b=c4UMq+0VrJExaoaY5iJA2t1KrIRDgquNu6mZFctgK2lxXq131Pzq7bhvyoOFFpgX2aY52Obmtj5rb2K9r4HMYRrws81URPXnMu/qnz68XYcpIvpOKTFrgWO8hY67+ZqaR8S1/x7zwINc/8P/6TFbCXcPIVQQT+fnWjXvkr4E+EC16QBotFBROjSodjex7FN7MQG1oH/uK/0l30SXRE5qIR6YJBO641XP+BJEdUf1LjIICjm+Aahx3p6ORG+vqkPdLcEI7D6KCo0w7cDXJ6qLcGisAut9XDOuKmGvtTkQlrDrWqbC0cGsVztABCI+1vGgc61bXTFM2DEbTu1Xb0UXjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y9OSyDZiDyHUyPp0nql0h+G17NB5aioZk3SV919nq50=; b=dEZtbG2ZNroHk+H4zbw5yRa9bolAtQIjCbTmdX7DP71ljYSv75E3/akv0jZBDDfmqlMatqNrmRYRP+m4z8o4cVFSFr4xy6Qr7WRcqOvWqENIkwRSuDDd7mRnDm1dNVz+zmF5TK8GItSsZoyUtBCWz5jP8oTYMh+L6QFs0MPggdc= Received: from BYAPR18MB2661.namprd18.prod.outlook.com (2603:10b6:a03:136::26) by BYAPR18MB2566.namprd18.prod.outlook.com (2603:10b6:a03:12f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.27; Wed, 22 Apr 2020 11:58:47 +0000 Received: from BYAPR18MB2661.namprd18.prod.outlook.com ([fe80::a165:ffa5:f3eb:d62d]) by BYAPR18MB2661.namprd18.prod.outlook.com ([fe80::a165:ffa5:f3eb:d62d%7]) with mapi id 15.20.2921.030; Wed, 22 Apr 2020 11:58:47 +0000 From: Robert Richter To: Borislav Petkov , Mauro Carvalho Chehab , Tony Luck CC: James Morse , Aristeu Rozanski , Robert Richter , Matthias Brugger , , Subject: [PATCH v2 01/10] EDAC/mc: Fix usage of snprintf() and dimm location setup Date: Wed, 22 Apr 2020 13:58:05 +0200 Message-ID: <20200422115814.22205-2-rrichter@marvell.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200422115814.22205-1-rrichter@marvell.com> References: <20200422115814.22205-1-rrichter@marvell.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: HE1PR0701CA0076.eurprd07.prod.outlook.com (2603:10a6:3:64::20) To BYAPR18MB2661.namprd18.prod.outlook.com (2603:10b6:a03:136::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from rric.localdomain (31.208.96.227) by HE1PR0701CA0076.eurprd07.prod.outlook.com (2603:10a6:3:64::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.6 via Frontend Transport; Wed, 22 Apr 2020 11:58:44 +0000 X-Mailer: git-send-email 2.20.1 X-Originating-IP: [31.208.96.227] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d475e871-e7b8-4e0e-078b-08d7e6b48368 X-MS-TrafficTypeDiagnostic: BYAPR18MB2566: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:792; X-Forefront-PRVS: 03818C953D X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR18MB2661.namprd18.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(346002)(136003)(376002)(39850400004)(396003)(366004)(6506007)(66556008)(478600001)(2616005)(5660300002)(2906002)(8936002)(6512007)(6666004)(36756003)(16526019)(66476007)(186003)(66946007)(316002)(1076003)(6486002)(4326008)(52116002)(26005)(956004)(110136005)(8676002)(86362001)(81156014)(54906003);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FIehxfIFc1BBnZ58txEHmilfvbESX9A3mA8zGDK5SReVu8J+h67VwpDlaRUsJQOgPunzhD7ViBcp/fCGQg+zNbRr3dp/kgFIn/HkGgejA4cPPNwTqGJCc7MFJ7g5SonkrbfzMqeS4nDWskxckedcnwFAabnnqemHSHVxmC+ultk3CAERCYaPKETxIyxdMg+CyGk/RK0JJ/wTe5nca7fepHd9xIyepy1HDUF/PjFYUkQdf8U+C+5hHeIDemzqnu0EclJsYYspsoJQsHERvWcMBzGawPZ1V3E1rmG8rTR5yOpgKoUNnlsrimQ/o0wJO4gQhd8/549rqObZUKZ89D1f/+exLUe7NwbTh/U3apbnBIr0UL5LkX7bZCxwsb4C96gFslqXw42aHi2foF0qbJaJQvMD+ekHfoaWZAleY7NSuOnAFVwpohbh1mk7/qNCqsCh X-MS-Exchange-AntiSpam-MessageData: UFVznkGtVTcDABCVY9hTxg8yM6ZGdVC1dAl7R4O8zgmf3+3dgdZt5MBduSoeGTPVASNfJtcDWsBPIGxYjtOXA3ziCFT5oiJFXdsJwfNIxMgzbjOj3PcBw52pwVaOecteMS76+Yb4znz0GMqLnDdoOA== X-MS-Exchange-CrossTenant-Network-Message-Id: d475e871-e7b8-4e0e-078b-08d7e6b48368 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2020 11:58:47.2477 (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-CrossTenant-UserPrincipalName: BMP3ZERQVvqLvNHznOtxs96S9BwX7iJ0W2k1EjRf5rBbqbM1TjnQZ6Ks1w8SbFrTYQkYdIZ1+xnEK6JIEzFDuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR18MB2566 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-22_03:2020-04-22,2020-04-22 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The setup of the dimm->location may be incomplete in case writing to dimm->label fails due to small buffer size. Fix this by iterating through all existing layers. Also, the return value of snprintf() can be higher than the number of bytes written to the buffer in case it is to small. Fix usage of snprintf() by either porting it to scnprintf() or fixing the handling of the return code. It is very unlikely the buffer is too small in practice, but fixing it anyway. Signed-off-by: Robert Richter --- drivers/edac/edac_mc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 75ede27bdf6a..107d7c4de933 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -130,11 +130,11 @@ unsigned int edac_dimm_info_location(struct dimm_info *dimm, char *buf, n = snprintf(p, len, "%s %d ", edac_layer_name[mci->layers[i].type], dimm->location[i]); + if (len <= n) + return count + len - 1; p += n; len -= n; count += n; - if (!len) - break; } return count; @@ -397,19 +397,19 @@ static int edac_mc_alloc_dimms(struct mem_ctl_info *mci) */ len = sizeof(dimm->label); p = dimm->label; - n = snprintf(p, len, "mc#%u", mci->mc_idx); + n = scnprintf(p, len, "mc#%u", mci->mc_idx); p += n; len -= n; + for (layer = 0; layer < mci->n_layers; layer++) { - n = snprintf(p, len, "%s#%u", - edac_layer_name[mci->layers[layer].type], - pos[layer]); + dimm->location[layer] = pos[layer]; + if (len <= 1) + continue; + n = scnprintf(p, len, "%s#%u", + edac_layer_name[mci->layers[layer].type], + pos[layer]); p += n; len -= n; - dimm->location[layer] = pos[layer]; - - if (len <= 0) - break; } /* Link it to the csrows old API data */ -- 2.20.1