From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAD9CC4646C for ; Tue, 25 Jun 2019 03:20:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 903072077C for ; Tue, 25 Jun 2019 03:20:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730273AbfFYDUn (ORCPT ); Mon, 24 Jun 2019 23:20:43 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:19474 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728020AbfFYDTg (ORCPT ); Mon, 24 Jun 2019 23:19:36 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5P391cb040580 for ; Mon, 24 Jun 2019 23:19:34 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2tb7x0q9he-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 24 Jun 2019 23:19:34 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Jun 2019 04:19:31 +0100 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 25 Jun 2019 04:19:22 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x5P3JLsx37486936 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Jun 2019 03:19:21 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 14F5D52052; Tue, 25 Jun 2019 03:19:21 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6C31F5204F; Tue, 25 Jun 2019 03:19:20 +0000 (GMT) Received: from adsilva.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 25523A021C; Tue, 25 Jun 2019 13:19:19 +1000 (AEST) From: "Alastair D'Silva" To: alastair@d-silva.org Cc: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , Dan Carpenter , Karsten Keil , Jassi Brar , Tom Lendacky , "David S. Miller" , Jose Abreu , Kalle Valo , Stanislaw Gruszka , Benson Leung , Enric Balletbo i Serra , "James E.J. Bottomley" , "Martin K. Petersen" , Greg Kroah-Hartman , Alexander Viro , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , David Laight , Andrew Morton , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fbdev@vger.kernel.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 1/7] lib/hexdump.c: Fix selftests Date: Tue, 25 Jun 2019 13:17:20 +1000 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190625031726.12173-1-alastair@au1.ibm.com> References: <20190625031726.12173-1-alastair@au1.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19062503-0016-0000-0000-0000028C0D9B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19062503-0017-0000-0000-000032E97D2E Message-Id: <20190625031726.12173-2-alastair@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-25_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=918 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906250024 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Alastair D'Silva The overflow tests did not account for the situation where no overflow occurs and len < rowsize. This patch renames the cryptic variables and accounts for the above case. The selftests now pass. Signed-off-by: Alastair D'Silva --- lib/test_hexdump.c | 48 +++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 5144899d3c6b..bef97a964582 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -163,45 +163,53 @@ static void __init test_hexdump_overflow(size_t buflen, size_t len, { char test[TEST_HEXDUMP_BUF_SIZE]; char buf[TEST_HEXDUMP_BUF_SIZE]; - int rs = rowsize, gs = groupsize; - int ae, he, e, f, r; - bool a; + int ascii_len, hex_len, expected_len, fill_point, ngroups, rc; + bool match; total_tests++; memset(buf, FILL_CHAR, sizeof(buf)); - r = hex_dump_to_buffer(data_b, len, rs, gs, buf, buflen, ascii); + rc = hex_dump_to_buffer(data_b, len, rowsize, groupsize, buf, buflen, + ascii); /* * Caller must provide the data length multiple of groupsize. The * calculations below are made with that assumption in mind. */ - ae = rs * 2 /* hex */ + rs / gs /* spaces */ + 1 /* space */ + len /* ascii */; - he = (gs * 2 /* hex */ + 1 /* space */) * len / gs - 1 /* no trailing space */; + ngroups = rowsize / groupsize; + hex_len = (groupsize * 2 /* hex */ + 1 /* spaces */) * ngroups + - 1 /* no trailing space */; + ascii_len = hex_len + 2 /* space */ + len /* ascii */; + + if (len < rowsize) { + ngroups = len / groupsize; + hex_len = (groupsize * 2 /* hex */ + 1 /* spaces */) * ngroups + - 1 /* no trailing space */; + } - if (ascii) - e = ae; - else - e = he; + expected_len = (ascii) ? ascii_len : hex_len; - f = min_t(int, e + 1, buflen); + fill_point = min_t(int, expected_len + 1, buflen); if (buflen) { - test_hexdump_prepare_test(len, rs, gs, test, sizeof(test), ascii); - test[f - 1] = '\0'; + test_hexdump_prepare_test(len, rowsize, groupsize, test, + sizeof(test), ascii); + test[fill_point - 1] = '\0'; } - memset(test + f, FILL_CHAR, sizeof(test) - f); + memset(test + fill_point, FILL_CHAR, sizeof(test) - fill_point); - a = r == e && !memcmp(test, buf, TEST_HEXDUMP_BUF_SIZE); + match = rc == expected_len && !memcmp(test, buf, TEST_HEXDUMP_BUF_SIZE); buf[sizeof(buf) - 1] = '\0'; - if (!a) { - pr_err("Len: %zu buflen: %zu strlen: %zu\n", - len, buflen, strnlen(buf, sizeof(buf))); - pr_err("Result: %d '%s'\n", r, buf); - pr_err("Expect: %d '%s'\n", e, test); + if (!match) { + pr_err("rowsize: %u groupsize: %u ascii: %d Len: %zu buflen: %zu strlen: %zu\n", + rowsize, groupsize, ascii, len, buflen, + strnlen(buf, sizeof(buf))); + pr_err("Result: %d '%-.*s'\n", rc, (int)buflen, buf); + pr_err("Expect: %d '%-.*s'\n", expected_len, (int)buflen, test); failed_tests++; + } } -- 2.21.0