From nobody Sat Nov 30 12:39:32 2024 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 560D2178CDE; Mon, 9 Sep 2024 14:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725890427; cv=none; b=P9fh1z3JrM5HdGx0T+OVHSz0qWv51lNTHAhBtpQF9GXNOsfkQnlgQ2WHtEE3sT+Plwc3POsb/as+2SjNeo4RkWHTOortAiFCVAL0iRKIjsbeqDMbXDxBPCFh8Uw744d/6jZUpcpJ2pnjPAGuUlLPP9jMTZaTszHanKRHo66Zd6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725890427; c=relaxed/simple; bh=wNI809TCw8dOjPZ7jI3GSjAYhudmFFPxfp4oZzcGufM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e06fRmb7XHzxU8wGLqi1rPSZkzQr7X+6NPCW5Hkz7quF5ZrgykR0Sc2oxa7/wrNy1Yf/GVjd+wJDXGk9x7qIeqjjYE0785EeD83j/lRNvpGjRJ0WfBhc2L9CGelamCq6aULZ2uQBZvtq2zMJtwbXW3n9qqhGoMfSkgEE67kSN1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=JUGCcD4i; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BEbMRQfk; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="JUGCcD4i"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BEbMRQfk" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 71CC9138022D; Mon, 9 Sep 2024 10:00:24 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Mon, 09 Sep 2024 10:00:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1725890424; x= 1725976824; bh=Zm1x8RMkMJ6iqGxXmzNuyEZHYUHIHWovazQAQQ9JJ5w=; b=J UGCcD4iuFLzBuyKAiBjoV7qxQN2cC4TiaYb0phmRo6+uaZXlwyDtW58IEQdj8YGT YO3aR47cLoAHl5BAqZINsfObIgM2eHQHql0JrrWDI0KbU9FdUbMHlz2Dm+Kk/x8S rdGiZeOy3OCFoQtpFvKGD0gcKVpFP+890wcJfPHIkSgPR8odJ+DGTD6U4raa+Fyg 81otInY4EFIIvZFXpIhR9UaETuWgpiagkXX1i4FSSCjADX4FYYjYUXuI9ePhfR+T rFAVojiuvvxuU8IFrZBjwNDyqaz44uO+E5T294CcVQj5gm1W8IQLbo5g/1QLsz4s QOtsFyJd/XQogNjT/fRqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725890424; x= 1725976824; bh=Zm1x8RMkMJ6iqGxXmzNuyEZHYUHIHWovazQAQQ9JJ5w=; b=B EbMRQfkPMujFllyKVl4lUO37zh5DV+Mo1kgG0beX4efymsilvTaVUbn9XnyoG0cb DfDCoRouaU12mQ5F4KR+iGnqW+/+inQRHZhNo8jg9k+krAW+fGjiNKPbaPk4TTbv e2A3LtAkrcY20URC1MhgrgmvRYk+inkUZUXtXFl3tO5HIQWB8UR2kDNhvV/53XhK 68dP26ZMq6T1WQlDkWqsI4d57DTu6D1PV4956//W6705+YpAHJkNbfIZmw83YLXr TjjzbU0KdfcPZd38w7KtM18CeamTcxbxHYWZXXAKPB4r0ze1IJQnYOPwmwtveC+R Tj9Vv7oXhF9eGvUbF+PVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeijedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghm ohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrg htthgvrhhnpedvjefgjeeuvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdff kedvtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopeef pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvg hlsehlihhsthhsrdhsohhurhgtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhu gidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinh hugidqshhouhhnugesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Sep 2024 10:00:23 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org Subject: [PATCH 1/2] firewire: core: move workqueue handler from 1394 OHCI driver to core function Date: Mon, 9 Sep 2024 23:00:17 +0900 Message-ID: <20240909140018.65289-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240909140018.65289-1-o-takashi@sakamocchi.jp> References: <20240909140018.65289-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In current implementation, the work item for isochronous context executes the same procedure of fw_iso_context_flush_completions() internally. There is a space to refactor the implementation. This commit calls fw_iso_context_flush_completions() in the work item. It obsoletes fw_iso_context_init_work(). It also obsoletes a pair of disable_work_sync() and enable_work() since the usage of test_and_set_bit_lock() mediates concurrent call already. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-iso.c | 26 +++++++++------------ drivers/firewire/core.h | 5 ----- drivers/firewire/ohci.c | 45 ++----------------------------------- 3 files changed, 12 insertions(+), 64 deletions(-) diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c index f2394f3ed194..9f41c78878ad 100644 --- a/drivers/firewire/core-iso.c +++ b/drivers/firewire/core-iso.c @@ -131,6 +131,13 @@ size_t fw_iso_buffer_lookup(struct fw_iso_buffer *buff= er, dma_addr_t completed) return 0; } =20 +static void flush_completions_work(struct work_struct *work) +{ + struct fw_iso_context *ctx =3D container_of(work, struct fw_iso_context, = work); + + fw_iso_context_flush_completions(ctx); +} + struct fw_iso_context *fw_iso_context_create(struct fw_card *card, int type, int channel, int speed, size_t header_size, fw_iso_callback_t callback, void *callback_data) @@ -149,6 +156,7 @@ struct fw_iso_context *fw_iso_context_create(struct fw_= card *card, ctx->header_size =3D header_size; ctx->callback.sc =3D callback; ctx->callback_data =3D callback_data; + INIT_WORK(&ctx->work, flush_completions_work); =20 trace_isoc_outbound_allocate(ctx, channel, speed); trace_isoc_inbound_single_allocate(ctx, channel, header_size); @@ -218,29 +226,15 @@ EXPORT_SYMBOL(fw_iso_context_queue_flush); * to process the context asynchronously, fw_iso_context_schedule_flush_co= mpletions() is available * instead. * - * Context: Process context. May sleep due to disable_work_sync(). + * Context: Process context. */ int fw_iso_context_flush_completions(struct fw_iso_context *ctx) { - int err; - trace_isoc_outbound_flush_completions(ctx); trace_isoc_inbound_single_flush_completions(ctx); trace_isoc_inbound_multiple_flush_completions(ctx); =20 - might_sleep(); - - // Avoid dead lock due to programming mistake. - if (WARN_ON_ONCE(current_work() =3D=3D &ctx->work)) - return 0; - - disable_work_sync(&ctx->work); - - err =3D ctx->card->driver->flush_iso_completions(ctx); - - enable_work(&ctx->work); - - return err; + return ctx->card->driver->flush_iso_completions(ctx); } EXPORT_SYMBOL(fw_iso_context_flush_completions); =20 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index 0ae2c84ecafe..96ae366889e0 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h @@ -159,11 +159,6 @@ int fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, = int page_count); int fw_iso_buffer_map_dma(struct fw_iso_buffer *buffer, struct fw_card *ca= rd, enum dma_data_direction direction); =20 -static inline void fw_iso_context_init_work(struct fw_iso_context *ctx, wo= rk_func_t func) -{ - INIT_WORK(&ctx->work, func); -} - =20 /* -topology */ =20 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 3a911cfb5ff3..02ff0363d3ad 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -1182,47 +1182,6 @@ static void context_tasklet(unsigned long data) } } =20 -static void ohci_isoc_context_work(struct work_struct *work) -{ - struct fw_iso_context *base =3D container_of(work, struct fw_iso_context,= work); - struct iso_context *isoc_ctx =3D container_of(base, struct iso_context, b= ase); - struct context *ctx =3D &isoc_ctx->context; - struct descriptor *d, *last; - u32 address; - int z; - struct descriptor_buffer *desc; - - desc =3D list_entry(ctx->buffer_list.next, struct descriptor_buffer, list= ); - last =3D ctx->last; - while (last->branch_address !=3D 0) { - struct descriptor_buffer *old_desc =3D desc; - - address =3D le32_to_cpu(last->branch_address); - z =3D address & 0xf; - address &=3D ~0xf; - ctx->current_bus =3D address; - - // If the branch address points to a buffer outside of the current buffe= r, advance - // to the next buffer. - if (address < desc->buffer_bus || address >=3D desc->buffer_bus + desc->= used) - desc =3D list_entry(desc->list.next, struct descriptor_buffer, list); - d =3D desc->buffer + (address - desc->buffer_bus) / sizeof(*d); - last =3D find_branch_descriptor(d, z); - - if (!ctx->callback(ctx, d, last)) - break; - - if (old_desc !=3D desc) { - // If we've advanced to the next buffer, move the previous buffer to the - // free list. - old_desc->used =3D 0; - guard(spinlock_irqsave)(&ctx->ohci->lock); - list_move_tail(&old_desc->list, &ctx->buffer_list); - } - ctx->last =3D last; - } -} - /* * Allocate a new buffer and add it to the list of free buffers for this * context. Must be called with ohci->lock held. @@ -3169,7 +3128,6 @@ static struct fw_iso_context *ohci_allocate_iso_conte= xt(struct fw_card *card, ret =3D context_init(&ctx->context, ohci, regs, callback); if (ret < 0) goto out_with_header; - fw_iso_context_init_work(&ctx->base, ohci_isoc_context_work); =20 if (type =3D=3D FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL) { set_multichannel_mask(ohci, 0); @@ -3624,7 +3582,8 @@ static int ohci_flush_iso_completions(struct fw_iso_c= ontext *base) int ret =3D 0; =20 if (!test_and_set_bit_lock(0, &ctx->flushing_completions)) { - ohci_isoc_context_work(&base->work); + // Note that tasklet softIRQ is not used to process isochronous context = anymore. + context_tasklet((unsigned long)&ctx->context); =20 switch (base->type) { case FW_ISO_CONTEXT_TRANSMIT: --=20 2.43.0 From nobody Sat Nov 30 12:39:32 2024 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 BFC451BAEC5; Mon, 9 Sep 2024 14:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725890429; cv=none; b=lfPU8TRFYIkzBQu2OOc606hK2xUqkPdAyriapbytI7XHn2smOcVG67S7tAQ4Z5vWLYi5H0UnIxR/s6O/KSA+JrMkko9DoyxABiYsEVikp34jeUNSkzJ947YhVdflBxeE4F47Egj1BfJU4eT7dWx7017HRMZTfIueWxA9+YAb9Gg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725890429; c=relaxed/simple; bh=u+yo3E6Jd8SLAjnMiSYlJpPHrBjM6aUECiwsaDFm41I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DRrk0mQ7p7A4RVLPt/W+vBgUkXFOhKlXz3bBqUJKzzq9PB6tnWYhwtvwY5lrycuLZwgm1HXdOCmAVCP4jVBAXeJMMrLeT6yZKV4ICnHUNQUyhyepzZ/sauy0aDYbfCdyPchvDx1afPoPN1Z4Y8qgPGlQZwlD+6xrLtd1esoGyKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=nVhArJCC; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bqidxGYf; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="nVhArJCC"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bqidxGYf" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id EBE99138020A; Mon, 9 Sep 2024 10:00:25 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Mon, 09 Sep 2024 10:00:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1725890425; x= 1725976825; bh=MohIuIYa3jbt6rYPobGsm21vBhfll8E6tRStmYqj0vU=; b=n VhArJCCLqq/UIdis516CFNcTZkwNIRvKpm67npRrTRQG09T2B79tdVE3w4z9hRnO Q6k6djPYGdgkCOwdmkEKJIlDr78DNGXlJDn42+vZDoo5Fq1Mef+e6+eXrMO81nCR kaE5ShMOryTXru7YztH5f92tYfhXFpERcKf33VL83lVqn6fCuAvXXsmvd+4hc01f CqDmTayWtCjUCYoiH6/c+bgdT0W/163LZAXK2M5V15ayYf1cohrGfT4HgGxe0mMz g3ImcpiL9FFQWv9kzhbo5axrFa/nA12rWBj27ZfTgetnw18mTeL5oKbUDUVqldY4 wPUBhcTgliiIwID6Qu4+Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725890425; x= 1725976825; bh=MohIuIYa3jbt6rYPobGsm21vBhfll8E6tRStmYqj0vU=; b=b qidxGYfIkIk+VilZr+inYmr89nVJyCqQQ/j43zQ29NW5xZhaW8hwcW1t5YuBx0WL joCPatEB7Cai92d0CTDEYxU7+wFPAIPO6Twjyd9ejGBRhIAHeO6Z9ugeiRHWadNX 1J9GX6fuudO1OwOJ1XqwBqIVzgwuNqwiGksd4HndzdPqEqDNgtnEVqUk/R0L7+EM 9ZN7WC5gYj7gv5X4subvubQR/YX6mD3oZf5eoe1mS8dHWAdo4tIGMGBydldtQaiu LW5J6m4FmLnP9bNh1W5EAB2bUb0rI4bfQ9UVXklwhORTnJcFz4GcaSUXqsK4HUTz V13XroHhKUFybkLbdnjSQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeijedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghm ohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrg htthgvrhhnpedvjefgjeeuvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdff kedvtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopeef pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvg hlsehlihhsthhsrdhsohhurhgtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhu gidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinh hugidqshhouhhnugesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Sep 2024 10:00:24 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org Subject: [PATCH 2/2] firewire: core: use mutex to coordinate concurrent calls to flush completions Date: Mon, 9 Sep 2024 23:00:18 +0900 Message-ID: <20240909140018.65289-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240909140018.65289-1-o-takashi@sakamocchi.jp> References: <20240909140018.65289-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In current implementation, test_and_set_bit_lock() is used to mediate concurrent calls of ohci_flush_iso_completions(). However, the ad-hoc usage of atomic operations is not preferable. This commit uses mutex_trylock() as the similar operations. The core function is responsible for the mediation, instead of 1394 OHCI driver. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-iso.c | 11 +++++++++-- drivers/firewire/ohci.c | 37 ++++++++++++++----------------------- include/linux/firewire.h | 1 + 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c index 9f41c78878ad..a5c5ef3c725d 100644 --- a/drivers/firewire/core-iso.c +++ b/drivers/firewire/core-iso.c @@ -157,6 +157,7 @@ struct fw_iso_context *fw_iso_context_create(struct fw_= card *card, ctx->callback.sc =3D callback; ctx->callback_data =3D callback_data; INIT_WORK(&ctx->work, flush_completions_work); + mutex_init(&ctx->flushing_completions_mutex); =20 trace_isoc_outbound_allocate(ctx, channel, speed); trace_isoc_inbound_single_allocate(ctx, channel, header_size); @@ -173,6 +174,8 @@ void fw_iso_context_destroy(struct fw_iso_context *ctx) trace_isoc_inbound_multiple_destroy(ctx); =20 ctx->card->driver->free_iso_context(ctx); + + mutex_destroy(&ctx->flushing_completions_mutex); } EXPORT_SYMBOL(fw_iso_context_destroy); =20 @@ -226,7 +229,7 @@ EXPORT_SYMBOL(fw_iso_context_queue_flush); * to process the context asynchronously, fw_iso_context_schedule_flush_co= mpletions() is available * instead. * - * Context: Process context. + * Context: Process context due to mutex_trylock(). */ int fw_iso_context_flush_completions(struct fw_iso_context *ctx) { @@ -234,7 +237,11 @@ int fw_iso_context_flush_completions(struct fw_iso_con= text *ctx) trace_isoc_inbound_single_flush_completions(ctx); trace_isoc_inbound_multiple_flush_completions(ctx); =20 - return ctx->card->driver->flush_iso_completions(ctx); + scoped_cond_guard(mutex_try, /* nothing to do */, &ctx->flushing_completi= ons_mutex) { + return ctx->card->driver->flush_iso_completions(ctx); + } + + return 0; } EXPORT_SYMBOL(fw_iso_context_flush_completions); =20 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 02ff0363d3ad..b182998a77f4 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -166,7 +166,6 @@ struct iso_context { struct context context; void *header; size_t header_length; - unsigned long flushing_completions; u32 mc_buffer_bus; u16 mc_completed; u16 last_timestamp; @@ -3579,31 +3578,23 @@ static void ohci_flush_queue_iso(struct fw_iso_cont= ext *base) static int ohci_flush_iso_completions(struct fw_iso_context *base) { struct iso_context *ctx =3D container_of(base, struct iso_context, base); - int ret =3D 0; =20 - if (!test_and_set_bit_lock(0, &ctx->flushing_completions)) { - // Note that tasklet softIRQ is not used to process isochronous context = anymore. - context_tasklet((unsigned long)&ctx->context); + // Note that tasklet softIRQ is not used to process isochronous context a= nymore. + context_tasklet((unsigned long)&ctx->context); =20 - switch (base->type) { - case FW_ISO_CONTEXT_TRANSMIT: - case FW_ISO_CONTEXT_RECEIVE: - if (ctx->header_length !=3D 0) - flush_iso_completions(ctx, FW_ISO_CONTEXT_COMPLETIONS_CAUSE_FLUSH); - break; - case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: - if (ctx->mc_completed !=3D 0) - flush_ir_buffer_fill(ctx); - break; - default: - ret =3D -ENOSYS; - } - - clear_bit_unlock(0, &ctx->flushing_completions); - smp_mb__after_atomic(); + switch (base->type) { + case FW_ISO_CONTEXT_TRANSMIT: + case FW_ISO_CONTEXT_RECEIVE: + if (ctx->header_length !=3D 0) + flush_iso_completions(ctx, FW_ISO_CONTEXT_COMPLETIONS_CAUSE_FLUSH); + return 0; + case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: + if (ctx->mc_completed !=3D 0) + flush_ir_buffer_fill(ctx); + return 0; + default: + return -ENOSYS; } - - return ret; } =20 static const struct fw_card_driver ohci_driver =3D { diff --git a/include/linux/firewire.h b/include/linux/firewire.h index f815d12deda0..19e8c5f9537c 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -512,6 +512,7 @@ union fw_iso_callback { struct fw_iso_context { struct fw_card *card; struct work_struct work; + struct mutex flushing_completions_mutex; int type; int channel; int speed; --=20 2.43.0