From patchwork Fri May 1 14:55:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1281348 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=a/QSSoVB; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49DFgN2b0Pz9sRY for ; Sat, 2 May 2020 00:56:00 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 40A4E822A7; Fri, 1 May 2020 16:55:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="a/QSSoVB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0869F82291; Fri, 1 May 2020 16:55:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0727.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::727]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C0E17821FC for ; Fri, 1 May 2020 16:55:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f584meiq05/pyvYHoV+RD+ToGwh6n6hZaIIxqOBVASb+WufXthAmXvrDmiGCR5BYbZkYPKK7IFyFo0DMfe3yew7N1Sngcy60Z2vohvX5fjVsgNRLltt7ejNkkQTZiBNTtbUc66ACc0OpVJyzIujO/KqZGDa08guHp5fXYuOC4ZPMharYdbLrlArffk2Fr4Dx67sM8im88p/rGrHL8qYDrWcvyL15RnqIeAq5Uo8o5m1ZhQIUgmsFH7ey+DddHvaHtzcLAOOOORU5ybSTQrixpNgsMgeTV9zqq01ulbVH0EEVQElGsNl7a5/f63anZGUHU5xtbXZjQtDi1MlI4AFsUA== 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=IuvgCsjOetG/DFnkDnxoxjin+bCVu/z0FUBkqn9Zf3M=; b=XyR/Emer3uNWviGFcR/e3jAbeTwUixv6l5+RRkXb4Km8YfqtDXZUCx13pFrFgwaEu39Wtlt6/3+Q9dK95YY4u+CSwbM3z64TwE0Syht6LryHsAQUP3Q7/lH2aaxHy7QxoN2QngWwxSg1gI9eTQce2uAYYzfE49aPtwPKIE4ZYQf7btYVncw7cv2AfqmoxQYA+KjbE0MmbB0NMsN/3vNEt+GqpeAQ9uMNJAim3CXeO4HaYkAAB6ahS8AudRcV631ZQJssmF2kK32VBbkh5sqCBfE3knnXG3hVhcf23LBTGXHVWdDSIpWHWQKeGtWY5rYV3wY+a7iRNmb3FO/csL4A0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IuvgCsjOetG/DFnkDnxoxjin+bCVu/z0FUBkqn9Zf3M=; b=a/QSSoVBsKUqSAaNEf+N/grHBQ0IuOFgqe0GetJXZdwdimNXZlQwcvuACxrp3MR1YzYyxnIPxmXkxg80A4oE/S1ZtCqRcSxF0dn7vZn7d7gdFFdbS0uSnWUP6Cd7KVCHix/RrSjAmVkrAnhIJFxoVWqgyf4qfegBr0NTvqg8QoU= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) by VI1PR10MB1967.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:32::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.27; Fri, 1 May 2020 14:55:26 +0000 Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::f0ac:4e97:2536:faa]) by VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::f0ac:4e97:2536:faa%7]) with mapi id 15.20.2958.020; Fri, 1 May 2020 14:55:26 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Mario Six , Bin Meng , Urja Rannikko , Rasmus Villemoes Subject: [PATCH 1/5] sysreset: mpc83xx: use scnprintf instead of snprintf Date: Fri, 1 May 2020 16:55:12 +0200 Message-Id: <20200501145516.18168-2-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200501145516.18168-1-rasmus.villemoes@prevas.dk> References: <20200501145516.18168-1-rasmus.villemoes@prevas.dk> X-ClientProxiedBy: AM6PR0502CA0065.eurprd05.prod.outlook.com (2603:10a6:20b:56::42) To VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (5.186.116.45) by AM6PR0502CA0065.eurprd05.prod.outlook.com (2603:10a6:20b:56::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2958.20 via Frontend Transport; Fri, 1 May 2020 14:55:26 +0000 X-Mailer: git-send-email 2.23.0 X-Originating-IP: [5.186.116.45] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 78f93e5a-7ce0-4d15-fb41-08d7eddfaef9 X-MS-TrafficTypeDiagnostic: VI1PR10MB1967: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:378; X-Forefront-PRVS: 0390DB4BDA X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 99Dr/TOmi17Ytzqf87doE+VhZoc5AzvrgluQ+TsoCt8QyZ+JRwLZJcI7v7ATVIq5PLCPCq7FWS/Q4EHP55I8ENVqsb6H3bV0VzDH6GdQOcUPs5OA9qchb3hK3NXj+UZAeQjBn/mmReBhSuVIgOsnzFYyAfl9nOzHSLSBJVqL56J2IfrgBtLBIVHJHTLQQjCeRXCDu4QOjTJ0acvlvofyfuqTO2JpGAnUlWSsoVBjdAuF8hBRPVgr2SsjAXYUmABI8K1TWZxCa4ZgGaTAFZCs1dAm5DNExbw81VEJB6V/dy2mPbStYS7aR3OpsW5waj2k8ZR62MYXIVJXAO+RtMr9Y43WGnU2UDrxZfwbpyvnvywlU5yxxqN9iEJ+Ma7McNkG/I8c+Xq4U+hGUiJP4OaeZF7iYkcvMo4pG9N3rwYZSbbns8YO36tf5AL6ZEW0wT2X X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFTY:; SFS:(396003)(376002)(39840400004)(136003)(346002)(366004)(52116002)(66946007)(8676002)(66556008)(66476007)(26005)(186003)(6486002)(6666004)(16526019)(316002)(6506007)(2906002)(54906003)(86362001)(107886003)(6916009)(8976002)(8936002)(4326008)(6512007)(478600001)(2616005)(44832011)(1076003)(36756003)(956004)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: oRCyarUyxRyVFiulDJ6XlWs7aC75s/L+NSw76rXRylrmcKkO8qumhHHP7sp6EZBigsGNElDEUGB2Tga+2iR1LmsbEz22+pDfp+u/ZVftIMeW25N+/SVux7X2g5DUOZGYoPY98sLrnyeJ2biRaOm2xjIKOV2wTTd5JvQ32REoKpvihn0XuNLSOq+2a3w4X7dGDnTaphdYWj8YPo0ROxMULNPmLBlFC15S/y6G4u6wznpl2HNChFzb/0SttfpOwXpTDdWxEpZomfTuC7khTZBUN+yZdZyZfAMCLiGb65bAIlEmhQdIeXZ4VVq1xV7a5gCelnGEe74JU7oOHPYVSJBoPswn9mfbuLKJusPQwIROqmKD8keqYnsdcxioaIxRfOWu+mYxirEW159Mgn/mq8bFsGHSIGcm5CVy6sKl7xQ1L6VTx3zJ9jDHiH6cbl5XFPfTgI9btqSyIrSM8/oGMyl2VEvuz5a0uMgp93s1zJvo4KLyZTua7+KsgwV+e8YwwZ+4sBjpRVrsuzqqxGvdcduLAep+oz5DhqGH6kV9lO5KlMfBrXln2ZZeFAW8r2UVn3AKyhMywNIBqB9xJCZ2tAn8AaFJJKWjRw4q3F+AYzBZjpmzPybpOPPPQRtdtFMpepkj/4gIE7rXFBWEkYfRbuIofJTuQv5tbepA1uonsAu78V11Rn+XHfExBdg8CxGlXO1tHuTgVZDASl4xcH15zmSYpGfTcLTOFLvrCB0ls5Ni1AQ1HRDTz6+btlekDHxKJafTFAWC9jF3mrFKk3MTdMRCdmX/94frWe3tlqbpGWAzAEE= X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 78f93e5a-7ce0-4d15-fb41-08d7eddfaef9 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2020 14:55:26.7151 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 739U+F3HGY8xjMv+HkjnC+1kQyVLczegVZoyIdAqmorxb4OdlD3oc5cd5mLoDDcb5Dl0AiF26OiEDCCRln+/O4c2ObHdXPho3CISQT5mmZU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB1967 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean Neither snprintf or scnprintf ever return a negative value, so the error checking is pointless. The correct idiom for printing piecemeal to a buffer of a given size is to use scnprintf(), since that will ensure buf will never point past the actual given buffer, and the remaining size will never become negative (since scnprintf(), when given a non-zero size, has the property that the return value is strictly less than the given size). Signed-off-by: Rasmus Villemoes --- drivers/sysreset/sysreset_mpc83xx.c | 54 ++++++++++------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/drivers/sysreset/sysreset_mpc83xx.c b/drivers/sysreset/sysreset_mpc83xx.c index 9092764e0b..7148464d8b 100644 --- a/drivers/sysreset/sysreset_mpc83xx.c +++ b/drivers/sysreset/sysreset_mpc83xx.c @@ -104,23 +104,23 @@ static int print_83xx_arb_event(bool force, char *buf, int size) return 0; if (CONFIG_IS_ENABLED(CONFIG_DISPLAY_AER_FULL)) { - res = snprintf(buf, size, - "Arbiter Event Status:\n" - " %s: 0x%08lX\n" - " %s: 0x%1x = %s\n" - " %s: 0x%02x = %s\n" - " %s: 0x%1x = %d bytes\n" - " %s: 0x%02x = %s\n", - "Event Address", gd->arch.arbiter_event_address, - "Event Type", etype, event[etype], - "Master ID", mstr_id, master[mstr_id], - "Transfer Size", tsize_val, tsize_bytes, - "Transfer Type", ttype, transfer[ttype]); + res = scnprintf(buf, size, + "Arbiter Event Status:\n" + " %s: 0x%08lX\n" + " %s: 0x%1x = %s\n" + " %s: 0x%02x = %s\n" + " %s: 0x%1x = %d bytes\n" + " %s: 0x%02x = %s\n", + "Event Address", gd->arch.arbiter_event_address, + "Event Type", etype, event[etype], + "Master ID", mstr_id, master[mstr_id], + "Transfer Size", tsize_val, tsize_bytes, + "Transfer Type", ttype, transfer[ttype]); } else if (CONFIG_IS_ENABLED(CONFIG_DISPLAY_AER_BRIEF)) { - res = snprintf(buf, size, - "Arbiter Event Status: AEATR=0x%08lX, AEADR=0x%08lX\n", - gd->arch.arbiter_event_attributes, - gd->arch.arbiter_event_address); + res = scnprintf(buf, size, + "Arbiter Event Status: AEATR=0x%08lX, AEADR=0x%08lX\n", + gd->arch.arbiter_event_attributes, + gd->arch.arbiter_event_address); } return res; @@ -150,13 +150,7 @@ static int mpc83xx_sysreset_get_status(struct udevice *dev, char *buf, int size) int i; char *sep; - res = snprintf(buf, size, "Reset Status:"); - if (res < 0) { - debug("%s: Could not write reset status message (err = %d)\n", - dev->name, res); - return -EIO; - } - + res = scnprintf(buf, size, "Reset Status:"); buf += res; size -= res; @@ -164,13 +158,8 @@ static int mpc83xx_sysreset_get_status(struct udevice *dev, char *buf, int size) for (i = 0; i < ARRAY_SIZE(bits); i++) /* Print description of set bits */ if (rsr & bits[i].mask) { - res = snprintf(buf, size, "%s%s%s", sep, bits[i].desc, + res = scnprintf(buf, size, "%s%s%s", sep, bits[i].desc, (i == ARRAY_SIZE(bits) - 1) ? "\n" : ""); - if (res < 0) { - debug("%s: Could not write reset status message (err = %d)\n", - dev->name, res); - return -EIO; - } buf += res; size -= res; sep = ", "; @@ -187,15 +176,10 @@ static int mpc83xx_sysreset_get_status(struct udevice *dev, char *buf, int size) * event to be printed */ res = print_83xx_arb_event(rsr & RSR_BMRS, buf, size); - if (res < 0) { - debug("%s: Could not write arbiter event message (err = %d)\n", - dev->name, res); - return -EIO; - } buf += res; size -= res; } - snprintf(buf, size, "\n"); + scnprintf(buf, size, "\n"); return 0; }