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 Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B655C433F5 for ; Sun, 3 Apr 2022 10:41:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 566CB83B39; Sun, 3 Apr 2022 12:39:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com 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=google.com header.i=@google.com header.b="KC/Hwq+p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 38A1F83B1B; Sun, 3 Apr 2022 12:39:39 +0200 (CEST) Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) (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 8BBAF83B0D for ; Sun, 3 Apr 2022 12:39:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3ZHlJYgYKBpUzH1JAA5DD5A3.1DBJ-0DDIA7HIH.23CM.23@flex--ascull.bounces.google.com Received: by mail-wm1-x349.google.com with SMTP id 189-20020a1c02c6000000b0038e6c4c6472so1197807wmc.1 for ; Sun, 03 Apr 2022 03:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XY19rbYy5Na9eu34xV/J/vOnFEnBGCOhXE6xWKTVtns=; b=KC/Hwq+pqYqYR79vQhmQR6SOavidew2YYMb6+1P0jFRpSCPMoJtbMnG3iqtINhluOE NOpLrNgZbK3CfhCOKS4l9jHN3EAY9LyfXJaJqmHQPcUf2wtQPiNXhuY4riKOL0BHnTIT tttAH6sapCtB/yWVxDQcone+6TQ0uHVxEkVWGEd+o1XjXAqhlT0VTePmxWyENoSVmXFJ 9gQbfQqdtnpDck67EfXBgMacPswStNSRLSPs+VwGAeveXLJdm/bUsrpLSYynlTduRYdR LKT4fT3w9/qDd+DkMot7D7ZcNlhmXjtEZwj4mX14aBjDKmPVkUfvKn9Yg0ZSjb1SLnrS /3Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XY19rbYy5Na9eu34xV/J/vOnFEnBGCOhXE6xWKTVtns=; b=1SxZnnRTLg7hTgCT8IKddiqYjzqftItsma3vCIJ8Idi4hieMrRa4bhrT4TymuGaAg9 fkLNReBlEwkzG8ljwGrHlOpIFKKX6eF+IW60RbWkvEcY09vZEVknpNnII1OFDbc9gRQl Tq0ovAN5666XfyNY3nzgd9D6LFlwucCCuMSrwlfRBjKviAdv3u56enwRB+Svt9t1lSRS dqNkNig4/EFAiXQeO4vSML+tT0U/vPjpcxOpkqA1QnSPgZAGOXHLd8jcjsjdvKCS3s9E 70gt0AKn4Qds84wg4bNibyaYz/wEhPv1+tBAt83G4+aqZnx9lVttKiajU1XV8XsxiH9Z H30Q== X-Gm-Message-State: AOAM532rw/xwMFqZe4jrNZ/Yg/M3L8HhegBNQ8L0MqFdRu0hnPWuDxW5 K9z4sqaG8USbb3L+74yjCPw1zdb5DmYz7LgX5ipZb9/TLasm0d00guCioy1WdpTXlCk3XTnZNP+ BbcerwfRk04ChKoF9pjRdt4GF+rd8Z30/efNNOTVw0Ate15KTquK1FWfx88I= X-Google-Smtp-Source: ABdhPJzIv9wxoLvG7PKMVZjA5RKlqe/lZp/Ync6xW2OiHjJXmHw8UTOPaKzjhpyDxDM6BH4vn2y07686bfI= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:1c11:b0:38b:4924:9a77 with SMTP id j17-20020a05600c1c1100b0038b49249a77mr834760wms.0.1648982372810; Sun, 03 Apr 2022 03:39:32 -0700 (PDT) Date: Sun, 3 Apr 2022 10:39:14 +0000 In-Reply-To: <20220403103915.3338027-1-ascull@google.com> Message-Id: <20220403103915.3338027-8-ascull@google.com> Mime-Version: 1.0 References: <20220403103915.3338027-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH 7/8] test: Fix pointer overrun in dm_test_devm_regmap() From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, seanga2@gmail.com, Andrew Scull , Heinrich Schuchardt , Jean-Jacques Hiblot , Pratyush Yadav Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.5 at phobos.denx.de X-Virus-Status: Clean This tests calls regmap_read() which takes a uint pointer as an output parameter. The test was passing a pointer to a u16 which resulted in an overflow when the output was written. Fix this by following the regmap_read() API and passing a uint pointer instead. Signed-off-by: Andrew Scull Cc: Simon Glass Cc: Heinrich Schuchardt Cc: Jean-Jacques Hiblot Cc: Pratyush Yadav --- test/dm/regmap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/dm/regmap.c b/test/dm/regmap.c index 04bb1645d1..8560f2afc2 100644 --- a/test/dm/regmap.c +++ b/test/dm/regmap.c @@ -286,8 +286,7 @@ U_BOOT_DRIVER(regmap_test) = { static int dm_test_devm_regmap(struct unit_test_state *uts) { int i = 0; - u16 val; - void *valp = &val; + uint val; u16 pattern[REGMAP_TEST_BUF_SZ]; u16 *buffer; struct udevice *dev; @@ -311,7 +310,7 @@ static int dm_test_devm_regmap(struct unit_test_state *uts) ut_assertok(regmap_write(priv->cfg_regmap, i, pattern[i])); } for (i = 0; i < REGMAP_TEST_BUF_SZ; i++) { - ut_assertok(regmap_read(priv->cfg_regmap, i, valp)); + ut_assertok(regmap_read(priv->cfg_regmap, i, &val)); ut_asserteq(val, buffer[i]); ut_asserteq(val, pattern[i]); } @@ -319,9 +318,9 @@ static int dm_test_devm_regmap(struct unit_test_state *uts) ut_asserteq(-ERANGE, regmap_write(priv->cfg_regmap, REGMAP_TEST_BUF_SZ, val)); ut_asserteq(-ERANGE, regmap_read(priv->cfg_regmap, REGMAP_TEST_BUF_SZ, - valp)); + &val)); ut_asserteq(-ERANGE, regmap_write(priv->cfg_regmap, -1, val)); - ut_asserteq(-ERANGE, regmap_read(priv->cfg_regmap, -1, valp)); + ut_asserteq(-ERANGE, regmap_read(priv->cfg_regmap, -1, &val)); return 0; } -- 2.35.1.1094.g7c7d902a7c-goog