Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 818DDC48BF6 for ; Thu, 29 Feb 2024 11:52:51 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ellerman.id.au header.i=@ellerman.id.au header.a=rsa-sha256 header.s=201909 header.b=pb0OpPyT; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4TlqNK6W22z3vZG for ; Thu, 29 Feb 2024 22:52:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ellerman.id.au header.i=@ellerman.id.au header.a=rsa-sha256 header.s=201909 header.b=pb0OpPyT; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4TlqMY1SLBz3dRp for ; Thu, 29 Feb 2024 22:52:09 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1709207529; bh=1JemNML8u0Pv/lftM5xYFX6qCmUnxakrk11UQxuV7oc=; h=From:To:Subject:Date:From; b=pb0OpPyTmvN2tkvlXGc76xpSyoXgB0Wq7BpetJ/42b0M6SsQRKdXyRJAaU7mzxBLZ K1F6qazOzi9mCbWMrDMS+FIWJ5HOG+0qisCrLm50tDlVdFOVh1aOvHpt4hZDniCoXW 13GND6WcBcCmI0NMuQRXRp0QVXI7SKI2ghbK9AbmjHlymk6Vlx0JIPUalIYy+nZOTe wjMt7L2WceqnEWjcB3aqfyllrOR/IJEAi2tS3KNTJ3OUJlhCGSLxDTE2EhaPoyzaQi 3KLsTIfjorL4vBB247YAXTQfOiYHfzhpdzTTkiqexN9NKDm2pXLInVwshsnsfwakZQ 7pIjnfUsIGilg== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4TlqMY0BVFz4wbh; Thu, 29 Feb 2024 22:52:08 +1100 (AEDT) From: Michael Ellerman To: Subject: [PATCH] powerpc/boot: Only free if realloc() succeeds Date: Thu, 29 Feb 2024 22:51:49 +1100 Message-ID: <20240229115149.749264-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" simple_realloc() frees the original buffer (ptr) even if the reallocation failed. Fix it to behave like standard realloc() and only free the original buffer if the reallocation succeeded. Signed-off-by: Michael Ellerman --- arch/powerpc/boot/simple_alloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/boot/simple_alloc.c b/arch/powerpc/boot/simple_alloc.c index db9aaa5face3..d07796fdf91a 100644 --- a/arch/powerpc/boot/simple_alloc.c +++ b/arch/powerpc/boot/simple_alloc.c @@ -112,10 +112,11 @@ static void *simple_realloc(void *ptr, unsigned long size) return ptr; new = simple_malloc(size); - if (new) + if (new) { memcpy(new, ptr, p->size); + simple_free(ptr); + } - simple_free(ptr); return new; } -- 2.43.2