From patchwork Thu Apr 25 19:22:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1091055 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HtHouAOO"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44qnCY64GBz9s3q for ; Fri, 26 Apr 2019 05:23:21 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 8FEDAC21DB6; Thu, 25 Apr 2019 19:23:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id DF7FAC21E3B; Thu, 25 Apr 2019 19:22:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5393AC21C2C; Thu, 25 Apr 2019 19:22:48 +0000 (UTC) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by lists.denx.de (Postfix) with ESMTPS id 050F3C21BE5 for ; Thu, 25 Apr 2019 19:22:48 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id r6so947506wrm.4 for ; Thu, 25 Apr 2019 12:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GP7Ij4LDCNwv9ryOqHPMC9Q7heZuztklGEAhBlp4+Bs=; b=HtHouAOOmLM6aGwnj7mCBCdRmgwnTNeB2iHkuqN2aoa2C326cXPfoNYEZusnqFsLWd qVMpBEwyGY5358zs6ilnuse/EuQ9GGDBPuzobZqTztsjnAW1L8LZFGpYEuoNGi2SZLje 2rRXRxN+Le6VBgQbuCuUBcooYozLIotLar4TI0E0tJj/PLzE1DYenzC2hrhJO1reYE8J XRG+ptzyGKz2Pc4RESb9wCaoGq9KVRu2DXsZgQv9zMlyewMHfLI8pq7+q5GL4VWiZV1N NndXt6gYjVnAYaMEVsOj+nDSDTm8A8Yf/B8rrbGS9XOzhvg/OeXC/y0r1qmKUJ9cIA/o 2BEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GP7Ij4LDCNwv9ryOqHPMC9Q7heZuztklGEAhBlp4+Bs=; b=AlfvdJUq7EnCejpcHpAAhHOtDNyE3TaMIyhMdKS5Xjgrcx7P1w0RHUVRPfpsp3n7Bi JuNa00tvo1xm9BqG8DMF2ymQfBdMZoqLnZDNZbDsvjn5MZe/mbvUIvw1bpGUGC4ZAqaV hQGUiy3Gz/a3Vs0vrPzxw/bqbfKI5qWQm70IaJa8xM2ax9nTXpNFVKpd8VqVXzRldzCw OTbOJGBnjBngdN70+gfFZskrrm0WQWt+4MUAK5MOLWY/s7jOCCLC2+FcKTWWpvLRU6oR ZWZhRGkTOPlDdZzvhiNLRI+KjLrTcozKn00okmzx5B0c5RmH1YODuqSEP6qmuu6/koZS VYmA== X-Gm-Message-State: APjAAAUALm0TSSRIss0TbWkk2KoVulVDKTIh8hPlpqV/agmqByVx6BeI wQKtL8Y9MBFjPRnODWyGSW8= X-Google-Smtp-Source: APXvYqzk0aEC6VL6rDYphzlL6jigt8LVjdPKbSOiq/wLiVO+4jwPuoFS202PRPb4TxNOwC1rrnZv2Q== X-Received: by 2002:a5d:6b46:: with SMTP id x6mr26109920wrw.313.1556220167719; Thu, 25 Apr 2019 12:22:47 -0700 (PDT) Received: from ubuntu.home ([2a02:8071:6a3:700:1caf:b95c:3a06:5af0]) by smtp.gmail.com with ESMTPSA id 17sm18644406wrk.91.2019.04.25.12.22.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Apr 2019 12:22:47 -0700 (PDT) From: Simon Goldschmidt To: Tom Rini Date: Thu, 25 Apr 2019 21:22:40 +0200 Message-Id: <20190425192240.5925-2-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190425192240.5925-1-simon.k.r.goldschmidt@gmail.com> References: <20190425192240.5925-1-simon.k.r.goldschmidt@gmail.com> Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v5 2/2] dlmalloc: fix malloc range at end of ram X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" If the malloc range passed to mem_malloc_init() is at the end of address range and 'start + size' overflows to 0, following allocations fail as mem_malloc_end is zero (which looks like uninitialized). Fix this by subtracting 1 of 'start + size' overflows to zero. Signed-off-by: Simon Goldschmidt --- Changes in v5: - this patch was 1/2 in v4 but is now 2/2 as the 2nd patch of v4 has already been accepted - rearrange the code to make it only 8 bytes plus in code size for arm (which fixes smartweb SPL overflowing) common/dlmalloc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 6f12a18d54..38859ecbd4 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -601,8 +601,12 @@ void *sbrk(ptrdiff_t increment) void mem_malloc_init(ulong start, ulong size) { mem_malloc_start = start; - mem_malloc_end = start + size; mem_malloc_brk = start; + mem_malloc_end = start + size; + if (size > mem_malloc_end) { + /* overflow: malloc area is at end of address range */ + mem_malloc_end--; + } debug("using memory %#lx-%#lx for malloc()\n", mem_malloc_start, mem_malloc_end);