From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384740; b=0oh6EM2mIYmI7oQgnW3G5g8Lg/jhKPK6AEzwnOauZDvZpUJ+gsK2fiau0m3lhWVaS2zX BDYu3ZjmWZero+eoRYJrkP+a+buRTrKbfmxYvZT1QcLvseCrHwpBkvok2t7ojDDFBZwsn nHm4DSZRhHZuAahb5nWj2QN6D4fIJgdu6Cge/dUwqbJK/af1n4kJIhX+OvBcXhMc70TJh hRRkncBqOf4A6xvJ6MpmzNm848MHbfs5mB5RDzIKuRmgQx7rEQ2lOojYNyUfGoMqtad/F ZXXgYuRK5t6KjeFywOBVfRjX59+yBE5acJqrBA6j75OZ77hCYKDrBiBhn5VDoARrEHw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384740; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=2ZHyTDVOAgLFYM7Y5RTsEYS9atBoh63SrNmhNuWIy20=; b=WEQG7AL9MWn2Z2TsVhCGQ+IL1vY0HYnZ3M/cv6A80c83zQ8p3G7OaWJydQundSDWDy1W 7zBUG29urwGKziB6yveoGxfVUmNpL1epOcIaDIZ63UQbDRXdsZ4flbSDgB9Aik+gvIEI6 mDYwpoc9QCeRLEJWMaQS77CsegCXymm6a2sQYd/c5hf7pQ5iG7/fDKvkTmaUc2/CRE2lc N2rL9Q6wlgiBClG8phJ5obstEVDNxiOxFXZj9FAbjZNjbUq2UBgvuzABDDxwfFfk+uG9z XDO6CnNy+mzGWQhFIAiD5qDwx8mB8y97P/f1M4rIJYbexdcUYFgCrb0Rfn5e1y13yAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=S5U0hYgT; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AB4D606A322; Fri, 4 Dec 2026 11:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=S5U0hYgT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A0591F000CE; Fri, 4 Dec 2026 11:45:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384739; bh=2ZHyTDVOAgLFYM7Y5RTsEYS9atBoh63SrNmhNuWIy20=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=S5U0hYgT4i7rwodVcV6opB8A0pE6Kp7FfgApp6Adl7RneAK0MaRsqEQxdkaIxUs8p LfPrrKICR+FsJvtIpoLQqatAo+CEMRWQXCaRvkU+z/xXJoHVtCCzf8wcu3nsWW99QO kFoaL1HP+/xZEx8L4waE7TCDnj+rponrVom+ko5I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Fan Wu , Hans Verkuil , Sasha Levin Subject: [PATCH 6.6 0272/1167] media: marvell: mcam: stop DMA and cancel s_bh_work before freeing DMA buffers Date: Fri, 4 Dec 2026 18:54:59 +0900 Message-ID: <20261204100709.141247183@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Fan Wu [ Upstream commit 0f29f84317c1e35f6a9265277be33e60d3fc8c1c ] In vmalloc mode the frame-completion IRQ queues mcam_frame_work() on cam->s_bh_work, which memcpy()s from the dma_bufs[] that mcam_free_dma_bufs() frees with dma_free_coherent(). mccic_shutdown() frees those buffers without stopping the controller, so while streaming a late frame IRQ can re-arm the work after the buffers are gone, causing a use-after-free. Stop the controller in mccic_shutdown() when streaming is still active (gated on an open fd, which holds a runtime-PM reference, so the device is powered), cancel s_bh_work in mcam_free_dma_bufs(), and move INIT_WORK() into mccic_register() before the device can be published. Fixes: 67a8dbbc4e04 ("[media] marvell-cam: Basic working MMP camera driver") Cc: stable@vger.kernel.org Signed-off-by: Fan Wu Signed-off-by: Hans Verkuil [ sashal: Replaced cancel_work_sync() and INIT_WORK() on the bottom-half work item with tasklet_kill() and tasklet_setup() on the existing s_tasklet, since this tree still uses a tasklet. ] Signed-off-by: Sasha Levin --- drivers/media/platform/marvell/mcam-core.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/marvell/mcam-core.c b/drivers/media/platform/marvell/mcam-core.c index 555f560238c9a..a1d5ea4b82889 100644 --- a/drivers/media/platform/marvell/mcam-core.c +++ b/drivers/media/platform/marvell/mcam-core.c @@ -406,6 +406,8 @@ static void mcam_free_dma_bufs(struct mcam_camera *cam) { int i; + tasklet_kill(&cam->s_tasklet); + for (i = 0; i < cam->nbufs; i++) { dma_free_coherent(cam->dev, cam->dma_buf_size, cam->dma_bufs[i], cam->dma_handles[i]); @@ -1310,7 +1312,6 @@ static int mcam_setup_vb2(struct mcam_camera *cam) break; case B_vmalloc: #ifdef MCAM_MODE_VMALLOC - tasklet_setup(&cam->s_tasklet, mcam_frame_tasklet); vq->ops = &mcam_vb2_ops; vq->mem_ops = &vb2_vmalloc_memops; cam->dma_setup = mcam_ctlr_dma_vmalloc; @@ -1868,6 +1869,12 @@ int mccic_register(struct mcam_camera *cam) goto out; } +#ifdef MCAM_MODE_VMALLOC + /* Init before sensor bind: armed by IRQ, cancelled on probe-error paths. */ + if (cam->buffer_mode == B_vmalloc) + tasklet_setup(&cam->s_tasklet, mcam_frame_tasklet); +#endif + mutex_init(&cam->s_mutex); cam->state = S_NOTREADY; mcam_set_config_needed(cam, 1); @@ -1926,10 +1933,15 @@ void mccic_shutdown(struct mcam_camera *cam) * take it down again will wedge the machine, which is frowned * upon. */ + mutex_lock(&cam->s_mutex); if (!list_empty(&cam->vdev.fh_list)) { cam_warn(cam, "Removing a device with users!\n"); + /* Stop so the IRQ can't re-arm s_tasklet after the buffers are freed. */ + if (cam->state == S_STREAMING) + mcam_ctlr_stop_dma(cam); sensor_call(cam, core, s_power, 0); } + mutex_unlock(&cam->s_mutex); if (cam->buffer_mode == B_vmalloc) mcam_free_dma_bufs(cam); v4l2_ctrl_handler_free(&cam->ctrl_handler); -- 2.53.0