From patchwork Wed Sep 9 13:02:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralph Siemsen X-Patchwork-Id: 1360622 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=czRUVIZV; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bmhxv1ZwHz9sTN for ; Wed, 9 Sep 2020 23:02:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BAC8C821BF; Wed, 9 Sep 2020 15:02:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="czRUVIZV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C3C228221F; Wed, 9 Sep 2020 15:02:18 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2976A81B79 for ; Wed, 9 Sep 2020 15:02:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ralph.siemsen@linaro.org Received: by mail-qk1-x743.google.com with SMTP id w16so2276335qkj.7 for ; Wed, 09 Sep 2020 06:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QlBwMAKRG6lmnu2/0L53k/TdK/k8G4ONVgJyzs+V4v8=; b=czRUVIZVW9QGWQBMkhrUYsoRx2few+6yF0CazBunYFMmCY/8BVkA4Xy8t4MPYgSkI2 /q/Za6qrXEzBlTYdEMhIAO/btpjuD1AFAOxoUgTEGTsBrLev4v0HfTM8+O4/oskRVbKS Tilww5sSQisg3Q/ADXPXRqONbhQIwdffHGKajZbqkXycf7mAjRxRN3RhOiXy+b7Z4Wv9 irxNtB/vUbxjHSimXo1OAUeUqY1YTHL705q7pw5DdsFyAddtVA6fnud/2NISyV9qYh5r 6cCn1rnWcEAoX1kYPBklRn4qiyneHwJuea6R4kj0G2KQtn5gnAZZFdpeIr/iqtVWFyZN LDLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QlBwMAKRG6lmnu2/0L53k/TdK/k8G4ONVgJyzs+V4v8=; b=NM0l0kDI45B0y1oWhGYgnTOVyaFhb+tad4KVuJWuv9RZKg9usu//gmh2je/ycfIWml Z44nuKc9Kp9nXcoxRBWFZLuRIq7SFgjx4v0l8PPFDYxGmJsTF1k+y21wTmS7euf7W5TO dbCr6tTktBDyTLNSONR/jWX5usqmwVXtc1hYis1sku2gW9z6x/5tGhyfZFm6pk2KSrrg mvPSnSDWZQErVZwqr+CABUr1MwyNJIxU5pSh3ks1G3l1weEKrG/8ZJMbXQMp6mOsH+r5 xwaraZNuf4G0BPKW44n8hArAvqwatyzRt9CG85cYwYqFoZ/dWQ1Xx6CI+3qadVHCzGnm w5eQ== X-Gm-Message-State: AOAM530wm9tewG+ayYUcRGyRUYwG5kHgU7NEO+2cWeCyNJXHcku2+wdJ x6M9aqm5N3PKjSYDJKak5u0NQpNeB3mn8A== X-Google-Smtp-Source: ABdhPJyib8j8GG5TeVMHSaVeLayqrCUZauwEiJa0VrFgNEIu0J/9XI7UuRilVEprzFuBAh4O5bo0qg== X-Received: by 2002:a05:620a:2014:: with SMTP id c20mr2907933qka.89.1599656530363; Wed, 09 Sep 2020 06:02:10 -0700 (PDT) Received: from maple.netwinder.org (rfs.netwinder.org. [206.248.184.2]) by smtp.gmail.com with ESMTPSA id p68sm2492553qkd.124.2020.09.09.06.02.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 06:02:09 -0700 (PDT) From: Ralph Siemsen To: u-boot@lists.denx.de Cc: sr@denx.de, trini@konsulko.com, Ralph Siemsen Subject: [PATCH v2] cmd: mem: fix range of bitflip test Date: Wed, 9 Sep 2020 09:02:01 -0400 Message-Id: <20200909130201.12885-1-ralph.siemsen@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <9c12ad86-531d-8487-997d-fc2edeab4fb4@denx.de> References: <9c12ad86-531d-8487-997d-fc2edeab4fb4@denx.de> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.3 at phobos.denx.de X-Virus-Status: Clean The bitflip test uses two equal sized memory buffers. This is achieved by splitting the range of memory into two pieces. The address of the second buffer, as well as the length of each buffer, were not correctly calculated. This caused bitflip test to access beyond the end of range. This patch fixes the pointer arithmetic problem. A second problem arises because u-boot "mtest" command expects the ending address to be inclusive. When computing (end - start) this results in missing 1 byte of the requested length. The bitflip test expects a count rather than an "ending" address. Thus it fails to test the last word of the requested range. Fixed by using (end - start + 1). Fixes: 8e434cb705d463bc8cff935160e4fb4c77cb99ab ("cmd: mem: Add bitflip memory test to alternate mtest") Signed-off-by: Ralph Siemsen Reviewed-by: Stefan Roese --- Changes in v2: - Minor refactor to reduce line length - Spellcheck and cleanup commit message Change-Id: Ie641d04e731fc5bc6a3bbef914bf7fad136cdc94 --- cmd/mem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index 9b97f7bf69..7bfa93d2a0 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -934,7 +934,7 @@ static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - ulong start, end; + ulong start, end, half_size; vu_long scratch_space; vu_long *buf, *dummy = &scratch_space; ulong iteration_limit = 0; @@ -987,10 +987,11 @@ static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc, if (errs == -1UL) break; count += errs; + half_size = (end - start + 1) / 2 / + sizeof(unsigned long); errs = test_bitflip_comparison(buf, - buf + (end - start) / 2, - (end - start) / - sizeof(unsigned long)); + buf + half_size, + half_size); } else { errs = mem_test_quick(buf, start, end, pattern, iteration);