From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1ED68426EAB; Wed, 4 Feb 2026 15:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770217630; cv=none; b=X+m7DKs732qonLRS1WMiB3O4bRZL0G+JmOxqa3a9eVAXAwCQgZd0f0SvqmYDKFwPs2VfnnHmrlJgE37IIUz+YFnlxmGox3f0e0j4w3Bk20Ri3ZVsx967m2xfNTfBg+RrECWt6HoyOCowGibqV1OMjm4IunSrutWewWPWQkxAUoM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770217630; c=relaxed/simple; bh=dTDI17AK/P/I9WfdeewUqwTjOQ+Zpg/VIgGGUJ0tNIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CxCRd6owfI1u1/m1OqQDCMXTbVs47CwSLZ03pDrfU1y6kiFST7si4P+2aYUA0g/AmMNFmhsDW0sKuImrVmvyrvU0lG3n1LXhWF9TPXQ7dvhFVjX5rDJhPUxcK/wl4ErLJ8tSdaQH2/uE7fzcERNMv0y3/csZmMg8dkP0k5p8e/A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=F5FABDFW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="F5FABDFW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 394A4C116C6; Wed, 4 Feb 2026 15:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1770217629; bh=dTDI17AK/P/I9WfdeewUqwTjOQ+Zpg/VIgGGUJ0tNIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F5FABDFWgzswnKl/IPzBIlzvKuE0G0Qt0OqOTIXE+UChWIUIAQx2sCRMtpAO6L4un vNkzOgBXBseQ3UaNDHBDUmnmqwIK7/Qhj221hHZmZLzSKOnpX1uv1kr3vS4o5BAYS0 fKOe/uz34ftQT6FJLRLTZHY2Ut6MXNVNuSSfwc0k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Miaoqian Lin , Bjorn Andersson , Vinod Koul Subject: [PATCH 6.1 072/280] dmaengine: qcom: gpi: Fix memory leak in gpi_peripheral_config() Date: Wed, 4 Feb 2026 15:37:26 +0100 Message-ID: <20260204143912.247701085@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260204143909.614719725@linuxfoundation.org> References: <20260204143909.614719725@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Miaoqian Lin commit 3f747004bbd641131d9396d87b5d2d3d1e182728 upstream. Fix a memory leak in gpi_peripheral_config() where the original memory pointed to by gchan->config could be lost if krealloc() fails. The issue occurs when: 1. gchan->config points to previously allocated memory 2. krealloc() fails and returns NULL 3. The function directly assigns NULL to gchan->config, losing the reference to the original memory 4. The original memory becomes unreachable and cannot be freed Fix this by using a temporary variable to hold the krealloc() result and only updating gchan->config when the allocation succeeds. Found via static analysis and code review. Fixes: 5d0c3533a19f ("dmaengine: qcom: Add GPI dma driver") Cc: stable@vger.kernel.org Signed-off-by: Miaoqian Lin Reviewed-by: Bjorn Andersson Link: https://patch.msgid.link/20251029123421.91973-1-linmq006@gmail.com Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/qcom/gpi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/dma/qcom/gpi.c +++ b/drivers/dma/qcom/gpi.c @@ -1621,14 +1621,16 @@ static int gpi_peripheral_config(struct dma_chan *chan, struct dma_slave_config *config) { struct gchan *gchan = to_gchan(chan); + void *new_config; if (!config->peripheral_config) return -EINVAL; - gchan->config = krealloc(gchan->config, config->peripheral_size, GFP_NOWAIT); - if (!gchan->config) + new_config = krealloc(gchan->config, config->peripheral_size, GFP_NOWAIT); + if (!new_config) return -ENOMEM; + gchan->config = new_config; memcpy(gchan->config, config->peripheral_config, config->peripheral_size); return 0;