From nobody Tue Feb 10 17:17:01 2026 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 6EBA31581F7 for ; Mon, 5 Aug 2024 08:54:35 +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=1722848077; cv=none; b=jDIcHRrQNZ+vNsg/BkD8TlKg97RpETGqJG0cIK5EeuHzxywflM3ahClWEioc9/QW0pHH3A6wVC6eQpnScsRvsT6UFZgYwvzVzLkM3Be4F7MA1skziJ0MNvyCHMwR4+ER398gxWpLUuFbmf5A1F2dOGfEctxyJrYVLb9Ml1QyOn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848077; c=relaxed/simple; bh=svBF9jtACmNy7W1IHbAFhFQHdueMPV/of/FXrm7txro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fjlsILxQ9pkBvFVXqpdopFyKb6mRCqhozvPLCPJXZF6TEpIB+d16SvAWWrT/stdDayZt7Cdd4VpCgJxY++GgbZwHXAmJN1muX17rMbSsdX34cQnVoaJCF75/aBqOC7AZqmHHEeYY8zYPmV0cIlNFmfJZJClqNCZV19C4uXNIgUY= 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=RgVEt70r; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uAXVTM86; 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="RgVEt70r"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uAXVTM86" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id C01D5138FDBC; Mon, 5 Aug 2024 04:54:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 05 Aug 2024 04:54:34 -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=fm3; t=1722848074; x= 1722934474; bh=kdsG2PJz0GJocG9ZLnehQX7pZUw+tAe5s31sau+KXtk=; b=R gVEt70rTfS1JwNrhu5vYJEx+jHTnuzPXV8NZNG0z8dC1D0se7MN/u+SJ5PNbx1UD e1pTdSLchBbetska/vHtAu5K3VPwOqOAhRrSimrtyRXlm8co0/GG81EgMzAhsqyx LdGjFfnjpfwgEUhn/d6I+FOI7y9A+AJggL05NeNZRrVNFTOSPEiio/4+0wy1+Jk4 kKZLGfs+r0zwAYV6krnKa6Q+BnHw1bgHkMI+kA6klaf5pxehoHe76JwQZdu7ogSd ZZeH7YTJN4HM1Y4lJkaucdSiXdUmGzYT73kKq+WAS7TmNybwD0DC+HaRAn8vf+/k UhgFc/qF5PPhlz3kfpWaA== 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=fm3; t=1722848074; x= 1722934474; bh=kdsG2PJz0GJocG9ZLnehQX7pZUw+tAe5s31sau+KXtk=; b=u AXVTM86HIotktWfkHbSJ3ErlRO6Mt2xXP/rYheQdXSnZDWQ/VTMWnhzd+lgZaC8o fqI7xBFlSFKM303D/m5Ws5S61AIuxLNwdt6UrrQasVga2pBUDnE+DL6YuNh62YFs 6zeReIOHKn2k9P7XTtx5zv42dLGAaVVGaEUD3S8wnvi3bRT17owIC/EsspNdpiXK rdEKRM4mALE3f7VDdewc8mQyfML3llUMgCvHJ+eAMdowOWUdftrC6DbCPxA23j/b aSiviUS6jbtfV4FsLzslm5f0kia2IbXuz+uy/fHZx+aXGz9I9ls/ryOZ0ShklvtK EBzOsDhFmyAxDQaiy7wOQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:33 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 17/17] firewire: ohci: use guard macro to serialize operations for isochronous contexts Date: Mon, 5 Aug 2024 17:54:08 +0900 Message-ID: <20240805085408.251763-18-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-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" The 1394 OHCI driver uses spinlock to serialize operations for isochronous contexts. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 182 +++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 105 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 368420e4b414..e1d24e0ec991 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -1173,13 +1173,11 @@ static void context_tasklet(unsigned long data) break; =20 if (old_desc !=3D desc) { - /* If we've advanced to the next buffer, move the - * previous buffer to the free list. */ - unsigned long flags; + // If we've advanced to the next buffer, move the previous buffer to the + // free list. old_desc->used =3D 0; - spin_lock_irqsave(&ctx->ohci->lock, flags); + guard(spinlock_irqsave)(&ctx->ohci->lock); list_move_tail(&old_desc->list, &ctx->buffer_list); - spin_unlock_irqrestore(&ctx->ohci->lock, flags); } ctx->last =3D last; } @@ -2122,14 +2120,12 @@ static void bus_reset_work(struct work_struct *work) return; } =20 - /* FIXME: Document how the locking works. */ - spin_lock_irq(&ohci->lock); - - ohci->generation =3D -1; /* prevent AT packet queueing */ - context_stop(&ohci->at_request_ctx); - context_stop(&ohci->at_response_ctx); - - spin_unlock_irq(&ohci->lock); + // FIXME: Document how the locking works. + scoped_guard(spinlock_irq, &ohci->lock) { + ohci->generation =3D -1; // prevent AT packet queueing + context_stop(&ohci->at_request_ctx); + context_stop(&ohci->at_response_ctx); + } =20 /* * Per OHCI 1.2 draft, clause 7.2.3.3, hardware may leave unsent @@ -2704,7 +2700,6 @@ static int ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation) { struct fw_ohci *ohci =3D fw_ohci(card); - unsigned long flags; int n, ret =3D 0; =20 if (param_remote_dma) @@ -2715,12 +2710,10 @@ static int ohci_enable_phys_dma(struct fw_card *car= d, * interrupt bit. Clear physReqResourceAllBuses on bus reset. */ =20 - spin_lock_irqsave(&ohci->lock, flags); + guard(spinlock_irqsave)(&ohci->lock); =20 - if (ohci->generation !=3D generation) { - ret =3D -ESTALE; - goto out; - } + if (ohci->generation !=3D generation) + return -ESTALE; =20 /* * Note, if the node ID contains a non-local bus ID, physical DMA is @@ -2734,8 +2727,6 @@ static int ohci_enable_phys_dma(struct fw_card *card, reg_write(ohci, OHCI1394_PhyReqFilterHiSet, 1 << (n - 32)); =20 flush_writes(ohci); - out: - spin_unlock_irqrestore(&ohci->lock, flags); =20 return ret; } @@ -3076,55 +3067,53 @@ static struct fw_iso_context *ohci_allocate_iso_con= text(struct fw_card *card, u32 *mask, regs; int index, ret =3D -EBUSY; =20 - spin_lock_irq(&ohci->lock); + scoped_guard(spinlock_irq, &ohci->lock) { + switch (type) { + case FW_ISO_CONTEXT_TRANSMIT: + mask =3D &ohci->it_context_mask; + callback =3D handle_it_packet; + index =3D ffs(*mask) - 1; + if (index >=3D 0) { + *mask &=3D ~(1 << index); + regs =3D OHCI1394_IsoXmitContextBase(index); + ctx =3D &ohci->it_context_list[index]; + } + break; =20 - switch (type) { - case FW_ISO_CONTEXT_TRANSMIT: - mask =3D &ohci->it_context_mask; - callback =3D handle_it_packet; - index =3D ffs(*mask) - 1; - if (index >=3D 0) { - *mask &=3D ~(1 << index); - regs =3D OHCI1394_IsoXmitContextBase(index); - ctx =3D &ohci->it_context_list[index]; - } - break; + case FW_ISO_CONTEXT_RECEIVE: + channels =3D &ohci->ir_context_channels; + mask =3D &ohci->ir_context_mask; + callback =3D handle_ir_packet_per_buffer; + index =3D *channels & 1ULL << channel ? ffs(*mask) - 1 : -1; + if (index >=3D 0) { + *channels &=3D ~(1ULL << channel); + *mask &=3D ~(1 << index); + regs =3D OHCI1394_IsoRcvContextBase(index); + ctx =3D &ohci->ir_context_list[index]; + } + break; =20 - case FW_ISO_CONTEXT_RECEIVE: - channels =3D &ohci->ir_context_channels; - mask =3D &ohci->ir_context_mask; - callback =3D handle_ir_packet_per_buffer; - index =3D *channels & 1ULL << channel ? ffs(*mask) - 1 : -1; - if (index >=3D 0) { - *channels &=3D ~(1ULL << channel); - *mask &=3D ~(1 << index); - regs =3D OHCI1394_IsoRcvContextBase(index); - ctx =3D &ohci->ir_context_list[index]; - } - break; + case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: + mask =3D &ohci->ir_context_mask; + callback =3D handle_ir_buffer_fill; + index =3D !ohci->mc_allocated ? ffs(*mask) - 1 : -1; + if (index >=3D 0) { + ohci->mc_allocated =3D true; + *mask &=3D ~(1 << index); + regs =3D OHCI1394_IsoRcvContextBase(index); + ctx =3D &ohci->ir_context_list[index]; + } + break; =20 - case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: - mask =3D &ohci->ir_context_mask; - callback =3D handle_ir_buffer_fill; - index =3D !ohci->mc_allocated ? ffs(*mask) - 1 : -1; - if (index >=3D 0) { - ohci->mc_allocated =3D true; - *mask &=3D ~(1 << index); - regs =3D OHCI1394_IsoRcvContextBase(index); - ctx =3D &ohci->ir_context_list[index]; + default: + index =3D -1; + ret =3D -ENOSYS; } - break; =20 - default: - index =3D -1; - ret =3D -ENOSYS; + if (index < 0) + return ERR_PTR(ret); } =20 - spin_unlock_irq(&ohci->lock); - - if (index < 0) - return ERR_PTR(ret); - memset(ctx, 0, sizeof(*ctx)); ctx->header_length =3D 0; ctx->header =3D (void *) __get_free_page(GFP_KERNEL); @@ -3146,20 +3135,18 @@ static struct fw_iso_context *ohci_allocate_iso_con= text(struct fw_card *card, out_with_header: free_page((unsigned long)ctx->header); out: - spin_lock_irq(&ohci->lock); - - switch (type) { - case FW_ISO_CONTEXT_RECEIVE: - *channels |=3D 1ULL << channel; - break; + scoped_guard(spinlock_irq, &ohci->lock) { + switch (type) { + case FW_ISO_CONTEXT_RECEIVE: + *channels |=3D 1ULL << channel; + break; =20 - case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: - ohci->mc_allocated =3D false; - break; + case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: + ohci->mc_allocated =3D false; + break; + } + *mask |=3D 1 << index; } - *mask |=3D 1 << index; - - spin_unlock_irq(&ohci->lock); =20 return ERR_PTR(ret); } @@ -3243,14 +3230,13 @@ static void ohci_free_iso_context(struct fw_iso_con= text *base) { struct fw_ohci *ohci =3D fw_ohci(base->card); struct iso_context *ctx =3D container_of(base, struct iso_context, base); - unsigned long flags; int index; =20 ohci_stop_iso(base); context_release(&ctx->context); free_page((unsigned long)ctx->header); =20 - spin_lock_irqsave(&ohci->lock, flags); + guard(spinlock_irqsave)(&ohci->lock); =20 switch (base->type) { case FW_ISO_CONTEXT_TRANSMIT: @@ -3272,38 +3258,29 @@ static void ohci_free_iso_context(struct fw_iso_con= text *base) ohci->mc_allocated =3D false; break; } - - spin_unlock_irqrestore(&ohci->lock, flags); } =20 static int ohci_set_iso_channels(struct fw_iso_context *base, u64 *channel= s) { struct fw_ohci *ohci =3D fw_ohci(base->card); - unsigned long flags; - int ret; =20 switch (base->type) { case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: + { + guard(spinlock_irqsave)(&ohci->lock); =20 - spin_lock_irqsave(&ohci->lock, flags); - - /* Don't allow multichannel to grab other contexts' channels. */ + // Don't allow multichannel to grab other contexts' channels. if (~ohci->ir_context_channels & ~ohci->mc_channels & *channels) { *channels =3D ohci->ir_context_channels; - ret =3D -EBUSY; + return -EBUSY; } else { set_multichannel_mask(ohci, *channels); - ret =3D 0; + return 0; } - - spin_unlock_irqrestore(&ohci->lock, flags); - - break; + } default: - ret =3D -EINVAL; + return -EINVAL; } - - return ret; } =20 #ifdef CONFIG_PM @@ -3573,24 +3550,19 @@ static int ohci_queue_iso(struct fw_iso_context *ba= se, unsigned long payload) { struct iso_context *ctx =3D container_of(base, struct iso_context, base); - unsigned long flags; - int ret =3D -ENOSYS; =20 - spin_lock_irqsave(&ctx->context.ohci->lock, flags); + guard(spinlock_irqsave)(&ctx->context.ohci->lock); + switch (base->type) { case FW_ISO_CONTEXT_TRANSMIT: - ret =3D queue_iso_transmit(ctx, packet, buffer, payload); - break; + return queue_iso_transmit(ctx, packet, buffer, payload); case FW_ISO_CONTEXT_RECEIVE: - ret =3D queue_iso_packet_per_buffer(ctx, packet, buffer, payload); - break; + return queue_iso_packet_per_buffer(ctx, packet, buffer, payload); case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: - ret =3D queue_iso_buffer_fill(ctx, packet, buffer, payload); - break; + return queue_iso_buffer_fill(ctx, packet, buffer, payload); + default: + return -ENOSYS; } - spin_unlock_irqrestore(&ctx->context.ohci->lock, flags); - - return ret; } =20 static void ohci_flush_queue_iso(struct fw_iso_context *base) --=20 2.43.0