From patchwork Fri Mar 15 20:13:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1057238 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="I7fdvMXq"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44LcHz5Vhmz9s5c for ; Sat, 16 Mar 2019 07:14:53 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 86207C221A3; Fri, 15 Mar 2019 20:14:43 +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_DNSWL_NONE, 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 AE1E9C221BF; Fri, 15 Mar 2019 20:14:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1B292C221B5; Fri, 15 Mar 2019 20:13:59 +0000 (UTC) Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by lists.denx.de (Postfix) with ESMTPS id 002D6C221A3 for ; Fri, 15 Mar 2019 20:13:56 +0000 (UTC) Received: by mail-wr1-f50.google.com with SMTP id p1so10852666wrs.8 for ; Fri, 15 Mar 2019 13:13:55 -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=lwNL5BZ3zDeJMVudnMy1Kzvj4K3kKzRXF0YoyapqQ5w=; b=I7fdvMXqGQPDu4PMF+DCHRUKh5vCbFgzUGxaSgkJHSlm+yJkcyVUbLGi6ngPdcNlPW xYZgkBys3lRUXDJE4bzPgF63G7XoJIKIy8fksIGL6I5Uynb4stlIB6Kn4/0hFTOLQgH8 r3V6FueAgV5jhxIjp5wQW1qheZCNSW5chAD43402TDwBf549hFprjlRlF8jcxKCtoMuX 3BZUBnVRJFzYsErETK7hdXA4OnwoS32YQ6srr2c+6BI+CASpzLni4sqicL00ZicozPT/ 15sJ2zFnnZh2gMFPjgVGbzzBWw5IVrGO8I5W46G0fmSLCT/o8L67ajCwpNVAi+J3wzxK 7vig== 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=lwNL5BZ3zDeJMVudnMy1Kzvj4K3kKzRXF0YoyapqQ5w=; b=Ism8zh0WkqNEhdCg14zFNXDxQQwvu8kAt2bPtWoks2kH5wY6Nge1goPMPpEfa+Bbix hNgZj4XumUgaNzwcoxleNCv6th0Xuc6tm/bFIBS+YxKKFTuPtz/3BxifS7m7VwY+d8MF ncYxD97li0TS02QrzWxzXl/BPHYAb/hjf3bae/+KZ8a/C7h8VGdeLK41A/hEjiVIsrJW oUoHEjWnFWKEvDMI2IfrVaYAsqXz6pQdN92nO2lLN7KuLcUBOeT2u6SNBbWehNTNPddX 8LuzWmhj5yf+xhz8wl21EfRoOk99LXtUYL1+8bTpmUlzNOEntYwQpyREIXjsaDbuCoLs BkcA== X-Gm-Message-State: APjAAAVMlKGBj8lGrKBzxzXZ+fO04VO37lVOBFmpCpgFVr2fqLmopgqS K6Ga2FSZtIEdYUUQHExUOS+qRx6W X-Google-Smtp-Source: APXvYqzaGbxJL/Gpjwi/PIA3n9IfqTtIeP3LhTJ6xBfKZTxDFHqIJybuzSlifizy0HaykZCyNwg1VA== X-Received: by 2002:adf:da42:: with SMTP id r2mr3635924wrl.62.1552680835466; Fri, 15 Mar 2019 13:13:55 -0700 (PDT) Received: from ubuntu.home ([2a02:8071:6a3:700:a087:9044:6211:ba43]) by smtp.gmail.com with ESMTPSA id z12sm4263957wmf.31.2019.03.15.13.13.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Mar 2019 13:13:54 -0700 (PDT) From: Simon Goldschmidt To: u-boot@lists.denx.de Date: Fri, 15 Mar 2019 21:13:44 +0100 Message-Id: <20190315201347.29475-4-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190315201347.29475-1-simon.k.r.goldschmidt@gmail.com> References: <20190315201347.29475-1-simon.k.r.goldschmidt@gmail.com> Subject: [U-Boot] [PATCH v2 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 --- Changes in v2: None 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);