From patchwork Wed May 23 19:07:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 919334 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=none (p=none dis=none) header.from=de.adit-jv.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40rhqS48YJz9ryk for ; Thu, 24 May 2018 05:08:04 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 37E8BC21DFB; Wed, 23 May 2018 19:08: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=RCVD_IN_DNSWL_BLOCKED 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 03313C21C29; Wed, 23 May 2018 19:07:58 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2ECF0C21C2F; Wed, 23 May 2018 19:07:56 +0000 (UTC) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [62.225.105.245]) by lists.denx.de (Postfix) with ESMTPS id A77D6C21BE5 for ; Wed, 23 May 2018 19:07:55 +0000 (UTC) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id DCB203C0059; Wed, 23 May 2018 21:07:54 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 26no26n_IpFp; Wed, 23 May 2018 21:07:46 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 6D2C23C004C; Wed, 23 May 2018 21:07:46 +0200 (CEST) Received: from vmlxhi-102.adit-jv.com (10.72.93.184) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.389.1; Wed, 23 May 2018 21:07:46 +0200 From: Eugeniu Rosca To: Simon Glass , Tom Rini , Stephen Warren , Philipp Tomsich , Peter Tyser , Kumar Gala Date: Wed, 23 May 2018 21:07:10 +0200 Message-ID: <20180523190710.30260-1-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 X-Originating-IP: [10.72.93.184] Cc: u-boot@lists.denx.de, Eugeniu Rosca Subject: [U-Boot] [PATCH] dlmalloc: ensure gd is set for early free 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This fix seems to be a twin of v2015.01 commit 854d2b9753e4 ("dlmalloc: ensure gd is set for early alloc"). Here is a gdb backtrace to make them look even more similar (sandbox build): (gdb) run Starting program: /path/to/u-boot [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Program received signal SIGSEGV, Segmentation fault. 0x00000000004123c0 in free (mem=0x0) at common/dlmalloc.c:2460 2460 if (mem == NULL) /* free(0) has no effect */ (gdb) where #0 0x00000000004123c0 in free (mem=0x0) at common/dlmalloc.c:2460 #1 0x00007ffff3f46cea in ?? () from /lib/x86_64-linux-gnu/libselinux.so.1 #2 0x00007ffff7de76ba in call_init (l=, argc=argc@entry=1, argv=argv@entry=0x7fffffffd928, env=env@entry=0x7fffffffd938) at dl-init.c:72 #3 0x00007ffff7de77cb in call_init (env=0x7fffffffd938, argv=0x7fffffffd928, argc=1, l=) at dl-init.c:30 #4 _dl_init (main_map=0x7ffff7ffe168, argc=1, argv=0x7fffffffd928, env=0x7fffffffd938) at dl-init.c:120 #5 0x00007ffff7dd7c6a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2 #6 0x0000000000000001 in ?? () #7 0x00007fffffffddbb in ?? () #8 0x0000000000000000 in ?? () Interestingly, this issue appears on a very old v2015.04 U-boot, but not on u-boot/master (even if the fix applies cleanly to u-boot/master). With the patch applied, my ancient u-boot starts to work properly: $ ./u-boot U-Boot 2015.04-00280-g5755c9e48b83 (May 23 2018 - 20:53:31) DRAM: 128 MiB Using default environment In: serial Out: lcd Err: lcd => Signed-off-by: Eugeniu Rosca --- common/dlmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index b395eefbf862..6012f9f162c0 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1524,7 +1524,7 @@ void fREe(mem) Void_t* mem; #if CONFIG_VAL(SYS_MALLOC_F_LEN) /* free() is a no-op - all the memory will be freed on relocation */ - if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) + if (gd && !(gd->flags & GD_FLG_FULL_MALLOC_INIT)) return; #endif