From patchwork Thu Jul 4 07:34:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 809907 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1041971wru; Thu, 4 Jul 2024 00:36:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW84Gv/YDQ5fEu5K63mO7XFAFbf1sALJ3Y++ugG9EWR0q1NOejkT+IwTMJz8+yxyUjMG9BMhnjF6m85XXiPSsKf X-Google-Smtp-Source: AGHT+IG5lJD3VYhRR3ubrHw+hHsoR0e2yi1aErJFGc0s1MJnlG2pb9/I3N/QNCRbPznYlYpJ6ifh X-Received: by 2002:a17:906:a415:b0:a68:b557:76f5 with SMTP id a640c23a62f3a-a77ba72249emr51389966b.69.1720078578315; Thu, 04 Jul 2024 00:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720078578; cv=none; d=google.com; s=arc-20160816; b=VSjhVtIQQdmQw8vx0p1hYf5yEKOnuEXwRfJaztHAOWzJg0uIrvEv8NJXiaSEVEVgCI 3ja+GEPHk65pU1pvDpyUz2TBw4e4gupAIBuqK+LE7n6imt62ZyAFKVfGgDVFq7B5iknh 3Hjf7UF/St8kg14sDPUvJsJMc1IWGqLVzqO6fWEfC59jneFyD7GTlJGvNkvmHFiEXiPZ gQbaiK0378zkxB5Cybq/HcOUsakGrG5h3zUWPC61iT/K1mSM4AfZpoUoExMO+dOLWWXU rphwLeFpq8dzs68hMOxEtrxm6wgJLXf9TxQ/hEtKxZIUwdM2q/fbTZJpdW2Eebr/XUh0 NSkg== 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=kAxTqQvr7LTvZ1RJ2pjiEEqwVCo/brb/6RZrl/QqPMQ=; fh=ez1zzjhC0XWyqTp7tWutqrA/nFdALDnQKrnQnXYhk5Q=; b=Jqk7OzdLrytmtfScgnFTCzKMar+nxkUkCmGRD+qY67hvWvExgOhrlptdMqyBbQ5hde K0hAYMGz5pnqqHdMFlhKy58rwSCa0DBJnv0Ok9MRoXEn/MMAY0HOos1saX+gMABfCYSa byCbpTwnt2HkhNq3XIfGwbGfhgqu0HvgpJLy7UCeXOuMCPXLUn9oLN7JhJWPCK8iw4UT Xqduuofu/pBsSgxp8n3aSkKsPLDrC3JREEJt7IG8zDodtxcKC2Ze7H9YZKXvREBnVzI8 PdBb9Y63tO7Qjmc4ZF8A39avNwmm0xQe3yq58tOR8UXdkkAx/15QnYVxoZ7drs5eeB4y rdQA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a72ab0969b2si651972266b.823.2024.07.04.00.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 00:36:18 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 7F070888A4; Thu, 4 Jul 2024 09:36:11 +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 43FCA8889D; Thu, 4 Jul 2024 09:36:10 +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.2 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no 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 503B5888A0 for ; Thu, 4 Jul 2024 09:36:08 +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 AF64A367; Thu, 4 Jul 2024 00:36:32 -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 8A91B3F762; Thu, 4 Jul 2024 00:36:04 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Tom Rini , Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Mark Kettenis , Fabio Estevam , Michal Simek , Sughosh Ganu Subject: [RFC PATCH v2 01/48] malloc: Support testing with realloc() Date: Thu, 4 Jul 2024 13:04:57 +0530 Message-Id: <20240704073544.670249-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240704073544.670249-1-sughosh.ganu@linaro.org> References: <20240704073544.670249-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 9549c59f35..65b130fabc 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1758,6 +1758,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);