From patchwork Mon Mar 11 21:35:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1054885 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="RSWi1zSB"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44JBHr483Nz9s47 for ; Tue, 12 Mar 2019 08:36:24 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2C70BC21EA6; Mon, 11 Mar 2019 21:36:01 +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, 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 BA805C21EE3; Mon, 11 Mar 2019 21:35:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9B966C21EA7; Mon, 11 Mar 2019 21:35:33 +0000 (UTC) Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by lists.denx.de (Postfix) with ESMTPS id 3E36FC21C3F for ; Mon, 11 Mar 2019 21:35:33 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id p1so459671wrs.8 for ; Mon, 11 Mar 2019 14:35:33 -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=jYwLEL2+nyu1uy41FEdClIgO2/T9CmDPqZQzcNFhjJY=; b=RSWi1zSBzixCrFNqqlbuMBxQI6fa6XjDoBBgMpWcLLSBxZloX3dBxXHAT7e91iki/S o7o49XX+X6JKnOSSwVsWPKK1NiSY8n+C58XRcnHhPsht7V3eO0pvjIkZSNawlDTovdXY LeIQihUlcARSY8jeFwDUmQzg/dsTMbQ8BbD607J/hK+fxzgVwUIfz+E5S5S0RaNtaqUS JausHTxdA6cqrE0n37vZ0fZvODdcb/h4bCsD/78UUw6FVokXYUJshCzjt/o/6zjY61yH HBJE2GeUlpavtrr7b260Fovjp52DP2mOjYucn1ExljxyOxkTlkTSa183u6uypmQDhr9g VyIg== 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=jYwLEL2+nyu1uy41FEdClIgO2/T9CmDPqZQzcNFhjJY=; b=p3yOHEO4zmD99WTaMcM7PAisNIoyeRyKBd15rV/gUEfyC0Q4NOZYOeGpbuhU1cHut5 hKKMB4sET1iS1JkBHLhQDBlp/mcVL1yWOvudukCDDfLxPRdgZpaG1YFmyWkzie0Tm/nl 3vSrhC/4+bbvVRXBOHZisOie88FA5fI53ubw7FsAUCAwWeuvfWhh510TMyYWaqzTui8p 9JsU8CqdY24yI+P9YFBClCOCX7wFfEfGkHerYC1VkZ/8LNhFXW7TSU8zMvTK9wLeePCe PueMn02cU78f7wQsi6tCCpWPAoK3cmBhrL7/CA9wkVzhYL0S5lvOpyrA8KE4cAyZiZ0t kLhw== X-Gm-Message-State: APjAAAUrZUYFl0Y3cVBAF2h37rnk++uSDRmuyieBV+Mdpd5ZcgzZ9l3s gqS1uuDSGPeTYvrJxM47fDRpzH09 X-Google-Smtp-Source: APXvYqz3WASfQ5BRcKlXsLqAkhCwKHnWsNvsx/gi4z/IMop6eddhHU2Efyke75FOlZHExIIW0CIOUA== X-Received: by 2002:adf:ec10:: with SMTP id x16mr21835378wrn.171.1552340132754; Mon, 11 Mar 2019 14:35:32 -0700 (PDT) Received: from ubuntu.home ([2a02:8071:6a3:700:3ce6:848a:8db5:3b8c]) by smtp.gmail.com with ESMTPSA id u17sm22997225wrg.71.2019.03.11.14.35.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 14:35:31 -0700 (PDT) From: Simon Goldschmidt To: u-boot@lists.denx.de Date: Mon, 11 Mar 2019 22:35:21 +0100 Message-Id: <20190311213524.15893-4-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190311213524.15893-1-simon.k.r.goldschmidt@gmail.com> References: <20190311213524.15893-1-simon.k.r.goldschmidt@gmail.com> Subject: [U-Boot] [PATCH 3/6] 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 --- common/dlmalloc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index edaad299bb..51d3bd671a 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -603,6 +603,10 @@ void mem_malloc_init(ulong start, ulong size) mem_malloc_start = start; mem_malloc_end = start + size; mem_malloc_brk = start; + if (start && 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);