From patchwork Mon Nov 21 06:34:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 13050352 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 3A232C433FE for ; Mon, 21 Nov 2022 06:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=gnoXUPQh/PgfpeHvdytXUXUwnPS8sdz2HSc4rDyOlG4=; b=pZ5Wfevg0tZ/Xt THR0/BuoKJ1rTt80qM93WlkIxXd3Sej9557sWcvpsItu0ohqeLEoyCYM7VUCqZeladWXx0CGSIEmu QJP1drNFXOYu739eON6c7lI4KT3RD6Cd5y1Sdlq44GgsYOahe5XDAhpQREbKljK6/Kok0X2o/buF8 L9qg5F1jswIouCs5sG8W3n8cPtOk1QPS9ZQj/sEyoMTgV1b0jDV1TlHSgRbQBL0WzTJzvv1bJltev hlpN99lBl70IQpRYMfBqaysIJeUHjj2DIKuf6SkVxLKN8z7LHJxXOI/7Pj9FmGvGHHceajjC9YxgI MwFFE0YSTtbPszIOtoPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ox0Om-009rMb-E0; Mon, 21 Nov 2022 06:35:20 +0000 Received: from mail-am6eur05on20616.outbound.protection.outlook.com ([2a01:111:f400:7e1b::616] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ox0Ok-009rL6-AU for linux-arm-kernel@lists.infradead.org; Mon, 21 Nov 2022 06:35:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a5vSUSZsZOTYDDEDMVDX28loSIqICb3YjS4WshmKSinxQ5Yu7dBdE/Sx08dLkkHetrSS4W5gsn8aTfOHOZBwLDL3+V1n+22ZizHkk3ITs+47TYjarHvlXUsLlvbwggjr7dwrYpPGejH5VsEZi+X8AS1MF05W6qH0dBsLVzuHV27vx0fIucUhlJLPaZv8ip1yhL36dWiPoVZiYh6qqQGbacQwQoDHKA0AmcY1zhfOULoo6JFO7ByO1ii119AAl0Rf5IDrcyE6p9PAtEqV9P1fXgUjpbHIFPIo5AtJJpXv6aiBydJcT3ZHMIgAtA29ok5i8yJlgOl+SdO6bTYWYSKkzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=hfhVT7FQpbc86Ob1Ku1QmxqQqk7KeVMCCIN4okjmBAw=; b=kN7xG3M8ag3jGidUhvlcajYHgm7YrebnExZRtiJgjdoAxt3USWBf2PJ6dLyS6mN+gYsbCdJdsYTCHkgypMfKK0t5blvnSN9cWP3KzhfDdipmxJAzC8xwW0882wF9nzOzUmugTeo5S8/7RgRuE5aLs58WsHjYDb3VIc5SGHwNqavyrzdYiauQ0ysl7czI/WiSh81yQivrDnIwYL4XktHShdZw0dTE6FBEXb6BJzjh4WYS6cz8b6y+z2n61DGI1YIB1AE/z8r8eHUeflMmcQzEXXclIZLus2JS8UlkrhK5TGuPJ3r5GKTnjVYBg93sD6bGF5q6Lx/8fo/bdXlkDpeOVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hfhVT7FQpbc86Ob1Ku1QmxqQqk7KeVMCCIN4okjmBAw=; b=gCq2w/RjtUFk4BcBsuLDdQRCV7EW6F3slFLk/amd/9NbRNh612TlyC03WcQyPedvfxMpWAY50DKI/dEXHcSK+YWPgWfGjKAlUNdT2oxBp6gu9S7nNA6sRgbH86kS/kAE1NyDQoJxHu4daXA3076dK2oCevG6SQqs7mRYdJGS9Ck= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by PAXPR04MB8736.eurprd04.prod.outlook.com (2603:10a6:102:20c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.9; Mon, 21 Nov 2022 06:35:14 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::5c78:27ea:319f:d11]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::5c78:27ea:319f:d11%3]) with mapi id 15.20.5834.015; Mon, 21 Nov 2022 06:35:14 +0000 From: Ming Qian To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl Cc: shawnguo@kernel.org, robh+dt@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, xiahong.bao@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] media: amphion: lock and check m2m_ctx in event handler Date: Mon, 21 Nov 2022 14:34:42 +0800 Message-Id: <20221121063442.8565-1-ming.qian@nxp.com> X-Mailer: git-send-email 2.38.1 X-ClientProxiedBy: SI1PR02CA0006.apcprd02.prod.outlook.com (2603:1096:4:1f7::11) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB6341:EE_|PAXPR04MB8736:EE_ X-MS-Office365-Filtering-Correlation-Id: f69f5862-12b2-4e9b-9241-08dacb8a8beb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Tn4vCO+TtRiltsEpF6uk858491uvDSCdbQIK/Xff5bLLyQNxacxzQDTD/r4/RB9/pprvRNNI6d96sQeBbMEwgllHGYuJ0vBDpNnyqLFuf1iNthby0/uA418C3n6wnjpidCOdVT7fqlLNdEL0wQkfDxcDr66rKcsbY4zgyYV44BLJ74Yl7WqYkGIZb0V+vk4Lpavm7xKxeM8wL8kriF7GIKmtPYVvRbMVx9jusc07nGw/nPVHIegsTQAZbnoFhaatvlYxydagZ4aBMSbOPw/3BG+ABtdaCNoJK/GRmRZjCbrGTpKxBOibzykGmAL0lvAAYDmj3ZWTz0ztW247qCb0TkHN69ZoPGmgNCR52xp5qBz9yfxtwC2BLkUIsl+JWpkygq67V778IOs33rMOGqHN7w3Ee7NPCtilInVbPZZuqdF2j2ozszMVncxV2ves2pRdUUQgaZogZW/9ERkk999pRq2hCDcnLeP/MEaI2Ouj+6tJ343liCL6ZbR9eJqhPOh5JL+DOrSBFru5VaeKSRZMyVp3lSftJsWzWvfP4wlztj7UOtX+L3Vde2vLKSsLmothrvbJ6JmmxlCP/lTB9a3FbwjcBvIyjlKmxKGdYytTxrvUElM9sjPeibGIevxHObX7Ej3NCJDFl2qCZLpLofBnuWpOSztej7ih+TDOE3aJzWJ5M/iNitMcsIXIo0nD6qHNZV1z6axmlo3na9MSoAlimg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB6341.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(366004)(376002)(396003)(136003)(451199015)(5660300002)(44832011)(7416002)(6506007)(316002)(52116002)(66476007)(8676002)(4326008)(66946007)(36756003)(6512007)(41300700001)(2616005)(26005)(1076003)(8936002)(186003)(38350700002)(38100700002)(2906002)(83380400001)(86362001)(66556008)(6666004)(6486002)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 36lopGQuYesLb3s0tmDaKujGcIaFLu2xlHLRsdCEUVKvBDgyX/7BszAzSCkCc5v6UasYPL5/XbUCFAGEkjYRE1u+0MIte0yYV96LVEwoM9nbrbjN7bu6DWomtwEEKqK0umtRcabM9lFUUQoWzDCjryz413twOaKGhnGvk2ATWa3G5CJZmDI5TJSDkgmW47RE46Gwe93y9/yCVLYmsEaQd5A3Cfa1QJvsK+3J4nmntiaxTfP9RThUL4BSnwmf+rMrj9t0sWKTunwdMt5OEHnQhbUFpV/d1rOCdQZTvP/u5SFbWYcM3f7HjC//+VpaWz/NhBwJqhDLN8EATTpIbO4UPauhYUfruDSHgEJ4WaeWkqg7gXGU/t287KO1hLWQkfje/cTef1p7SzxKSHYrvERrNRoDn5+8BPqr1U4OMRgzTV9P0+hoTaBlDnDi19Xg6xJnx1KmT8EikiMDsttxesShFbwyssqKIRFPoIE07RJoJ1ANlDrWZgMPWiluUannI6/A7Oj6W4e/ZuuoACnKHq4sVhqG/sKFXTBZYPZMvVDlcCBdXE9sPBZVt1B4euIHkIc/K5vPeu23N1KKtlRKMWLTbjCDK7Y0OkOgUjgRy+sbU2Si1vVpVEkDDCoOenx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04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 06:35:14.1149 (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: V5dAdMUfXN34nGS9eYXnEHRLrpmlgZSWcRmWkS5kz9o0xOtrj9FmGIkE5hmNtFmVXBWOFq07GbTh4kGmpbbZIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8736 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221120_223518_388252_CC0C0766 X-CRM114-Status: GOOD ( 12.40 ) 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 driver needs to cancel vpu before releasing the vpu instance, so call v4l2_m2m_ctx_release() first, to handle the redundant event triggered after m2m_ctx is released. lock and check m2m_ctx in the event handler. Fixes: 3cd084519c6f ("media: amphion: add vpu v4l2 m2m support") Signed-off-by: Ming Qian --- drivers/media/platform/amphion/vpu_msgs.c | 2 ++ drivers/media/platform/amphion/vpu_v4l2.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/amphion/vpu_msgs.c b/drivers/media/platform/amphion/vpu_msgs.c index d8247f36d84b..92672a802b49 100644 --- a/drivers/media/platform/amphion/vpu_msgs.c +++ b/drivers/media/platform/amphion/vpu_msgs.c @@ -43,6 +43,7 @@ static void vpu_session_handle_mem_request(struct vpu_inst *inst, struct vpu_rpc req_data.ref_frame_num, req_data.act_buf_size, req_data.act_buf_num); + vpu_inst_lock(inst); call_void_vop(inst, mem_request, req_data.enc_frame_size, req_data.enc_frame_num, @@ -50,6 +51,7 @@ static void vpu_session_handle_mem_request(struct vpu_inst *inst, struct vpu_rpc req_data.ref_frame_num, req_data.act_buf_size, req_data.act_buf_num); + vpu_inst_unlock(inst); } static void vpu_session_handle_stop_done(struct vpu_inst *inst, struct vpu_rpc_event *pkt) diff --git a/drivers/media/platform/amphion/vpu_v4l2.c b/drivers/media/platform/amphion/vpu_v4l2.c index 33aaa86d465f..6773b885597c 100644 --- a/drivers/media/platform/amphion/vpu_v4l2.c +++ b/drivers/media/platform/amphion/vpu_v4l2.c @@ -327,8 +327,12 @@ int vpu_process_capture_buffer(struct vpu_inst *inst) struct vb2_v4l2_buffer *vpu_next_src_buf(struct vpu_inst *inst) { - struct vb2_v4l2_buffer *src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx); + struct vb2_v4l2_buffer *src_buf = NULL; + if (!inst->fh.m2m_ctx) + return NULL; + + src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx); if (!src_buf || vpu_get_buffer_state(src_buf) == VPU_BUF_STATE_IDLE) return NULL; @@ -351,7 +355,7 @@ void vpu_skip_frame(struct vpu_inst *inst, int count) enum vb2_buffer_state state; int i = 0; - if (count <= 0) + if (count <= 0 || !inst->fh.m2m_ctx) return; while (i < count) {