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 B9832C433F5 for ; Wed, 30 Mar 2022 16:49:38 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2B687840F8; Wed, 30 Mar 2022 18:49:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="ZStesNuq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F273684101; Wed, 30 Mar 2022 18:49:34 +0200 (CEST) Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) (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 42C99840EB for ; Wed, 30 Mar 2022 18:49:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x734.google.com with SMTP id p25so17094816qkj.10 for ; Wed, 30 Mar 2022 09:49:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=g+KSoFxQAh4ZihsDMX3p0CEJIZmH3P/XHocoLVuTeH4=; b=ZStesNuqHhJ6xwwpjvTFO1yE1fypCU5NwgvVR0R3hcdBDmHY3/g5J9FN18IvLeeSrO SX3NrQiYZTzwbBVECOHzWpQYBI0O5PlOop4g6qQRa6BeUywCM7yMKszIOjkpcyk0nCMU Qw2RIwpLdQ0Ns1wItLFSsNOXxk4ZVWpNIbrIfJkidYH3O+yKIrNzk6YSiWtLOkRgxjB5 bRTKwvWpfP1RasZiH7DEBQstClMtWD2NgMtk92I1Vrqchwjva7Lc9t4qFp8TOflpeRYR 3Mt70UUEs2KWXKAH78RXD4EhJI9kw/0ODhyEj/AcT/OS1P5riduQPYm6ZfSq1r8802po ysvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=g+KSoFxQAh4ZihsDMX3p0CEJIZmH3P/XHocoLVuTeH4=; b=o7VM9koCzO+nkOjbFRpMzPx/hCUFByr0DvwrQEOXBDOIrkNCmcyGemQvNyMr+Vhbho gqoNhFpwsddTMisxwzGukG4rCnqOaLzWI0uHdBtHRJZ2zf9innvwu3d0N+LtopmEEAzS +SaPIyStCNMDpyx7BUi2UVSsd1V5YvsZsMZpnoYeUnA1ZNcXWmV2ou8YSbZKmr6GofIO oGgA2GZYDmsWJVCF5dHFSHsAha9CEnkQdMcoXDF+lxzd1WcAC+/y4RH6Q021gDB9rmAB UW9wLIGpcdID/DGyB1vQxL3rTwYMsaBAoA09IRDBerBvngVwGU/sEnX3KLYn7HmBM5HT oAaw== X-Gm-Message-State: AOAM531QbEADSVxro0oRi0eOpq089ig16usQ8lNnQqUKgj+qLIpaRSc5 9qg3OH7vL2+TFeAVh+8niekMuflDyj0= X-Google-Smtp-Source: ABdhPJz+qSutOj+FCxzvYkDhz5bVUwSgRweyEsx3yHyUttnNx+s4tze9zEt4L2y0/27yvUDoCAefBw== X-Received: by 2002:a05:620a:bce:b0:662:e587:fbbf with SMTP id s14-20020a05620a0bce00b00662e587fbbfmr366123qki.757.1648658958800; Wed, 30 Mar 2022 09:49:18 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-18-137-133.washdc.fios.verizon.net. [108.18.137.133]) by smtp.gmail.com with ESMTPSA id d28-20020a05620a205c00b0067d154026bdsm11118840qka.29.2022.03.30.09.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 09:49:18 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Andy Shevchenko , Sean Anderson Subject: [PATCH] IOMUX: Fix access past end of console_devices Date: Wed, 30 Mar 2022 12:49:02 -0400 Message-Id: <20220330164902.431732-1-seanga2@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 We should only access console_devices[file][i] once we have checked that i < cd_count[file]. Otherwise, we will access uninitialized memory at the end of the loop. console_devices[file][i] should not be NULL, but putting the assignment in the loop condition allows us to ensure that i is checked beforehand. This isn't a bug, but it does make valgrind stop complaining. Fixes: 400797cad3 ("IOMUX: Split out for_each_console_dev() helper macro") Signed-off-by: Sean Anderson --- include/iomux.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/iomux.h b/include/iomux.h index 37f5f6dee6..1046df133b 100644 --- a/include/iomux.h +++ b/include/iomux.h @@ -25,9 +25,8 @@ extern struct stdio_dev **console_devices[MAX_FILES]; extern int cd_count[MAX_FILES]; #define for_each_console_dev(i, file, dev) \ - for (i = 0, dev = console_devices[file][i]; \ - i < cd_count[file]; \ - i++, dev = console_devices[file][i]) + for (i = 0; i < cd_count[file] && \ + (dev = console_devices[file][i]); i++) int iomux_match_device(struct stdio_dev **, const int, struct stdio_dev *); int iomux_doenv(const int, const char *); -- 2.35.1