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 5A858C43217 for ; Thu, 7 Apr 2022 11:06:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 26FB683093; Thu, 7 Apr 2022 13:06:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=linux.intel.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=intel.com header.i=@intel.com header.b="jsiKw+WF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AC0FD83515; Thu, 7 Apr 2022 13:06:16 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7D4578209C for ; Thu, 7 Apr 2022 13:06:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=andriy.shevchenko@linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649329573; x=1680865573; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=MNtFbb/uJ6CJHGoYSGA1hkv0Np2xMxaF7XMafUnDHD8=; b=jsiKw+WFR8tqQXMTVHfLnDnM4zFZsUBOeVNKfoEmK9YRr1MsBff5db7K iOWj6V7DM8In93gHBEUmmMKhqpn+qbrRl+j00EVYLJxbMuNXwM0JDyokq wm3tmLbfzY2xePAFaYXzyrUKb9GolvPqyZVtkWyIzOj9Ls3uV4Xq1wdM4 cj2wXrEWRBIgcrJinL01N/k1zpxJx0gMTobtKlHgeWVBaSgb1WeX7vEq0 6bzZZuN8U5ZqwAuybpsmq+u4C0mbsIBR9Bb94CbMayYsY6Ft1jNBr3xuV 19cCDuDdYEnJfBJunSIrISsG5InMXuYQfej/T009tH9V3Bw1jm49t2U2z A==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="260129025" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="260129025" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 04:06:11 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="588766056" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 04:06:08 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.95) (envelope-from ) id 1ncPwM-000Lku-8Z; Thu, 07 Apr 2022 14:04:38 +0300 Date: Thu, 7 Apr 2022 14:04:38 +0300 From: Andy Shevchenko To: Sean Anderson Cc: u-boot@lists.denx.de, Andrew Scull , Simon Glass Subject: Re: [PATCH v2] IOMUX: Fix access past end of console_devices Message-ID: References: <20220406183636.1004612-1-seanga2@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220406183636.1004612-1-seanga2@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo 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 On Wed, Apr 06, 2022 at 02:36:35PM -0400, Sean Anderson wrote: > 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. Acked-by: Andy Shevchenko > 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 > -- With Best Regards, Andy Shevchenko