From patchwork Wed Jul 24 06:01:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 814124 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp2617341wro; Tue, 23 Jul 2024 23:02:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVDvea54c9lejnejXxylLkhmaOdAlJNP6n+bp540L48OBnKATP0/1TkgPIbgZ0sLeCXL5CuAtK52HzgFEHll5iM X-Google-Smtp-Source: AGHT+IGlrfa+4wfKtBYcDJ7PvMCY90FpltQvaeYHvBLmGSQPtqXNHFuxQidVvizbz/5e1spU95Fm X-Received: by 2002:a05:600c:34c1:b0:426:59d3:8cae with SMTP id 5b1f17b1804b1-427f7abb562mr13238925e9.13.1721800975876; Tue, 23 Jul 2024 23:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721800975; cv=none; d=google.com; s=arc-20160816; b=qJ+Xzdj7glHbBdqbsYR3G6SApA3R/YpJewqhkdzhdv1hf93tRMA3xUdUCp71sicmb9 GvNg5fWYWQCmrRqCTYNxqqVlCVSAadhwu3h3xTjsdKYdHydfSsqL9sN+ycEANihONahr 3JHdA0JAP4xBPz36hwe7/UXwTP3el+iDGQ+VsFjIvYbxxZDxdamRlz1bjGnMDzkkFJoo icFBnXKLzUYIABnAptbvXlSARWUHEbS+YYg3HiFHErA3OohtCvAE2nmbFanMU03O9hEz KGxC2C4RGvGvw0NnfZrjwV5+V43YAC77KTfXxcelrmteAp7ac0fL+3FOXENvZUG2nRl7 nazA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=NdDN3PL4ZatbV/asmY/CigKgPcRkvZfeVZlpV0Z7POM=; fh=eimiGswTlodK8yi2DcDfSicmKwvq5bxKQKpD+SkkTNY=; b=f5dCls4SNvW0VcqjsySOjdbEA09Wii4p5P+b2XuBzf4WmhogO46vr5xdRp7HaCjFXn cF6ma9SnQd2b/oizAfhUuX9YoaOeQqDiJfRIKfJjheY/Fv0S+eXFZQtY2o+SCOJiMwAV X+RXX0idRJPCO4UURgvl8pQVGfVZxfSzKM3K7MLVq+TB4LgposVrSrDDGoIKGt7DPbSY Zzpnl2xQEZ8BHMllOO80rCMe4BzknHvOzknzYhwXfP9ghAETDQdx6W2RYU8b99+EzLw8 h1G8ReUBdx5/5RkTXugbGPvtqIyj/zaPAq0pafOUiX7aWteFRvYZimlOV4XIMISXH4ae RCpA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 5b1f17b1804b1-427f939acc6si3587575e9.134.2024.07.23.23.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 23:02:55 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7DEDC8883D; Wed, 24 Jul 2024 08:02:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 837B688805; Wed, 24 Jul 2024 08:02:53 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,T_SPF_TEMPERROR autolearn=ham autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 7147288005 for ; Wed, 24 Jul 2024 08:02:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5E20C1476; Tue, 23 Jul 2024 23:03:13 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4AB263F766; Tue, 23 Jul 2024 23:02:43 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Mark Kettenis , Michal Simek , Patrick DELAUNAY , Patrice CHOTARD , Huan Wang , Angelo Dureghello , Daniel Schwierzeck , Thomas Chou , Rick Chen , Max Filippov , Sughosh Ganu Subject: [PATCH 01/40] malloc: Support testing with realloc() Date: Wed, 24 Jul 2024 11:31:45 +0530 Message-Id: <20240724060224.3071065-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240724060224.3071065-1-sughosh.ganu@linaro.org> References: <20240724060224.3071065-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Simon Glass At present in tests it is possible to cause an out-of-memory condition with malloc() but not realloc(). Add support to realloc() too, so code which uses that function can be tested. Signed-off-by: Simon Glass Signed-off-by: Sughosh Ganu --- common/dlmalloc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 62e8557daa..1e1602a24d 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1698,6 +1698,10 @@ Void_t* rEALLOc_impl(oldmem, bytes) Void_t* oldmem; size_t bytes; panic("pre-reloc realloc() is not supported"); } #endif + if (CONFIG_IS_ENABLED(UNIT_TEST) && malloc_testing) { + if (--malloc_max_allocs < 0) + return NULL; + } newp = oldp = mem2chunk(oldmem); newsize = oldsize = chunksize(oldp);