From patchwork Fri Oct 25 19:23:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1184419 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 (no SPF record) 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="FpLhvS1X"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 470DYp1Zn8z9sPK for ; Sat, 26 Oct 2019 06:23:56 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 70571C21E12; Fri, 25 Oct 2019 19:23:44 +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 D1CBBC21C51; Fri, 25 Oct 2019 19:23:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2AF98C21C51; Fri, 25 Oct 2019 19:23:41 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by lists.denx.de (Postfix) with ESMTPS id D108BC21C3F for ; Fri, 25 Oct 2019 19:23:40 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id l10so3599828wrb.2 for ; Fri, 25 Oct 2019 12:23:40 -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:mime-version :content-transfer-encoding; bh=YtDxi2GKt0PCtNKrb3yLqB2OAdiukHIIzNB2mSfpOv8=; b=FpLhvS1XyXR/iSIOO7ugqUld4abnD6MtwmQXhF6g+qoEFTOX1+iIdYiHFxkhoYyTir QEhTaUxOEGUsOomv+NJRqHe3e/2PqdDQAcpL8JXcx1wbB77N2Png0yLOdy2hg0eTzwnq jHlW4E+5wnTmcv34IdLrlKR2EKvhQ/uDALlq+Te/r4Co+7qiMTBK94A1LdG4pW3fnW8y dmq5irX9LBFflrp2ooHqePwhZy1+feFqqs1Wg280qeClwpVYtzKQQk+izZ9w1xFUriYJ sVvG7hJK5vD1Rd439aQNxuaIMkF38RSc2mMB+S1VFo6Y0uJtYXBPEC/QuR9lDdeKOSrz WcMg== 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:mime-version :content-transfer-encoding; bh=YtDxi2GKt0PCtNKrb3yLqB2OAdiukHIIzNB2mSfpOv8=; b=jBBAhLvqoHRQJhWhNZoupS2qop1HXG1HkqHKergXfWSYd24827LkmY5aLHVOjT+b7P PloFKiWmlk6KaLatyMOrAscstUVzIT4MjMUZTBaia3/hwqVPqUKCXBRhiDzYlXhGbkAz Ic2Exc7F9k75foGuf+znoyYojI9L0Op3v5vBAf5weCq+XKeP70KI6pq1kkGTdTnhwiJV RCE4LajcN+Oj6is8Z4kNEC6xYb/S8u5Fu+LWrI0supWtP0ubMmW3JkFzCZo0jSnDd34A riaV9/wUP8ms2OCEw1Vpw+96iuja3XapctPdGzgb1UWsFZqxOPf7nRfcdaRH55LdZGww IbTg== X-Gm-Message-State: APjAAAVH3LtqqeRmfqhMzJbSBwGmqHYgaZTWds3j1r4w92xcf+Zlt9bz m2IYnHDAl6790fOKHuaepCQ= X-Google-Smtp-Source: APXvYqwe1TznNAhh60MGHMUkZ7bBoseWpo8Xjj9AVbXe5ygn6bwaM6Vr4z2+w1QplPOsTUP/RRlWaA== X-Received: by 2002:adf:f44e:: with SMTP id f14mr4271412wrp.56.1572031420361; Fri, 25 Oct 2019 12:23:40 -0700 (PDT) Received: from ubuntu.home ([2a02:8071:6a3:700:50e:1b2d:a4c8:d388]) by smtp.gmail.com with ESMTPSA id a9sm4818562wmf.14.2019.10.25.12.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 12:23:39 -0700 (PDT) From: Simon Goldschmidt To: Tom Rini Date: Fri, 25 Oct 2019 21:23:35 +0200 Message-Id: <20191025192335.13498-1-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH] dlmalloc: calloc: fix zeroing early allocations 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" When full malloc is enabled and SYS_MALLOC_F is also enabled, the simple pre-reloc heap is used before relocation. In this case, calloc() uses the MALLOC_ZERO macro to zero out the allocated memory. However, since this macro is specially crafted for the dlmalloc implementation, it does not always work for simple malloc. For example, when allocating 16 bytes via simple malloc, only the first 12 bytes get zeroed out. The last 4 bytes will remain untouched. This is a problem for DM drivers that are allocated before relocation: memory allocated via 'platdata_auto_alloc_size' might not be set to zero, resulting in bogus behaviour. To fix this, use 'memset' instead of 'MALLOC_ZERO' to zero out memory that compes from simple malloc. Signed-off-by: Simon Goldschmidt Reviewed-by: Tom Rini --- common/dlmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 6f12a18d54..dade68faf7 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -2086,7 +2086,7 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size; { #if CONFIG_VAL(SYS_MALLOC_F_LEN) if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { - MALLOC_ZERO(mem, sz); + memset(mem, 0, sz); return mem; } #endif