From nobody Mon Jun 8 20:53:22 2026 Received: from mta.al2klimov.de (mta.al2klimov.de [162.55.223.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10636425CEB for ; Tue, 26 May 2026 18:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.55.223.79 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820902; cv=none; b=l+TvOsOmtLYRkrj7Nk+G9K8XFMSns9HJMlkJN1C9fUV+s1QGM9YEJx5dqq6x0cLa/WpEmCkA3GnXMkjH/5iGOGceMKmO32tQLXH1MBzVCNT9i5ewbIiWsVUrJh+tGuAo3sx6/xuFCiVIxaKQfcz7Jm9uWekcpfJhbIvMMBfm/gA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820902; c=relaxed/simple; bh=hsjJM5DVrK8FbkWTeJwhjpPNr/BYyBjDu24U6AurzbY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vF617uHveW6pfecxki4+bsoB79DWvqWvQ5o4CXP/tBfkiqxlULnF/3wVcPX+ReFSjqatllwaxAR8voYURxmNFr8dnyRDiHWHpxe4bYpkhWhQdVYNyBuY1FKC1UVQrMZX2Sv/tAduslpAKrgkEbxVpqfeHurVg/5TeIGXPFLZdog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=al2klimov.de; spf=pass smtp.mailfrom=al2klimov.de; dkim=pass (2048-bit key) header.d=al2klimov.de header.i=@al2klimov.de header.b=E2+WgkMg; arc=none smtp.client-ip=162.55.223.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=al2klimov.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=al2klimov.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=al2klimov.de header.i=@al2klimov.de header.b="E2+WgkMg" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=default; bh=hsjJM5DVrK8F bkWTeJwhjpPNr/BYyBjDu24U6AurzbY=; h=references:in-reply-to:date: subject:cc:to:from; d=al2klimov.de; b=E2+WgkMgMWzEuC8idw43CBXl/EmfM3iT vMpNxOUrM6FQuy1SGnFMCQz+3ADtebTHez0D025CeQHUg9DvwY646e7J617Pg3I+RmGM+x hrqBfLdaeKmnhj8CadNagc2pS3fs8rv/+JBrAqC1hBA4cGgtv5A/B/eUGJXv13ZOSbnyIR 66jCLMMNe5TA2HXGBYMWOtCG5/3WDJHhWEksrGFYCAKowQeUqP5hhrXHtwVmDhm5nc5ly4 O7W5Bn5d3C41xAwdruN+l3zpRzMnO0YjHSJEM40Z/mwNgyugtdvjfw/mYFViFmWMww7rJl cuWiEwCd/wmY2Adc1OZ+GXUXHi+qxA== Received: from cachy-ak (88.215.123.80.dyn.pyur.net [88.215.123.80]) by mta.al2klimov.de (OpenSMTPD) with ESMTPSA id c57fab13 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Tue, 26 May 2026 18:41:32 +0000 (UTC) From: "Alexander A. Klimov" To: Maxime Ripard , Dave Stevenson , =?UTF-8?q?Ma=C3=ADra=20Canal?= , Raspberry Pi Kernel Maintenance , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Eric Anholt , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-kernel@vger.kernel.org (open list) Cc: "Alexander A. Klimov" Subject: [PATCH] drm/vc4: fix krealloc() memory leak Date: Tue, 26 May 2026 20:41:00 +0200 Message-ID: <20260526184105.18962-5-grandmaster@al2klimov.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260526184105.18962-1-grandmaster@al2klimov.de> References: <20260526184105.18962-1-grandmaster@al2klimov.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Don't just overwrite the original pointer passed to krealloc() with its return value without checking latter: MEM =3D krealloc(MEM, SZ, GFP); If krealloc() returns NULL, that erases the pointer to the still allocated memory, hence leaks this memory. Instead, use a temporary variable, check it's not NULL and only then assign it to the original pointer: TMP =3D krealloc(MEM, SZ, GFP); if (!TMP) return; MEM =3D TMP; Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validati= on.") Signed-off-by: Alexander A. Klimov --- drivers/gpu/drm/vc4/vc4_validate_shaders.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/v= c4/vc4_validate_shaders.c index d48cf76983c0..af48758592f9 100644 --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c @@ -291,14 +291,14 @@ static bool require_uniform_address_uniform(struct vc= 4_validated_shader_info *va uint32_t o =3D validated_shader->num_uniform_addr_offsets; uint32_t num_uniforms =3D validated_shader->uniforms_size / 4; =20 - validated_shader->uniform_addr_offsets =3D - krealloc(validated_shader->uniform_addr_offsets, - (o + 1) * - sizeof(*validated_shader->uniform_addr_offsets), - GFP_KERNEL); - if (!validated_shader->uniform_addr_offsets) + void *mem =3D krealloc(validated_shader->uniform_addr_offsets, + (o + 1) * + sizeof(*validated_shader->uniform_addr_offsets), + GFP_KERNEL); + if (!mem) return false; =20 + validated_shader->uniform_addr_offsets =3D mem; validated_shader->uniform_addr_offsets[o] =3D num_uniforms; validated_shader->num_uniform_addr_offsets++; =20 --=20 2.54.0