From nobody Fri Apr 3 01:31:23 2026 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 BC87C27C84E; Fri, 20 Feb 2026 08:15: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=1771575309; cv=none; b=FAP8EVwCEmrsy2yvU/8zhuUD8UmlbCN1eKckqNKWolbFPaIZD8ztOSJl+ExVDZXS8vihaHlyug5kfOJWn2RsAbpm2G7YPKi9eTgGmap8w+4LRyLtRI17y4xp+Dmf0tKyP7Xh/1Pi+zITv3OBt9rnJ1KJv1YoaiD5Dfk6Qx0DoOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771575309; c=relaxed/simple; bh=g/dKe7ealZ2Roz+w0mia01uKOCP+aV0TUZ6SoON1WvU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PSQGsF13CJvPuC+KxxOgYg62j89GQpZficTF1ig+1tt13CMP4ea6QXvuTFBdLjqbNlCZTGHapcLhnQCW/BL+oN1vMynscy28vqAH82Z/vIOLci8aJlaGR7EjgV7dLQRfyI7ymrBe7afcRGZWkBmgRqp92aKAgZ/T+pPPrjLubiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m7WmexyX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m7WmexyX" Received: by smtp.kernel.org (Postfix) with ESMTPS id 71332C19424; Fri, 20 Feb 2026 08:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771575309; bh=g/dKe7ealZ2Roz+w0mia01uKOCP+aV0TUZ6SoON1WvU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=m7WmexyXFUpR564zdYVzl0jpUfbGWki2B868oYV9SvP2w1U978QnEU+GW/KUkUFYZ prX5H9PAGydDhOh4KN1gPMr2PqzkZkVAQMj9UI4X8bfBc7aeMWIoiwdgEa04Wrc0l/ yNuH6GewHmQviG/dBWIgjvPYDLXtRft6D50lWpw715FYHiSYeVE9mmd1SBVUGMqfKT H7aZ6biFyUAkgLcPMwP1rpQNTOiFxSZvMeLgshLqOB/UbQOVLT2Zjd58HatB8FNYfJ XilNxGFXx446icJCucRLLpWX8LPiFVX8d37QjNTDi/k023SdGPplo65P9bgf0DJaQa vCcQMYv6sIb6Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CE4EC54FD4; Fri, 20 Feb 2026 08:15:09 +0000 (UTC) From: Michael Riesch via B4 Relay Date: Fri, 20 Feb 2026 09:15:07 +0100 Subject: [PATCH v2 1/2] media: rockchip: rkcif: fix off by one bugs 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 Message-Id: <20260216-rkcif-fixes-v2-1-ee40931fe0ff@collabora.com> References: <20260216-rkcif-fixes-v2-0-ee40931fe0ff@collabora.com> In-Reply-To: <20260216-rkcif-fixes-v2-0-ee40931fe0ff@collabora.com> To: Dan Carpenter , Paul Elder , Laurent Pinchart , Mehdi Djait , Mauro Carvalho Chehab , Heiko Stuebner , Sakari Ailus , Hans Verkuil , Bryan O'Donoghue Cc: Collabora Kernel Team , stable@kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Michael Riesch , Chen-Yu Tsai X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1771575308; l=2303; i=michael.riesch@collabora.com; s=20250410; h=from:subject:message-id; bh=+CTMmqq/FBf0OUNoxM2h1AJhLJnTaBpUVbDN8g6FJXc=; b=jkqMSDUDANKBRHHyuTdC4NY7nDzfs9Wzk6LdU8E0ORJ+OVHx360FP8JRfy5VTJk4vVrWWJ7MQ HVgUvXIym14CwVEQA2gWZ/Cq0XPnkiR8U22M7NCl4m2YbgLdCjOcg6X X-Developer-Key: i=michael.riesch@collabora.com; a=ed25519; pk=+MWX1fffLFZtTPG/I6XdYm/+OSvpRE8D9evQaWbiN04= X-Endpoint-Received: by B4 Relay for michael.riesch@collabora.com/20250410 with auth_id=371 X-Original-From: Michael Riesch Reply-To: michael.riesch@collabora.com From: Dan Carpenter Change these comparisons from > vs >=3D to avoid accessing one element beyond the end of the arrays. While at it, use ARRAY_SIZE instead of the _MAX enum values. Fixes: 1f2353f5a1af ("media: rockchip: rkcif: add support for rk3568 vicap = mipi capture") Cc: stable@kernel.org Signed-off-by: Dan Carpenter Reviewed-by: Michael Riesch Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart Tested-by: Chen-Yu Tsai [fix cosmetic issues] Signed-off-by: Michael Riesch --- drivers/media/platform/rockchip/rkcif/rkcif-capture-mipi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-capture-mipi.c b/d= rivers/media/platform/rockchip/rkcif/rkcif-capture-mipi.c index 1b81bcc067ef..9e67160a16e4 100644 --- a/drivers/media/platform/rockchip/rkcif/rkcif-capture-mipi.c +++ b/drivers/media/platform/rockchip/rkcif/rkcif-capture-mipi.c @@ -489,8 +489,8 @@ static inline unsigned int rkcif_mipi_get_reg(struct rk= cif_interface *interface, =20 block =3D interface->index - RKCIF_MIPI_BASE; =20 - if (WARN_ON_ONCE(block > RKCIF_MIPI_MAX - RKCIF_MIPI_BASE) || - WARN_ON_ONCE(index > RKCIF_MIPI_REGISTER_MAX)) + if (WARN_ON_ONCE(block >=3D ARRAY_SIZE(rkcif->match_data->mipi->blocks)) = || + WARN_ON_ONCE(index >=3D ARRAY_SIZE(rkcif->match_data->mipi->regs))) return RKCIF_REGISTER_NOTSUPPORTED; =20 offset =3D rkcif->match_data->mipi->blocks[block].offset; @@ -510,9 +510,9 @@ static inline unsigned int rkcif_mipi_id_get_reg(struct= rkcif_stream *stream, block =3D stream->interface->index - RKCIF_MIPI_BASE; id =3D stream->id; =20 - if (WARN_ON_ONCE(block > RKCIF_MIPI_MAX - RKCIF_MIPI_BASE) || - WARN_ON_ONCE(id > RKCIF_ID_MAX) || - WARN_ON_ONCE(index > RKCIF_MIPI_ID_REGISTER_MAX)) + if (WARN_ON_ONCE(block >=3D ARRAY_SIZE(rkcif->match_data->mipi->blocks)) = || + WARN_ON_ONCE(id >=3D ARRAY_SIZE(rkcif->match_data->mipi->regs_id)) || + WARN_ON_ONCE(index >=3D ARRAY_SIZE(rkcif->match_data->mipi->regs_id[i= d]))) return RKCIF_REGISTER_NOTSUPPORTED; =20 offset =3D rkcif->match_data->mipi->blocks[block].offset; --=20 2.39.5 From nobody Fri Apr 3 01:31:23 2026 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 A2EC0C145; Fri, 20 Feb 2026 08:15: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=1771575309; cv=none; b=JljVP66/GRbQawYh/6a2xwWXWgmdiX3CtHdsg3k5tOIwipw5um4dhUr8QTycjiyAudH4z8j2zbfUk9lZ6U+9uVVs7o6gKBxT1/RbJuRUqB6+92AowcR63KWwJNKT7cyp/k+uGnt7M7iL3yhk1UwTcVJOLnsFPIOlJJL30fEC4D8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771575309; c=relaxed/simple; bh=jtkgWkJjHoviWzC1L3qi3r1Sfz0YtO2chH+woXl6s5E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QpBlJ8bKtoHNym2NHwgzjSfpr0Orsx1hMt7OJqeqICtxOqoPfgVYvScda1qBeSRfP7+3No+4j8/uoInzs1o8Pc4nl7SWG0JMBX9fwf7YlbZEJcgzeDdBWxFuiMq49t/Vuet6VEfQGIaCO2ituJ9H85CHZhLYQkAi9HcMLyv+2H8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jPkTRKBI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jPkTRKBI" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7A797C116D0; Fri, 20 Feb 2026 08:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771575309; bh=jtkgWkJjHoviWzC1L3qi3r1Sfz0YtO2chH+woXl6s5E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=jPkTRKBIdV8vbcuEUJHyULqSjI8oaWmDKLMP/Ibfi37LtwN9ix5QkJGbSiSHiOLxc o0xj8L19NMDC5J3fRMHAwbwRsGstSCqWOoJClb/wgzmwq+tm3GvnpfBKdNZPVw7gWq XYduAEtQQXNi48HMACHIqiGncGjGGXzFsjQnN/Y2j00maerUQ6ES49iSTlX/d8w+xc uAr3lvJaUp05PJip7hNFCOdd1Q7Oh+G2Q584Wxm49i690pRRAysmumcrA0a4n8qklc t5uvb4omELk9evaUCk7slGWm9LyGMKn/9AyChweLkOP+NZJzxGkDNzRPo6jhYxdY9W mQ58Lb/w6fCSw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DCB8C55162; Fri, 20 Feb 2026 08:15:09 +0000 (UTC) From: Michael Riesch via B4 Relay Date: Fri, 20 Feb 2026 09:15:08 +0100 Subject: [PATCH v2 2/2] media: rockchip: rkcif: comply with minimum number of buffers requirement 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 Message-Id: <20260216-rkcif-fixes-v2-2-ee40931fe0ff@collabora.com> References: <20260216-rkcif-fixes-v2-0-ee40931fe0ff@collabora.com> In-Reply-To: <20260216-rkcif-fixes-v2-0-ee40931fe0ff@collabora.com> To: Dan Carpenter , Paul Elder , Laurent Pinchart , Mehdi Djait , Mauro Carvalho Chehab , Heiko Stuebner , Sakari Ailus , Hans Verkuil , Bryan O'Donoghue Cc: Collabora Kernel Team , stable@kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Michael Riesch , Chen-Yu Tsai X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1771575308; l=2843; i=michael.riesch@collabora.com; s=20250410; h=from:subject:message-id; bh=QlnSURdd8Dclxdp8UA+BrdFUZIn2tw+OGzLWQP2V3Uw=; b=aUmJLnmSesafA20KayfGrJ/nBjA/G1S1v3FbSvXyYUCwd5vve4+NrwlAD+vjZ2DpAv+UGoK7N yAS0hKGcYuJDspP8YEFpbSn/FGQKkYY5q0FtMoVclqlMwAbF0CmqgM/ X-Developer-Key: i=michael.riesch@collabora.com; a=ed25519; pk=+MWX1fffLFZtTPG/I6XdYm/+OSvpRE8D9evQaWbiN04= X-Endpoint-Received: by B4 Relay for michael.riesch@collabora.com/20250410 with auth_id=371 X-Original-From: Michael Riesch Reply-To: michael.riesch@collabora.com From: Michael Riesch Each stream requires CIF_REQ_BUFS_MIN=3D1 buffers to enable streaming. However, it failed with only one buffer provided. Comply with the minimum number of buffers requirement and accept exactly one buffer. Fixes: 501802e2ad51 ("media: rockchip: rkcif: add abstraction for dma block= s") Cc: stable@kernel.org Tested-by: Paul Elder Tested-by: Chen-Yu Tsai Signed-off-by: Michael Riesch Reviewed-by: Isaac Scott Reviewed-by: Paul Elder --- .../media/platform/rockchip/rkcif/rkcif-stream.c | 44 +++++++++++-------= ---- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c b/drivers= /media/platform/rockchip/rkcif/rkcif-stream.c index e00010a91e8b..f15bee4f7cd7 100644 --- a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c +++ b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c @@ -106,42 +106,42 @@ static int rkcif_stream_init_buffers(struct rkcif_str= eam *stream) { struct v4l2_pix_format_mplane *pix =3D &stream->pix; =20 - stream->buffers[0] =3D rkcif_stream_pop_buffer(stream); - if (!stream->buffers[0]) - goto err_buff_0; - - stream->buffers[1] =3D rkcif_stream_pop_buffer(stream); - if (!stream->buffers[1]) - goto err_buff_1; - - if (stream->queue_buffer) { - stream->queue_buffer(stream, 0); - stream->queue_buffer(stream, 1); - } - stream->dummy.size =3D pix->num_planes * pix->plane_fmt[0].sizeimage; stream->dummy.vaddr =3D dma_alloc_attrs(stream->rkcif->dev, stream->dummy.size, &stream->dummy.buffer.buff_addr[0], GFP_KERNEL, DMA_ATTR_NO_KERNEL_MAPPING); if (!stream->dummy.vaddr) - goto err_dummy; + return -ENOMEM; =20 for (unsigned int i =3D 1; i < pix->num_planes; i++) stream->dummy.buffer.buff_addr[i] =3D stream->dummy.buffer.buff_addr[i - 1] + pix->plane_fmt[i - 1].bytesperline * pix->height; =20 - return 0; + stream->buffers[0] =3D rkcif_stream_pop_buffer(stream); + if (!stream->buffers[0]) + goto err_dummy_free; + + stream->buffers[1] =3D rkcif_stream_pop_buffer(stream); + if (!stream->buffers[1]) { + stream->buffers[1] =3D &stream->dummy.buffer; + stream->buffers[1]->is_dummy =3D true; + } =20 -err_dummy: - rkcif_stream_return_buffer(stream->buffers[1], VB2_BUF_STATE_QUEUED); - stream->buffers[1] =3D NULL; + if (stream->queue_buffer) { + stream->queue_buffer(stream, 0); + stream->queue_buffer(stream, 1); + } + + return 0; =20 -err_buff_1: - rkcif_stream_return_buffer(stream->buffers[0], VB2_BUF_STATE_QUEUED); - stream->buffers[0] =3D NULL; -err_buff_0: +err_dummy_free: + dma_free_attrs(stream->rkcif->dev, stream->dummy.size, + stream->dummy.vaddr, + stream->dummy.buffer.buff_addr[0], + DMA_ATTR_NO_KERNEL_MAPPING); + stream->dummy.vaddr =3D NULL; return -EINVAL; } =20 --=20 2.39.5