From patchwork Wed Oct 23 08:56:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurentiu Palcu X-Patchwork-Id: 13846777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CFB23D2E02B for ; Wed, 23 Oct 2024 09:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=hKjakOuYaQ+ewzNw+5YLMhWRUTzBaiWnAb14uJ5PHy8=; b=zazvf5JE3hgliN+LFivN5MrOoi 9RmWSA7u/XkqFEnjfaV4JlWbYmcdPMqFgvMKE/3kojXROzV17kI15EimLg8JSqv39d76DsxIR5His yVNqgbDP4HkQU3rbN2ONBaFdkWJBC7uYeYYTwhvLl6l71GScbJuAhozRxoZMaMXOLa903CXcMy2NQ Hba0zQDVwYckUwxJkjjhHxr5QWkUd3YNGrZBtzJtUq7H1Crg4mBIZiuIxKeplc1XZIkoid6tKeCJg kQziFm635uLYUtbWmo/Q5nyF195DPfC4gR20x0obxCFa++GwNVRSC5Zuiyr34SV2+NBOFR695NN06 4ZmSFMZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3XNA-0000000Diw9-0emL; Wed, 23 Oct 2024 09:09:44 +0000 Received: from mail-am7eur03on2061a.outbound.protection.outlook.com ([2a01:111:f403:260e::61a] helo=EUR03-AM7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3XAk-0000000DfAm-3bq0 for linux-arm-kernel@lists.infradead.org; Wed, 23 Oct 2024 08:56:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FnFkZlIaV6291t5bwo7Z1dxEol4bRgK4HCVPzBT8OwB1bNBhIAE9vJSCSANYiSQCLv3BZYWjus4pPDtRSdzDpjdRHDWGkXrMPSnO3OAtDVSt8q3xuJ0kqWMbk1O31xttPwlBhp6di0iZGlUKj067uk5w/wcegd7eXrPZSGzis4Ghgi8NrzQADzM1IdC+9g3LtwNywLcLdvCjaSulAtW+6cCBIzHxTRUqBRg1lh1zyddAimI+em5Ud92HmJJFsFc+YQYVFSEyq8L7WL10fa25u4RxDZAv14TAH9iZZjQ2GzfD0kLQqJadEbtfnVjx+iyScT5oVsvUD4FJ1az9Oa72QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hKjakOuYaQ+ewzNw+5YLMhWRUTzBaiWnAb14uJ5PHy8=; b=Me2OHuDh9QyVzRjTcT/O1+/Esmcl+ePkkMTxKI3HhJfWkWvGB7Gs9ILFixIy5EX27uksMqtTiHUiXcSySN09moTd2Gs94vIRwHmvvh6ctYifDxeE4bf80oynOiBr0HUxw5X+NMWO8LTEV34Gi5/5v0i6htpLMUM3ULwXeTqxj1HmCONYrg3DtHrHwZAo7c6VzKbPkq0GlDlz3XeXt0mmxMP/BhPgj3Rh9a7uX9LmyURK48epm7e0uVWVyf+82nrty029XFGSi4appAEInVMQgzSCl8XebhiJDJbf9Y33Pd3bLyB+h4tIOtidVE6pnZxt96LT2DuHmPkL+1v40+Z+WQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hKjakOuYaQ+ewzNw+5YLMhWRUTzBaiWnAb14uJ5PHy8=; b=wB0WXV6LWORD/wa9597Us8MSSQGNPKnrDAkZ0HD/LdvHqpw4V3DKrBXGTXqo9GWcCBzowUpmks+Bn3ZvVD11RoHIq5XRRCGcuNIA6hxw/2ui5zEO5NVInspevh1HtCAsF4WsPMFKjO8qohMSZeXoWklaPACcQt3/Sz8m4MKBbIW8YyuLPGHaMvuKCIu2Hz6rp4vB0Yztawzy+4XFKfDww/ZkFuQgXUf7CNfmi40n5D6Algl8KFWiUSNxVjaq6pD7nN302ImrtHYLvFN7uM9WtrRL9RGBC7j0/M6WmO+k2oQ0YmxgKOUUWsFJIN4J2J7KXAedHdJ4upVM3kAe3cxvcw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AS4PR04MB9576.eurprd04.prod.outlook.com (2603:10a6:20b:4fe::12) by PA4PR04MB7936.eurprd04.prod.outlook.com (2603:10a6:102:c6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.18; Wed, 23 Oct 2024 08:56:48 +0000 Received: from AS4PR04MB9576.eurprd04.prod.outlook.com ([fe80::9cf2:8eae:c3d1:2f30]) by AS4PR04MB9576.eurprd04.prod.outlook.com ([fe80::9cf2:8eae:c3d1:2f30%7]) with mapi id 15.20.8069.027; Wed, 23 Oct 2024 08:56:48 +0000 From: Laurentiu Palcu To: Laurent Pinchart , Mauro Carvalho Chehab , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Dong Aisheng , Jacopo Mondi , Christian Hemp , Guoniu Zhou Cc: Laurentiu Palcu , Stefan Riedmueller , linux-media@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] media: nxp: imx8-isi: better handle the m2m usage_count Date: Wed, 23 Oct 2024 11:56:43 +0300 Message-Id: <20241023085643.978729-1-laurentiu.palcu@oss.nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: AS4P190CA0019.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:5d0::18) To AS4PR04MB9576.eurprd04.prod.outlook.com (2603:10a6:20b:4fe::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS4PR04MB9576:EE_|PA4PR04MB7936:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a3e8f73-386a-4823-3736-08dcf340a095 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024|921020; X-Microsoft-Antispam-Message-Info: Mtj7hNstWzbQaXpNo4jPQcOg3XCsA/Xa94NFYaKGqMXph3XQBy3kv0CwY8DbdbR4qZZ6o/MG95MqC0ZVjJeVgNOf6l9mvIn2KWXx3NX6GssOSiBsi1ydhHhG1Ed+xKM2QueU8ACNFt/43+BYKF0ypE+MzgYD2ZyrWXWe0ijqdCnnXms4r/IWU823N8hO31sAyz3hejaoysvM75F7yxHWNu1PDsmVY1Y5/4TpM05BUdwlIpes1w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l8vlKZ77lse8lvARlUAmVNM1wHEGcW105CgTiVNLYjUymhUCkaPWZzyElu7i50/nz6ZrXkX9/+se8izY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS4PR04MB9576.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Rgbt6fqncOSwL70HC1gRESK6oHSnt/Td+6zn08QOR+24xsr3wmB9bD8UD1mLPN9t/gPrsxeRUEdR6X1h3pyfP5Wm/JurnP6D5PSQcU/tP1BV4EsLOObpiK1p7QGjRkgwGB2NsMWNcHVCfP4DqM+hj0h99KviMFTcOB+/gyZwODLMnoEuKCgyFrKkkc9OkqDlNYJVnF3rI54m+71de3dlcKzMDbfYDkaTUlJukGZ0VgdJjKqZfq//UOnkiet5PYSjXH46IqLCM21DE13agy7zcCWdzpT4H+8E4YRsGncuUu0rCxWSxmqK6hgQXiwCPaiBu/obGGKtDD6jnLtnxorW58NEV+QB0yOmoN1c4vbi9enPNqej7HKa3puCDXJvY+QkhfuSSL2uIlkzpDZ47tdlM2HVPyd4DVD8mv8KBfgm75c0ymbfG4Ar1YoHuuzhhqd9F5oi0+8kQ82nNM5AIcgMc6excKoMilw4T9TXXa+rDOpyB5vA667y9+NKB/CEAlB64/six2ihoKSKcB77Lxog47A7mWJ2Cn6RQ9B3DNbQWrtMPNGG4ZCCtfgpPlz/enmFOFYAmt4aNIyYA+htRcRweW6vqWoA8cZrY5batznkkBMUl6PPUKl0IlbOaDQBV6UQGJHUWnUyPnPwqM4QIBZyCFgIDPGgGmNC6+HhRFBTABxCjGjC96OpK7axb0B7yfYSMhV33faJYkIZo5Ydpix7ZMS0biA8zauvSO2yb0cBcQJw+hSJnNzITit5mlDZxSoXuOUV4AD8je6J6NbKMPmWgtENLtUUyauJpaqZOfjubtHL6Hjm9T5XmBeSgEvO/KQRmDl0hqlVaCzxwULIb82YYVyVZHX6OwqHlG0J0/iJg53f3TwZrk/JbV5nTZb3OGS3hDZmLD1DFVH/0T+ITGnRK+m5FYuCTgDu8R1RujiPfhNpbV5wAnS2cU0l4thg7eCFvFTcIQAM/Qd83nSXLe4dw/eKveqTjybfJLpgyAbOyLfxicNcR+khX1MAyZ8zDamZkCKkOHmXlHzzt0Q8IECWx1hbwPb3DPImEO5PCHiykX3dn3PIw7Nnm2+vhTDUIV2fxH0xJQ4UVVyTsrW9F8IEZ1DqvqAO6T5D49jIdLcoaQggXtW7+WISlu1SsEwCMgjB2uubQeMDHRF1Bc+Bx04+kVcdkFebzgoujU5Bq0flW/uRtwoFzOSpYmAa6utDtuQXKWWY3ivzMZgmptrzmid/nSOOhWOUihgs0jw/6943goioU/IMeuJZJReuUtM4Al8ewbIPRt/MCBqr1aubHWHCJCHCmCX2YxE/Wca1/0rPrTWBqJ1x0Huag/WIFqCc6JcQudTh13Zp9jKz13SQ71x452Od7c6qQHuMwREQjK1j+RixpA2ppq09Yq6yIdVI7CQ+IpJIVv0BoBbQuVg9CEoNtzHAHhF5bEyc/owKKY3ymnnXj3s/cgcBTDbZ1R/pWbANiwrL+ISbnEJchOW1sk51CqYb4f/t/7/OxGFvZPuPJ0TX7z+PMwUemqO+hmmCGxzxQJoH8pmfJEJNNmJa4DArmqU+GLhEr9R+EHMIFXpjzYPDeaCeKzaHB5bTA4u2+Df4qudm5RXDl1pkBEe3J+VSjw== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a3e8f73-386a-4823-3736-08dcf340a095 X-MS-Exchange-CrossTenant-AuthSource: AS4PR04MB9576.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 08:56:47.9795 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1wbMa4IocgeA9FzYUqQh3kixFzqYxZLQg7+d/oajC/3IgzehagKNnjH5U+p/eUCIEhkwjzuslma72m325Sxl5w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7936 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241023_015654_935759_97F8681F X-CRM114-Status: GOOD ( 15.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, if streamon/streamoff calls are imbalanced we can either end up with a negative ISI m2m usage_count (if streamoff() is called more times than streamon()) in which case we'll not be able to restart the ISI pipe next time, or the usage_count never gets to 0 and the pipe is never switched off. To avoid that, add a 'streaming' flag to mxc_isi_m2m_ctx_queue_data and use it in the streamon/streamoff to avoid incrementing/decrementing the usage_count uselessly, if called multiple times from the same context. Fixes: cf21f328fcafac ("media: nxp: Add i.MX8 ISI driver") Suggested-by: Laurent Pinchart Signed-off-by: Laurentiu Palcu --- v3: * Changed the implementation as suggested by Laurent and add a Suggested-by tag to reflect that; v2: * Changed the way 'usage_count' is incremented/decremented by taking into account the context the streamon/streamoff functions are called from; * Changed the commit message and subject to reflect the changes; drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c index 9745d6219a166..dc10e1a9f27c1 100644 --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c @@ -43,6 +43,7 @@ struct mxc_isi_m2m_ctx_queue_data { struct v4l2_pix_format_mplane format; const struct mxc_isi_format_info *info; u32 sequence; + bool streaming; }; struct mxc_isi_m2m_ctx { @@ -486,6 +487,7 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh, enum v4l2_buf_type type) { struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh); + struct mxc_isi_m2m_ctx_queue_data *q = mxc_isi_m2m_ctx_qdata(ctx, type); const struct v4l2_pix_format_mplane *out_pix = &ctx->queues.out.format; const struct v4l2_pix_format_mplane *cap_pix = &ctx->queues.cap.format; const struct mxc_isi_format_info *cap_info = ctx->queues.cap.info; @@ -495,6 +497,9 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh, int ret; + if (q->streaming) + return 0; + mutex_lock(&m2m->lock); if (m2m->usage_count == INT_MAX) { @@ -547,6 +552,8 @@ static int mxc_isi_m2m_streamon(struct file *file, void *fh, goto unchain; } + q->streaming = true; + return 0; unchain: @@ -569,10 +576,14 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh, enum v4l2_buf_type type) { struct mxc_isi_m2m_ctx *ctx = to_isi_m2m_ctx(fh); + struct mxc_isi_m2m_ctx_queue_data *q = mxc_isi_m2m_ctx_qdata(ctx, type); struct mxc_isi_m2m *m2m = ctx->m2m; v4l2_m2m_ioctl_streamoff(file, fh, type); + if (!q->streaming) + return 0; + mutex_lock(&m2m->lock); /* @@ -598,6 +609,8 @@ static int mxc_isi_m2m_streamoff(struct file *file, void *fh, mutex_unlock(&m2m->lock); + q->streaming = false; + return 0; }