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 36A0AC433EF for ; Wed, 6 Apr 2022 18:36:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2D10983E15; Wed, 6 Apr 2022 20:36:56 +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="m9pf2qOi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5506F83DCB; Wed, 6 Apr 2022 20:36:54 +0200 (CEST) Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) (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 8CA6F83DCB for ; Wed, 6 Apr 2022 20:36:51 +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-qt1-x829.google.com with SMTP id o15so5898040qtv.8 for ; Wed, 06 Apr 2022 11:36:51 -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=RkM0dsPs9AFo5IQXxVRP1CNsNymzcvpGoBax+wTXWA4=; b=m9pf2qOif7NXK49R3vYaWTyG7arojsuuYul8bGvaCWvT0vbLOiECSZZwXf/3DJ8wBO H3PMZlmuu+k3PRSU+ypRGSqVatXxuQmtQOUMLxDYMQ+c5oQnb7/XLNsAexWDLv603ooI Z6A+mixKIyY3NwyzINIbPugBktQqoFZuMwbrYaNaPDenSg/SghDzVJQFuUaxHX67bDM8 gi1irJFMEy22tVgXbOhPpcMYvTUN6QktsDpKZryLg5Y51vPEBlCbbofqiBOlVkjQ9F9d vYuFGNR/b8UmFkZe/BMtLlUDa2CHpb3U/NF6mD0IBpqZ9P67f9m4R4BsNiaROs/JMwtM piAw== 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=RkM0dsPs9AFo5IQXxVRP1CNsNymzcvpGoBax+wTXWA4=; b=6ZChz6hBWQ4a4MhWGKyUsLOjtPfIvJOp67J5e10Vp+WVoPdb5eitY+YxCY5jsn7eqU X/WDzDY4kY1BiJia0F3hVXZyGjAp/PTBV19EHthYot1J1WvoIltiCsyhubjjKX+LBSGQ NTAys5RT3dBd8dYM9L3fKcFnFqBBTSqz3Fq0g1f7WL39ftizAuN9eRngPFzRrdZ/dVQA RxSPvLjNEaVRHh4wdFZU0Fm7453k1qYA1G2vxhVIuhy8lBuzM9fNuIUJ/bsGbVkxNlAW WmywGEBb+anyLy4ADw9XNKVy1X1/Toqk/80n3j/jzN+gWpTkL89I/u11G9lxfGWF+VeY lxuw== X-Gm-Message-State: AOAM530Ga2JG63e/lXpCPV/Qa6muNBWjdxXzMOdIiK2glcTq48/B4fDm ZSdMq9u4TYUUQEtRdvxq4weJWlN7Iws= X-Google-Smtp-Source: ABdhPJziwyQk1zMPiFKauxSXot68qUrWsEaaekJWyJg/kJ/vz08Nk7MSOthnUAfY2WtOIz1ah9DlaQ== X-Received: by 2002:a05:622a:246:b0:2e1:eb3e:4ea1 with SMTP id c6-20020a05622a024600b002e1eb3e4ea1mr8506464qtx.592.1649270210257; Wed, 06 Apr 2022 11:36:50 -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 i184-20020a37b8c1000000b00699fa585088sm155752qkf.46.2022.04.06.11.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 11:36:49 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Andrew Scull , Andy Shevchenko , Simon Glass , Sean Anderson Subject: [PATCH v2] IOMUX: Fix access past end of console_devices Date: Wed, 6 Apr 2022 14:36:35 -0400 Message-Id: <20220406183636.1004612-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 Reviewed-by: Andrew Scull --- Changes in v2: - Put each clause of the for loop on its own line include/iomux.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/iomux.h b/include/iomux.h index 37f5f6dee6..35caa697eb 100644 --- a/include/iomux.h +++ b/include/iomux.h @@ -24,10 +24,10 @@ 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]) +#define for_each_console_dev(i, file, dev) \ + 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