From patchwork Mon Oct 21 17:18:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 837320 Delivered-To: patch@linaro.org Received: by 2002:a5d:50c9:0:b0:37d:45d0:187 with SMTP id f9csp2130907wrt; Mon, 21 Oct 2024 10:19:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXun63CneL8ECgoget7k7jCY8ZpTu8J4A6gJktqhwSlS0ULQjni6Hv0iM1EcoIRG+biyzQmZw==@linaro.org X-Google-Smtp-Source: AGHT+IExgYl2c9McsXX7Ft5dQzc5xq7LqXX9XhqXR48VLoq6Sq8kTPSJd/P4yidtOjKQ0gbzkbGW X-Received: by 2002:a05:6602:641e:b0:83a:a82b:f856 with SMTP id ca18e2360f4ac-83aba5bbec0mr1018414739f.3.1729531141397; Mon, 21 Oct 2024 10:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729531141; cv=none; d=google.com; s=arc-20240605; b=O3Id8U9pIDJvNYH41PwjnMZZewVAl9h9qKliS7sK2UY6y2kXomdiysKB8/3ATtyVfC s4PdwQRO8iyJ0kYx557fOgVbZug535uw3+A7OcWEclFw+oqVjhJkKIkdnBpEKe+crIH9 urAcK7wxXMWisGY/V96i98naa/IdgT8uM2/oIxxeOYOUKhba4YhhdsfDtQvE1kBGK+dN v/TI7JdwlUDdLkECyn+ieOiM1fRj5GQNzjQ4ZB1N3gD9ho2p67/vYHcUOsFeQYfnbY8G w1To9ys9Sz+QitzCbNpQrxY8UfWWe+g8+FDzWnRWRNddaJ7Xvu0wr9t9pP805rdbWbDC u1kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=MdcI+Kp06NXlCltrmHd9maup08bVcr8TF+TJ8AdrMZ8=; fh=c3tZYzOKdeEPikfV/Bc89R7+ZlV1hn+ljypRVA3I1w0=; b=HFjaxNXcpqS1pgZOH63e42rReZvUMiJS/TdVhnx3R7LE3Fe2Wu1doS5sSfQzoyDKPj YsB9yR+/LPDz484aZmaLZ9Iqo52Zw9bN0BtzDnHCNw55rxbvAprr4O5zzOh5+Yh2ayNc +ycN30eikVEPVXgndTbskQRY4kcZQGcUm9zJuhR6QEO8kqBg7wVNUbkaXi+PuGf2tg3E gFJoPdjaXXy8Ii5L/oCO0c0kgFFzx2HwqIqa3R69IPLmfBVxY57O8tixip5Gwlj9TLiv 1yzlWusVqeBKPaZm3eQk4xvPzF1qe2XHvtZdw0k+xbPeFDRRdhRavwEdcS4AWVDlteDp aj0Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ca18e2360f4ac-83ad1c93e44si171291639f.25.2024.10.21.10.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 10:19:01 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8F62288901; Mon, 21 Oct 2024 19:18:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 52F438897F; Mon, 21 Oct 2024 19:18:59 +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=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 717EB88549 for ; Mon, 21 Oct 2024 19:18:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 937A1DA7; Mon, 21 Oct 2024 10:19:25 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 94BEA3F528; Mon, 21 Oct 2024 10:18:54 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Tom Rini , Sughosh Ganu Subject: [PATCH] lmb: add a check to prevent memory overrun Date: Mon, 21 Oct 2024 22:48:20 +0530 Message-Id: <20241021171820.625003-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean When printing the LMB flags for a memory region, there is a need to check that the array index that is computed is a sane value. Put a noisy assert in case this check fails, as that implies something with the LMB code is not working as expected. Reported-by: Coverity (CID 510463) Signed-off-by: Sughosh Ganu --- lib/lmb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/lmb.c b/lib/lmb.c index 7e90f178763..a7298dfd673 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -76,6 +76,7 @@ static void lmb_print_region_flags(enum lmb_flags flags) do { bitpos = flags ? fls(flags) - 1 : 0; + assert_noisy(bitpos < ARRAY_SIZE(flag_str)); printf("%s", flag_str[bitpos]); flags &= ~(1ull << bitpos); puts(flags ? ", " : "\n");