Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp503761lqc; Fri, 8 Mar 2024 04:14:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVfTzvMEt1J5Ehg11T9eQDTmpqU1n4YAKVwuAOIXcghLe0KtQt0pjWleGj+8Dug6QLMdOYOIQakDBYUJ4Nd6N8rlQHxP/JwG4B69mJQ5w== X-Google-Smtp-Source: AGHT+IGXl2Fa0agXTt9d8h+s2yNtCUbKcGDWAldFBAzROZsz6wYacJ6eleEfDOOKLnUyVZJ4pFNa X-Received: by 2002:a05:6a21:6da9:b0:1a0:e944:15b7 with SMTP id wl41-20020a056a216da900b001a0e94415b7mr11577202pzb.5.1709900041497; Fri, 08 Mar 2024 04:14:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709900041; cv=pass; d=google.com; s=arc-20160816; b=vvoFUGG71l5ZiN4xN984hV5BTTDCWVY9Ccz8N4RDLwha+uM/dbu0a4IfqLMz/ry2pf UozyMXen0TqXNPRngER3xUQ2c4SsNHWl4Z6A3bgw//askYVu4a2w5QB/2/P2Zdaw9kTJ s6tarwtyOV7+S9dHCEPJZB2eGnxT1gg69zsyFnI3+xnJLOHzYJZHKJzQYrCaVR/m9ETi F6svHEFeVSQRi2F6V8zfQhNdaGmMYMio2I/s/AJghryK0XYKGs8WfTLOdiwBUvbF8atI fwgPGcK4Lyzs1QFkdoZyz6IZQP3Vcc0rQ1iM0pZnvMY/Dzjp6M0gPYEl5TLzQJPaZlMd f7lw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:to:from:dkim-signature; bh=fHu3cl6dyYT2DX3fZ/mA0MeLZ4iLVn+iFMGJOWHCrvs=; fh=n9XuIJ1jODKO6LUbsL547f37oo9N78tR6l/1Jp99WB8=; b=h7IAQAFgWz8nFuLr0CQVg+yXIx6m9r2qe3wvXDIWcHUJu/dmLWoEmUh3mzz8mJYznl 8l/RlNmC7i+v0ejIiR8hjOr8ltnnmIJennu9IMIMszvQxAyTF+voblAgTUH/24iPWW3m ev5KdxcWGm5QpO1Uz4HF9cF9j5LLECUqwdiptqH1tW5jgoiUzxfP80vE7Qc40KTZQVEm CuPO7nCctt3OkwltDkK81IxuQO8GtInXqLljiwjBcffsteaVW+O6P/w2cXstTG0dF0WO F9Nzmr+xr37H4bE2y1qxAxirq9KaIb77GoBZZ3Z7+tHRkAqQ9wzPZiD51WrsFMAt/Wfa PcSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=G8aAkqSr; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-96987-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96987-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t66-20020a628145000000b006e5787df82csi15735184pfd.29.2024.03.08.04.14.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 04:14:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96987-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=G8aAkqSr; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-96987-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96987-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2B0DA283A5E for ; Fri, 8 Mar 2024 12:14:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE32D5676E; Fri, 8 Mar 2024 12:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G8aAkqSr" Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB04455E57; Fri, 8 Mar 2024 12:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709900024; cv=none; b=S4fGH//ksB4f39e/aFAT+jOB5wZfV3ztfwsIek15tlY5PVm/ni7xHgKfr5OMQfSrCBZzNSmS3XomqLTv6B3tRkjWNx8tBn9eazWmyI2WfkYTxdvIsYg2Z+t1RhBeWk9hCbhMXxaU5NqSiGu9KZVtM6xZBCEdZHkNcKx1TQMZiFY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709900024; c=relaxed/simple; bh=xRQYQNukZYRtKTnk/JrS0VuezsXQVEgHR6HcqlV1dQg=; h=From:To:Subject:Date:Message-Id; b=MtBccxGz81/witF9oaU87U5CUYiPo94qBWB4RMTevCq7TJijexu2BU46RADu7ExacS0Qlt7+BVbWTne9cs2CgPsRD2/+SBtWT/LgjBMfvheBHPB/6lK0/l0V3cwgyYbEbOsknhlUIR0jACpVz5t8QEaPvEiau6p+DxQARr54Nl0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G8aAkqSr; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6e6277f72d8so1548886b3a.1; Fri, 08 Mar 2024 04:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709900022; x=1710504822; darn=vger.kernel.org; h=message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=fHu3cl6dyYT2DX3fZ/mA0MeLZ4iLVn+iFMGJOWHCrvs=; b=G8aAkqSrx62rmRhUWck7zfzv1bFZptoKsDyAEs8VH51620k/mQ0U0gKCR7/Tnz+Wch 6so0tUyY9LkG/QZgH2qBlt9LaLe9dT6YN64wfGDCZUaAWwYrb9QJfzGojwB7bWpqn9KP jwzvOuxQnYdSCa2Cy1IWLCS4fHL3uV+ht3aEY7QQ5fSOr8JfuNAaxppcVxWMsnWaDHqD XKTnpT9wV1Ahy+nyKScnGwrIqCktN2wgmojVypu59gU25+j05k+IRKFSDVL7rYsw99bo 5bFJnOuG41IbXH+RLRSHkOvu9oqFtFcrOOFEwPyC8jCL47xFrN8go14DZlGkLMyuQ0cc q4IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709900022; x=1710504822; h=message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fHu3cl6dyYT2DX3fZ/mA0MeLZ4iLVn+iFMGJOWHCrvs=; b=RB+selI4JEEero2jMxNKJ36hA9EpPiA41JhSc7/bhgD7E1tlb8Lwx2pM2YWDJQuzt4 n9h8JD0AF5xw0nMgk/cIjLj1QBMjieqU7yY04anD1fxhCsJkISq+hFYrItOvD1Gpp9Z4 uoS/LfqzrOxxHMJuPgFqQ4t2TZ4asVD3f4FRN/FJWmG6pseddDB6GgS7Q3ezRmajiNpi aRDE9G6vzp4VTRTw3pUGvju31QzgVrLRjI/YcKidBdoed9bIFgBPO2SV+Jy3ul+krRNx 4eB+LK++dUpTfpiYtJYurJhP3PFhdMddnZ7SrNGhBHmMtvyWyBlXpnVXKVWnF//MA3a5 R53w== X-Forwarded-Encrypted: i=1; AJvYcCWlNVJb45pRXNivVowsXC3lms94OEADJXB4K2wEC2KXtZi+0Y0x8WyZJ678zDrHvfI8EbebZzzYt8m9d5tP7cv/6xjMDyclG0W9XcyK/R+937IIxuZN1jGiB9ejjPoVz0mgnlOCtc1HZmg= X-Gm-Message-State: AOJu0YwfUrZ+PDG1eQZ0ScuB/KotRN1ayIqpYxNGDFUg8w5znddPbNAK xBbFsmfnbxy9igkSDaQ/iMiRL8g2hiP3Gj43yXbga9wr7cs132x07WU4zlZVcmo= X-Received: by 2002:a05:6a20:da87:b0:1a1:484d:ef09 with SMTP id iy7-20020a056a20da8700b001a1484def09mr11655179pzb.4.1709900022014; Fri, 08 Mar 2024 04:13:42 -0800 (PST) Received: from goorm.ap-northeast-2.compute.internal (ec2-52-78-100-77.ap-northeast-2.compute.amazonaws.com. [52.78.100.77]) by smtp.gmail.com with ESMTPSA id o16-20020a056a001b5000b006e555d40951sm13980843pfv.188.2024.03.08.04.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 04:13:41 -0800 (PST) From: yongsuyoo0215@gmail.com To: mchehab@kernel.org, yongsuyoo0215@gmail.com, v4bel@theori.io, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: dvb_ca_en50221: Add a returing EBUSY logic into CA_RESET Date: Fri, 8 Mar 2024 12:13:38 +0000 Message-Id: <20240308121338.1983-1-yongsuyoo0215@gmail.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Yongsu yoo Signed-off-by:Yongsu Yoo In source/drivers/media/dvb-core/dvb_ca_en50221.c, if the CA_RESET ioctl is called, in a normal case, the state of the thread of the dvb_ca_en50221_thread_state_machine will transit like below order. DVB_CA_SLOTSTATE_NONE -> DVB_CA_SLOTSTATE_UNINITIALISED -> DVB_CA_SLOTSTATE_WAITREADY -> DVB_CA_SLOTSTATE_VALIDATE -> DVB_CA_SLOTSTATE_WAITFR -> DVB_CA_SLOTSTATE_LINKINIT -> DVB_CA_SLOTSTATE_RUNNING But in some problem cases, the state will become DVB_CA_SLOTSTATE_INVALID. Among the above mentioned states, the DVB_CA_SLOTSTATE_NONE and the DVB_CA_SLOTSTATE_INVALID are "already stablized" states, whereas other states are "transiting" states. The "already stablized" states mean no matter how long time we wait, the state will not be changed. The "transiting" states mean the states whose final state is not yet determined. The state keeps to be changed. Only after some time passes, we get to know whether the final state will be DVB_CA_SLOTSTATE_RUNNING or DVB_CA_SLOTSTATE_INVALID. During the "transiting" states, we do not yet know whether the CA_RESET operation, which triggered the "transiting" states, will succeed or fail. For this reason, during the "transiting" states, if another CA_RESET ioctl is called and if this new CA_RESET ioctl operation begins again, it will be meaningless and waste time. For preventing this problem from happening, we make CA_RESET ioctl do nothing and only return EBUSY if the ioctl is called during the "transiting" states. --- drivers/media/dvb-core/dvb_ca_en50221.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c index baf64540dc00..2e8aec354b7c 100644 --- a/drivers/media/dvb-core/dvb_ca_en50221.c +++ b/drivers/media/dvb-core/dvb_ca_en50221.c @@ -1362,13 +1362,19 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file, struct dvb_ca_slot *sl = &ca->slot_info[slot]; mutex_lock(&sl->slot_lock); - if (sl->slot_state != DVB_CA_SLOTSTATE_NONE) { + if ((sl->slot_state == DVB_CA_SLOTSTATE_RUNNING) || + (sl->slot_state == DVB_CA_SLOTSTATE_INVALID)) { dvb_ca_en50221_slot_shutdown(ca, slot); if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE) dvb_ca_en50221_camchange_irq(ca->pub, slot, DVB_CA_EN50221_CAMCHANGE_INSERTED); } + else { + if (sl->slot_state != DVB_CA_SLOTSTATE_NONE) { + err = -EBUSY; + } + } mutex_unlock(&sl->slot_lock); } ca->next_read_slot = 0; -- 2.17.1