From nobody Mon Jun 8 07:26:16 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 A18DE231A23 for ; Sun, 31 May 2026 19:55:36 +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=1780257338; cv=none; b=GEJ4PvtILwbU3PkU+SVsD0WHTO6UI530hE4i/VhdpvIfh3TQ+RX4OnPVRtdK8Gmrr5BDHA/RySoyt3JHqmGaWUwRkN4oU3yo90rKAbULfPTF2FIh+sq9CmPY7uVml4kHhX6G5ZdCtFaMljXataDoDQpr2p+46DoMvApvHegLcOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780257338; c=relaxed/simple; bh=ZoukwfSF8bc4T0zOTYJl0C8sMTVJuamWQpd1iB8O5oY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FEZUSQZ84IAKRCnhvdTIjoXfCtCPWnMrRHKJF34p279ixt/5h7WFeyt4SHzf/p/kHhW+WHn7TLfS7OG0v/1MeY8kvhx2qXUUA0B0GaajfyMgD/gqYsoMOpARBTpwK9HY9f8zvHzdv/z+6Swux9F0gtJ6UZBOu3+JqgS0aXvWzMg= 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=KlI1Nk1I; 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="KlI1Nk1I" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=default; bh=ZoukwfSF8bc4 T0zOTYJl0C8sMTVJuamWQpd1iB8O5oY=; h=references:in-reply-to:date: subject:cc:to:from; d=al2klimov.de; b=KlI1Nk1IOl7Xplg+KLj9PasHUyKo26zW v28XKYaCn9XtSp0HAIfaO8UMXsl8cxjmvHwqi0u8PcTsJcxgNE71K0HH9jp2oL6YY/k7QP FUb70eJWpnX1Q0tCl+UsGKhhGtcBrmX42C4Xto3lpk4Y1d9HGGocI197vR9Rlekqxy745Y NNq2qmcLXwccal2GtxXAcjIFrtopqKgBYZL3V7QstMMtTKzeD6MjwbRlUyBGqdOFva5EL+ zZAviDp1BtEppsXVYgs+V2Bv6FUkjz4ze7G4hx/xzLeYKo3lj1nTcByka5O630M2hyO18C HD5SodwmJhkiySidSSxQgoeT59YxVg== Received: from cachy-ak (88.215.123.80.dyn.pyur.net [88.215.123.80]) by mta.al2klimov.de (OpenSMTPD) with ESMTPSA id e9e32a2c (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Sun, 31 May 2026 19:55:34 +0000 (UTC) From: "Alexander A. Klimov" To: Cc: "Alexander A. Klimov" , Maxime Ripard , Dave Stevenson , =?UTF-8?q?Ma=C3=ADra=20Canal?= , Raspberry Pi Kernel Maintenance , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Eric Anholt , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), linux-kernel@vger.kernel.org (open list), llvm@lists.linux.dev (open list:CLANG/LLVM BUILD SUPPORT:Keyword:\b(?i:clang|llvm)\b) Subject: [PATCH v2] drm/vc4: fix krealloc() memory leak Date: Sun, 31 May 2026 21:55:10 +0200 Message-ID: <20260531195515.99623-1-grandmaster@al2klimov.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <2b602ec6-d563-4fa0-a0c5-89b97a46abf9@igalia.com> References: <2b602ec6-d563-4fa0-a0c5-89b97a46abf9@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 --- v2: Declare the variable explicitly v2: Instead of void *, use u32 * v2: While on it, enhance variable name [=E2=9C=93] scripts/checkpatch.pl --strict [=E2=9C=93] allmodconfig compiled (i686, LLVM) [=E2=9C=93] localyesconfig booted (IBM T43) Note to myself: use --in-reply-to=3D2b602ec6-d563-4fa0-a0c5-89b97a46abf9@i= galia.com drivers/gpu/drm/vc4/vc4_validate_shaders.c | 13 +++++++------ 1 file changed, 7 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..6f52b4db9cc9 100644 --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c @@ -290,15 +290,16 @@ 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; + u32 *offsets; =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) + offsets =3D krealloc(validated_shader->uniform_addr_offsets, + (o + 1) * + sizeof(*validated_shader->uniform_addr_offsets), + GFP_KERNEL); + if (!offsets) return false; =20 + validated_shader->uniform_addr_offsets =3D offsets; validated_shader->uniform_addr_offsets[o] =3D num_uniforms; validated_shader->num_uniform_addr_offsets++; =20 --=20 2.54.0