From nobody Mon Feb 9 10:14:40 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 D8482200C7 for ; Sun, 4 Aug 2024 13:02:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776553; cv=none; b=Yxi2gOXvHwDOidTvzpNtVzr/2f9U1ddCYLNwaebCBQlo5+GnTkcztQzf8qB4RhhZzbVzhmkIzoIrpH+QtNTPU3GdLb0/LBEDzr0J6ktSI/H/Xk8dfL9mNkPndF8tMor/Zn1lrhbgAX3lfFqxOm9aiE8+r3IWfO42rbBXGzPmf/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776553; c=relaxed/simple; bh=LTZgk4Q7yEHgsYa/3BCj3o9FpVWAGqL0/melW16hM1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kd3P2Pm+H50SLs8NjV68CEJ8zgHRRDj9zoFbpJVNWMz0LlDL5V+k/0MnUwYHVnKeowSMF6B1P1Ehec79Vr89StKXbbM2/mRKZBVSVyN6R3qaHpQd5nCoYKontgAM+FQgEUNtXtv05JD42vnYU/UFd+CGP7mbUK0Yv6KdhNW5roA= 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=nqKC+niX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gXOK+yaL; arc=none smtp.client-ip=103.168.172.159 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="nqKC+niX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gXOK+yaL" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E1B411147F19; Sun, 4 Aug 2024 09:02:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 04 Aug 2024 09:02:30 -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=1722776550; x= 1722862950; bh=96B7qG2RXUCqvEU76ArBM5B2OlW27Ke00tHiDtOnSak=; b=n qKC+niXkISymn3iskL0ys42fhe2+ytiQA8OUhgoRrZThgtAbMbd010xCuoWTX1b7 dIXPgNjE89Ub/8Az5IiYGyGxOgl08XmJJ3SqxBgY8qdmOion9prMvt1IWzRTy4qm LiIpKtB5mgScrEvWVVlBX0JO1GHLbnVd7ndzeNOIxeRN6C4Ch5CE3bo7jHGn8kMm V3q6Gapyc3HJ6FFmcQB5LXLkYw2an1ha367Tn8dHOiK8OD42g0Jc1dMMunfc/JT9 zSH8YgCxLhaHvf+WhNYiIE36mKEWmxE8PysB8Oa5+LvJPABOBSHbRX8ZwXn5QhPH /tDM07zWHBQRq4VHySmGA== 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=1722776550; x= 1722862950; bh=96B7qG2RXUCqvEU76ArBM5B2OlW27Ke00tHiDtOnSak=; b=g XOK+yaLdLPYnJaufcWddCBJBO9+3pTlky1W+Clwki/ENP9KMktbxcRE8WMTEvLsE Wl8bgeJKud1myjKj58qe9zEzQ9+cdGVFP0lQP03r/9Vk916TwdnV1GeC4fSSEuzt 68s8oGKjLL30vRA3aKQoZTHRuwHtsL2Y/UM5hBDQYZq3SuPTKuL1XqHEspwBnyf3 1ameW/1WmyETcvpcm8q2K9uYzY/GNWA4bMLHRrKNCwId0P+IG1be8Zc2ZiXEPtPs xSA8E3zFPJEk4s2UQxDjqMVs3pKcdXYJloBAiCF5OTJ4Vqk0wUcwsWE12muKlWsm dnvMLzJSUjLnr/wSGERdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:29 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 01/17] firewire: core: use guard macro to maintain static packet data for phy configuration Date: Sun, 4 Aug 2024 22:02:08 +0900 Message-ID: <20240804130225.243496-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function provide a kernel API to send phy configuration packet. Current implementation of the feature uses packet object allocated statically. The concurrent access to the object is protected by static mutex. This commit uses guard macro to maintain the mutex. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-transaction.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index a89c841a7dbe..2a2cbd6e2f9b 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -494,7 +494,7 @@ void fw_send_phy_config(struct fw_card *card, phy_packet_phy_config_set_gap_count(&data, gap_count); phy_packet_phy_config_set_gap_count_optimization(&data, true); =20 - mutex_lock(&phy_config_mutex); + guard(mutex)(&phy_config_mutex); =20 async_header_set_tcode(phy_config_packet.header, TCODE_LINK_INTERNAL); phy_config_packet.header[1] =3D data; @@ -508,8 +508,6 @@ void fw_send_phy_config(struct fw_card *card, =20 card->driver->send_request(card, &phy_config_packet); wait_for_completion_timeout(&phy_config_done, timeout); - - mutex_unlock(&phy_config_mutex); } =20 static struct fw_address_handler *lookup_overlapping_address_handler( --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 468EE210FB for ; Sun, 4 Aug 2024 13:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776555; cv=none; b=O4FCQRd5ww35gX5Orsk+SterYxcGgFaB7VmOAJSTRhAeVZLkwJ4AHyme/ZjIDzaSH8stRuxzc+BQRlz/OWtbOc/VGn0JE1qoE2mSXp/2K7sgxl0RAGnsCVZx2FUsyujHQtnz7P8HSlicqGZkVEheK+4ia7o6KW7/rEdAKfm5s5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776555; c=relaxed/simple; bh=w7k0vH2F9MOx4njtAUYL+RMBDZfz4ElgK8jF9a0p6F4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=en6nvkdGTnhsRW/6gnPv7babepZAhWjuj7xjfBixFsvvLK0l6nvb8hVwIVLBj8IY2KSkIZZ0ds3mftpruJ0AOLHwaI7/vgLuEqd2DlmHcilAHvxZSU3xNmfyksykLIKLqO7lq01Rx2XYYx2f6vHf/6CmSLZ1+cu2sA8iRVemOoY= 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=BorCRmev; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=oTceX0f7; arc=none smtp.client-ip=103.168.172.159 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="BorCRmev"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="oTceX0f7" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 5665B1147EEC; Sun, 4 Aug 2024 09:02:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 04 Aug 2024 09:02:32 -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=1722776552; x= 1722862952; bh=o9vF7u9NUcybsaqu9wuw/REBguJhypKXIzx9986qq3g=; b=B orCRmevl0USxohGWZC6o+oUYLxDUBHC+U/w0EW+ZZTc+PGA4KD6cXRyrCK3xHFCj PoeD34bVBynRNpME3TZNlfyMe1X24oF1wuh4pgBLU8mYVdbh4fXpS2v2ug7auJqB wQeXtnuiLvnvUu4/nERA6LT8IDtXaBvnIXpp5+Y1UA08Nccel5gXwGHDgAiVU21y X+5qLRJv5S5OLlnoCNecvJ1kzcg04tKOwBbSRVL7hV6zNeZZ1KBag7jmYnWzRInw Wmq5WjY4OALxav0IZzWeuSBdbbH6mJd9RHQFouTNx5BYrjaibyArWmu7MKwLtxiK k8p5RCOZgYDRh17TLiOqw== 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=1722776552; x= 1722862952; bh=o9vF7u9NUcybsaqu9wuw/REBguJhypKXIzx9986qq3g=; b=o TceX0f7cxa1lc9Q7eNYtm/mUGHTDnyDBylI75xUvvXwm3/Wz6EowHxFBWQTC4ZB3 0AWp93GavKUzNvLcv9DjJgYlUnnIYxku1L3jruziLeoJXPCjul564CU8mbJwaNHF ypPfRnNSlHnMZAbFBLQcGs7x1LQRbX94YQDeOwXnR2I4m4iV0Btbe/u3Zldwc0u4 xyQPAOHYrW3HsXKaOLuZdn36KM8iH+/7YaiJiB6jcL4cpoA6X+2OcY7/VBOz/V/g eZpGnfMMW6svGyO3LhnSmxM+Ddj7q8h4nAM27Pd0U/K5COPxkm0mQLtgfz+RYVBo UQmL+ZW2L2UvtNXcVSapQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:31 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 02/17] firewire: core: use guard macro to maintain the list of card Date: Sun, 4 Aug 2024 22:02:09 +0900 Message-ID: <20240804130225.243496-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function maintains registered cards by list. The concurrent access to the list is protected by static mutex. This commit uses guard macro to maintain the mutex. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-card.c | 44 +++++++++++++++--------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index f8b99dd6cd82..79a5b19e9d18 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -168,7 +168,6 @@ static size_t required_space(struct fw_descriptor *desc) int fw_core_add_descriptor(struct fw_descriptor *desc) { size_t i; - int ret; =20 /* * Check descriptor is valid; the length of all blocks in the @@ -182,29 +181,25 @@ int fw_core_add_descriptor(struct fw_descriptor *desc) if (i !=3D desc->length) return -EINVAL; =20 - mutex_lock(&card_mutex); + guard(mutex)(&card_mutex); =20 - if (config_rom_length + required_space(desc) > 256) { - ret =3D -EBUSY; - } else { - list_add_tail(&desc->link, &descriptor_list); - config_rom_length +=3D required_space(desc); - descriptor_count++; - if (desc->immediate > 0) - descriptor_count++; - update_config_roms(); - ret =3D 0; - } + if (config_rom_length + required_space(desc) > 256) + return -EBUSY; =20 - mutex_unlock(&card_mutex); + list_add_tail(&desc->link, &descriptor_list); + config_rom_length +=3D required_space(desc); + descriptor_count++; + if (desc->immediate > 0) + descriptor_count++; + update_config_roms(); =20 - return ret; + return 0; } EXPORT_SYMBOL(fw_core_add_descriptor); =20 void fw_core_remove_descriptor(struct fw_descriptor *desc) { - mutex_lock(&card_mutex); + guard(mutex)(&card_mutex); =20 list_del(&desc->link); config_rom_length -=3D required_space(desc); @@ -212,8 +207,6 @@ void fw_core_remove_descriptor(struct fw_descriptor *de= sc) if (desc->immediate > 0) descriptor_count--; update_config_roms(); - - mutex_unlock(&card_mutex); } EXPORT_SYMBOL(fw_core_remove_descriptor); =20 @@ -587,16 +580,16 @@ int fw_card_add(struct fw_card *card, card->link_speed =3D link_speed; card->guid =3D guid; =20 - mutex_lock(&card_mutex); + guard(mutex)(&card_mutex); =20 generate_config_rom(card, tmp_config_rom); ret =3D card->driver->enable(card, tmp_config_rom, config_rom_length); - if (ret =3D=3D 0) - list_add_tail(&card->link, &card_list); + if (ret < 0) + return ret; =20 - mutex_unlock(&card_mutex); + list_add_tail(&card->link, &card_list); =20 - return ret; + return 0; } EXPORT_SYMBOL(fw_card_add); =20 @@ -720,9 +713,8 @@ void fw_core_remove_card(struct fw_card *card) PHY_LINK_ACTIVE | PHY_CONTENDER, 0); fw_schedule_bus_reset(card, false, true); =20 - mutex_lock(&card_mutex); - list_del_init(&card->link); - mutex_unlock(&card_mutex); + scoped_guard(mutex, &card_mutex) + list_del_init(&card->link); =20 /* Switch off most of the card driver interface. */ dummy_driver.free_iso_context =3D card->driver->free_iso_context; --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 97B7738F9A for ; Sun, 4 Aug 2024 13:02:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776556; cv=none; b=KoWiEdVoKuEbRv85XCdguVl5HQf15xdbWIXhM3mO0vL2tavY51+ndMHsN5V09+dW0HDy79lHZyObN8OEjAjl+rgHs9//HApFXDHedwtAUdtl9JVmqxG2nu7hZDr6QAcni5kwRZtmWxkuBgLUT3uLNrlbZZPr9m8qVcT03/43C0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776556; c=relaxed/simple; bh=JeyYRSMCwYlr7qNMG60tXxpFd6Zjzxm4aN90qQy7yKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ml2PYS9S1w3E7Kzd7y4duakj8G/Fya1MI5WIdBukt0wc7tx1cNt7FjKs5UMnS/G1m9Zd4JTh8jpZrqSuwYFm7mXlpIjjRcVAZZpihbpPn7w2hhv7rg+PvKs9ZJcMYD0iFlT+2DdpLtg1Td96QCkf7w6s+KzbGjX/UBjW9b+D7pw= 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=T13axiZ2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qGaf0/Af; arc=none smtp.client-ip=103.168.172.146 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="T13axiZ2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qGaf0/Af" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id A59251388027; Sun, 4 Aug 2024 09:02:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 04 Aug 2024 09:02:33 -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=1722776553; x= 1722862953; bh=8IZ5bfVFLX4rIiQS2rZQ4M3BHJvsAdGdGKx2Wo29X3M=; b=T 13axiZ2v/1vg5Aa1EwHifIKLIvzas8XqIQCVCX5hlwnMaKTmjwP2KU0cyHZX7deW YME6ZH9UrsrqRnu5/XmApXleJR7ocAMx3LMc41XoHEfeNbu1AKr1gO9vbEK/Zsy1 /iIu+9+8W24v4/Z/iIfn8DgZlswQGEWM69C7URqmHIPcSgWk859zl32cLhzoATSp e78uLU2tZlgIPit/WaJzvurbJdrYHGC+/uw4YDqS6CpQmiGSL+lG1Ik2P3V9VBSp LpMXRCp2R6ugndHN48nemEumyQa02JsrX+sXk7b1n2fpv4mfpba6u0IyMTVXQU3Q wNjZmvAL/V1O5OIqN40yA== 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=1722776553; x= 1722862953; bh=8IZ5bfVFLX4rIiQS2rZQ4M3BHJvsAdGdGKx2Wo29X3M=; b=q Gaf0/AfPyGgMOEPDl8qZ+QHhvk6qy0CuM+U/2I9H2j5/ejtWxeFK29cp+a1yB+ZM ldCxe+L0DywFWjANCrlBkS9dlru/Qj10HN7sZqnjBLA2iGKOyXbRlKiVVeoc/02M gg8P35BUpidelYE/galFAaDg29fNjDmE+RVYGWoT1w54QEGMfpT3UbGDhpiOdfnF TlLOJ6qsW8wpVPUpO6TbOiHyKt+W4T2w/A87jfmKfNxBmGR3EVVg8GtPZ6X4/0oP TfGTp8OVAWRDMQxuiw9k4ZnzJqIBvPGXFC5X9bcaSAPT6lNSQ3k4o5LeFtmPeMQ5 oBkSX5/pboJ3yfhfyQYzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:32 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 03/17] firewire: core: use guard macro to maintain the list of cdev clients Date: Sun, 4 Aug 2024 22:02:10 +0900 Message-ID: <20240804130225.243496-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function maintains userspace clients by the list in fw_device object associated to the operated character device. The concurrent access to the list is protected by mutex in the object. This commit uses guard macro to maintain the mutex. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 619048dcfd72..a51aabb963fb 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -375,10 +375,10 @@ static void for_each_client(struct fw_device *device, { struct client *c; =20 - mutex_lock(&device->client_list_mutex); + guard(mutex)(&device->client_list_mutex); + list_for_each_entry(c, &device->client_list, link) callback(c); - mutex_unlock(&device->client_list_mutex); } =20 static int schedule_reallocations(int id, void *p, void *data) @@ -470,7 +470,7 @@ static int ioctl_get_info(struct client *client, union = ioctl_arg *arg) if (ret !=3D 0) return -EFAULT; =20 - mutex_lock(&client->device->client_list_mutex); + guard(mutex)(&client->device->client_list_mutex); =20 client->bus_reset_closure =3D a->bus_reset_closure; if (a->bus_reset !=3D 0) { @@ -481,8 +481,6 @@ static int ioctl_get_info(struct client *client, union = ioctl_arg *arg) if (ret =3D=3D 0 && list_empty(&client->link)) list_add_tail(&client->link, &client->device->client_list); =20 - mutex_unlock(&client->device->client_list_mutex); - return ret ? -EFAULT : 0; } =20 @@ -1884,9 +1882,8 @@ static int fw_device_op_release(struct inode *inode, = struct file *file) list_del(&client->phy_receiver_link); spin_unlock_irq(&client->device->card->lock); =20 - mutex_lock(&client->device->client_list_mutex); - list_del(&client->link); - mutex_unlock(&client->device->client_list_mutex); + scoped_guard(mutex, &client->device->client_list_mutex) + list_del(&client->link); =20 if (client->iso_context) fw_iso_context_destroy(client->iso_context); --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 D47283BBE9 for ; Sun, 4 Aug 2024 13:02:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776557; cv=none; b=UzZsq+1d6kEXxRC/P2E0vCHJc+CrQ/TE17mfAAJo3WwfmeStuvxFTMOBHERdGjjQOKclwUaaMW4pPFA8uspqZG6mC9E/orJ7NzPw3gtMHfdjY23SyjTqI50xF48l6daUszWazcZZl/D1CDEPM49QR2nBGQlYhQkqT+7wBfJ248c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776557; c=relaxed/simple; bh=vA0kDygfFj7ZpFqinqieUC76/4F6R76Vd+hTvrPc/oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NiK+m5YD7RqupgnlVY2MPXbpxSRgmaOJYgiUWqfUt5NtmDtrVFZ8kkXK7G/if5OH736JqdrDZFHH6p1caIJEJSHZp/lqgwCql++Zs1MzSvR4wykqEr1fIaXOI6ez0PXsFcQax4HoGhPijMbvfg4UgsyoYy1qNdFP7dlVBSBPf/A= 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=hcTiCBRM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TgLILsy2; arc=none smtp.client-ip=103.168.172.146 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="hcTiCBRM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TgLILsy2" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id EACC413807E7; Sun, 4 Aug 2024 09:02:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 04 Aug 2024 09:02: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=1722776554; x= 1722862954; bh=umV/dIhWSMe39OeV812KLlWHxNO+f3xTH4ZsEWLWI7U=; b=h cTiCBRMHcnfZcrEhwQIemboRFgT4OhvxPVVIuUd0kiYkF/vy/IlXXVeveEAb2szV kXuXhbWDhRN3P8+8KkMScvxKf854rBUNVjEpepAj32Y7T1OUhzbu9Xw8V8OG4pjG vCz9Q8kpNzyuEnOPQ1r8c8p9dAIu1ZCdOmo/8CEzhXP/DqVTWxVzR7scigNnNi64 38WBCz4JqEMKB2rjwF9N4sOh3wPjbEtqqfo89CqXVlCWBoPxi01qJm+65kxae7Iu 0PuGHAll/sWn0m9HM5RpZExKHBUbjse6rw+f5pow9FeVF2Ou+VoQWncQueVk2kqe pZ+XedhDE0EkopN/fiulg== 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=1722776554; x= 1722862954; bh=umV/dIhWSMe39OeV812KLlWHxNO+f3xTH4ZsEWLWI7U=; b=T gLILsy23ycuxII2aVp9gPz8CbzA7O7MHV5dIwDQeOchKOQnXIow7lsl5UBObO3Ij xtZcBG9tfQHJDmXerFiNsknfjFkWRD0p7RXkTLKqVSA+veuxdwR/c3nL7a3iyPA5 62SnIY03plDbQsFqS/Q7Q26uZgSiESpsvF31jSJBnxGxs+koViENMdKVx6xwiCVW hgbafr0aVSysqRrob4e2NkzZ6Kf/lF3aV2N61fG8UdSjrlW17wu9Iw7yq+U1v2Zn T8Q0ZAbg3G9UgG/EHoNy4nrRrdLZCi7/Otj8U+UyVdlPdaXRnzZ4I0c5SoIOL9hq e8Hp2xaQccyLwhCOpI0BA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:33 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 04/17] firewire: ohci: use guard macro to serialize accesses to phy registers Date: Sun, 4 Aug 2024 22:02:11 +0900 Message-ID: <20240804130225.243496-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 protects concurrent accesses to phy registers by mutex object in fw_ohci structure. This commit uses guard macro to maintain the mutex. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 71 +++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 8f2bbd0569fb..1461e008d265 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -713,26 +713,20 @@ static int read_paged_phy_reg(struct fw_ohci *ohci, i= nt page, int addr) static int ohci_read_phy_reg(struct fw_card *card, int addr) { struct fw_ohci *ohci =3D fw_ohci(card); - int ret; =20 - mutex_lock(&ohci->phy_reg_mutex); - ret =3D read_phy_reg(ohci, addr); - mutex_unlock(&ohci->phy_reg_mutex); + guard(mutex)(&ohci->phy_reg_mutex); =20 - return ret; + return read_phy_reg(ohci, addr); } =20 static int ohci_update_phy_reg(struct fw_card *card, int addr, int clear_bits, int set_bits) { struct fw_ohci *ohci =3D fw_ohci(card); - int ret; =20 - mutex_lock(&ohci->phy_reg_mutex); - ret =3D update_phy_reg(ohci, addr, clear_bits, set_bits); - mutex_unlock(&ohci->phy_reg_mutex); + guard(mutex)(&ohci->phy_reg_mutex); =20 - return ret; + return update_phy_reg(ohci, addr, clear_bits, set_bits); } =20 static inline dma_addr_t ar_buffer_bus(struct ar_context *ctx, unsigned in= t i) @@ -1882,13 +1876,15 @@ static int get_status_for_port(struct fw_ohci *ohci= , int port_index, { int reg; =20 - mutex_lock(&ohci->phy_reg_mutex); - reg =3D write_phy_reg(ohci, 7, port_index); - if (reg >=3D 0) + scoped_guard(mutex, &ohci->phy_reg_mutex) { + reg =3D write_phy_reg(ohci, 7, port_index); + if (reg < 0) + return reg; + reg =3D read_phy_reg(ohci, 8); - mutex_unlock(&ohci->phy_reg_mutex); - if (reg < 0) - return reg; + if (reg < 0) + return reg; + } =20 switch (reg & 0x0f) { case 0x06: @@ -1929,26 +1925,31 @@ static int get_self_id_pos(struct fw_ohci *ohci, u3= 2 self_id, static bool initiated_reset(struct fw_ohci *ohci) { int reg; - int ret =3D false; =20 - mutex_lock(&ohci->phy_reg_mutex); - reg =3D write_phy_reg(ohci, 7, 0xe0); /* Select page 7 */ - if (reg >=3D 0) { - reg =3D read_phy_reg(ohci, 8); - reg |=3D 0x40; - reg =3D write_phy_reg(ohci, 8, reg); /* set PMODE bit */ - if (reg >=3D 0) { - reg =3D read_phy_reg(ohci, 12); /* read register 12 */ - if (reg >=3D 0) { - if ((reg & 0x08) =3D=3D 0x08) { - /* bit 3 indicates "initiated reset" */ - ret =3D true; - } - } - } - } - mutex_unlock(&ohci->phy_reg_mutex); - return ret; + guard(mutex)(&ohci->phy_reg_mutex); + + // Select page 7 + reg =3D write_phy_reg(ohci, 7, 0xe0); + if (reg < 0) + return reg; + + reg =3D read_phy_reg(ohci, 8); + if (reg < 0) + return reg; + + // set PMODE bit + reg |=3D 0x40; + reg =3D write_phy_reg(ohci, 8, reg); + if (reg < 0) + return reg; + + // read register 12 + reg =3D read_phy_reg(ohci, 12); + if (reg < 0) + return reg; + + // bit 3 indicates "initiated reset" + return !!((reg & 0x08) =3D=3D 0x08); } =20 /* --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 2B95147773 for ; Sun, 4 Aug 2024 13:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776558; cv=none; b=XsDyJPxywOhyukW885tXxhszqf2GgkoKW1j+Nw9vF9W12WNwic876ty+n6wBKnI6StdZBVZEmdvrEKdGQuGTNkBiozU8An8gDNz+vBHb6I75zI4woBalcNepEwQjM8ZW89J476E+LHFlVzSq+4rubGjk+zE6Y9HaOSXUo1LlULA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776558; c=relaxed/simple; bh=cscKU5uPCciyY7dYw/8esZBE005/LOUY76gf8+d1Fko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fkfvbU0GUrnhkVAYqCFCkkoe+zRG5l2uYRfs/rOzTzTIBZjcPZnHvaerv97t1TcKWmSKA5bYwtilm+GBZzEOWi7uCNpRpNWO/hOdQ6NBvZQ7iBt4EEzCNguumrc2+81P3J+sv9j0YuASjuc5rE3/mZiuRq9pQ0g7O7xgdV2vogs= 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=v4dlk2Cg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ahxdGVbH; arc=none smtp.client-ip=103.168.172.159 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="v4dlk2Cg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ahxdGVbH" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4B17B11481EB; Sun, 4 Aug 2024 09:02:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 04 Aug 2024 09:02:36 -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=1722776556; x= 1722862956; bh=Qc/S6YXZ+4o3poTVbyilyGCeWi9HX+4N+cgNY9BibBI=; b=v 4dlk2CgeNhcL7Ly2ue62WFXDjfMN/Bu806IMPBop8oqOYineurANx4G5ddPG6m4S +qT3tU3xv64Lo3wjYA+Kb3knaCGOIprhSv/n9iM/9i3nXp45lftExODrKZahcBXk cjlg+ZFSzbj/W5ea0AnrB39SquPVF+MlC+fZkqP3D6GYcRNz4T+mNKMv/5cHkmuX YizP6AFMn4Ay5o2z87S/5/wSR/8wkTbpJpiyY3614TwQ6bGB9BxOyFQ3yG6/H65h 8h7V2MMT3ks9qeBlulO5wiCG+X67Iqda64aVGG8MTnkr0qhO5FPXgb0EwU8BleqH B5ryVKxuU9qruQ1aq320g== 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=1722776556; x= 1722862956; bh=Qc/S6YXZ+4o3poTVbyilyGCeWi9HX+4N+cgNY9BibBI=; b=a hxdGVbH5i/BdKRRvPn6D+pfzOPcEREtFwXJslIsJhLm4/r6Cw3BT2OD7aF11rOKf m8sEUseNk8iIOK1mKHhcDWfyouZfxuXcR1hqssnLtYX/oq2I0Dupq2YjrIuMEfrl 3YloQ0abnE4GpvvXaORFSTxJdlohZZdwpyTKnS+WVjbcnFz8/1R0xIQrN9n5w0r0 qxEl6Z68k4dRebt5RQVL0aanQYuxpea16mmmGKNCyiuVKQ3bj2BV/s1Edpm9ZJfY 9o1FAiSSEDJYoNYeU1uAO3gFp2yz0aRS32z5weydfOiz0sn2QSzXoPSEF8FHivda hYj8ZACP++3iwFMu4T6MQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:35 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 05/17] firewire: core: use guard macro to maintain RCU scope for transaction address handler Date: Sun, 4 Aug 2024 22:02:12 +0900 Message-ID: <20240804130225.243496-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function maintains address handlers by list. RCU is utilized for efficient read access to any entries in the list. This commit uses guard macro to maintain RCU locking and releasing. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-transaction.c | 35 +++++++++++++---------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index 2a2cbd6e2f9b..a0224d4d8e11 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -925,16 +925,14 @@ static void handle_exclusive_region_request(struct fw= _card *card, if (tcode =3D=3D TCODE_LOCK_REQUEST) tcode =3D 0x10 + async_header_get_extended_tcode(p->header); =20 - rcu_read_lock(); - handler =3D lookup_enclosing_address_handler(&address_handler_list, - offset, request->length); - if (handler) - handler->address_callback(card, request, - tcode, destination, source, - p->generation, offset, - request->data, request->length, - handler->callback_data); - rcu_read_unlock(); + scoped_guard(rcu) { + handler =3D lookup_enclosing_address_handler(&address_handler_list, offs= et, + request->length); + if (handler) + handler->address_callback(card, request, tcode, destination, source, + p->generation, offset, request->data, + request->length, handler->callback_data); + } =20 if (!handler) fw_send_response(card, request, RCODE_ADDRESS_ERROR); @@ -967,17 +965,14 @@ static void handle_fcp_region_request(struct fw_card = *card, return; } =20 - rcu_read_lock(); - list_for_each_entry_rcu(handler, &address_handler_list, link) { - if (is_enclosing_handler(handler, offset, request->length)) - handler->address_callback(card, request, tcode, - destination, source, - p->generation, offset, - request->data, - request->length, - handler->callback_data); + scoped_guard(rcu) { + list_for_each_entry_rcu(handler, &address_handler_list, link) { + if (is_enclosing_handler(handler, offset, request->length)) + handler->address_callback(card, request, tcode, destination, source, + p->generation, offset, request->data, + request->length, handler->callback_data); + } } - rcu_read_unlock(); =20 fw_send_response(card, request, RCODE_COMPLETE); } --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 532694D8DA for ; Sun, 4 Aug 2024 13:02:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776560; cv=none; b=Ke2mJpk/oPXu/RUaKf6cJeqNxrf0/W4UCIEYf45WUovB0DRq0ZrnErE2ovHUBjHgnKwEw2i+qVnUXwm1MSYYv8JYL/6hsfZWk5Azy64iDBFM6LxRhdukeYTtd0dCNYjlTqtTrArLuEzty8F7bfmIdT+pzSyILXqouRU2OxBOFEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776560; c=relaxed/simple; bh=6gNVdCbKVSjJWTIrAa6h7j/OsYRdI7mtMVNyParzw+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QgXfB38BgQOTj6mOS7tX2zLfMD5LMx+/bcq2G6TtQGPcJJ5SEsPL5G11Tv4sQFgRSupbgrw/wtcZow1M800nnhQN3m8E1sf9DNsQyEXwGtYSIO6P10HJL4ecSfOVvmd0SwjgTKTRT4pgEE7nCxrlFvW3u/PewhfXj9+U/WkyJuw= 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=cL5A5xKh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=X8VvpyGv; arc=none smtp.client-ip=103.168.172.146 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="cL5A5xKh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="X8VvpyGv" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 97F641388037; Sun, 4 Aug 2024 09:02:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 04 Aug 2024 09:02:37 -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=1722776557; x= 1722862957; bh=GZl0F95VKdVRmO/VEzrXjIFDoXhwf1ZOuWhytnJzBf0=; b=c L5A5xKhX5dT1ywGHYqCCxW6xxlGDrgTd2HK44i6NLyvaZSHfXwMSmL8/HY3AjX1P lGWQ85TWXeEujVwbovv9TprvDHewcJhYJ+LfJGkOeK7vwqViKXGY3i9AhE3bW+pQ 2necELC5gHSct9W9BuRa7N5QErfGI8EXduEg7W/oKkscDxLlyUx4BawNsMHqctLo VlDE6tcyuhDpBC3/2Qp5yGl8pka92UlMN03HtRf1NwMaeofaeI4S7U9AlgHb7T+y sHflI0uz5sWxKina1BDAUEEcDIsSw+YDA6afon4mtX7z1qnGIowONnz7THJk0lOF vakSVcY5GlNxOBGX75xvg== 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=1722776557; x= 1722862957; bh=GZl0F95VKdVRmO/VEzrXjIFDoXhwf1ZOuWhytnJzBf0=; b=X 8VvpyGvcHY+3vX1J0lvikQBPWE43DUFODQMp27ipV+NO+Z0QRAAo55DUoyMc167r CBaqzed5Wi7uHbfpFQ8C8gqHox5xy5MHW8BRDs5036OhcnuSE/EgdhEUl7yKYWdx IC3d5REEuMKywaHBBdd4o1znyIuHpa8R68hKrza+DZ/hwj+BtUXRQjyWEAda6xkX ov88pRcof4L+9+ucTr8cZnvSdekU+irCnC6F6arANw8INrdZAPmod6+PmCXKpSEs gLYOqsVfT3CCu2V96kh6NhQamwOGER+D7u7Lnw71n+tE0p8YBhQ4qZ3R1k+3/LTa /qkAwO82eSW0hWvqCpOUg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:36 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 06/17] firewire: core: use guard macro to access to IDR for fw_device Date: Sun, 4 Aug 2024 22:02:13 +0900 Message-ID: <20240804130225.243496-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function maintains the instance of fw_device structure by IDR. The concurrent access to IDR is protected by static read/write semaphore. The semaphore is also utilized to protect concurrent access to the content of configuration ROM cached to the instance so that the cache is swapped to the latest one. This commit uses guard macro to maintain the mutex. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 25 +++++------- drivers/firewire/core-device.c | 73 +++++++++++++++------------------- 2 files changed, 42 insertions(+), 56 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index a51aabb963fb..c3baf688bb70 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -454,21 +454,18 @@ static int ioctl_get_info(struct client *client, unio= n ioctl_arg *arg) a->version =3D FW_CDEV_KERNEL_VERSION; a->card =3D client->device->card->index; =20 - down_read(&fw_device_rwsem); - - if (a->rom !=3D 0) { - size_t want =3D a->rom_length; - size_t have =3D client->device->config_rom_length * 4; - - ret =3D copy_to_user(u64_to_uptr(a->rom), - client->device->config_rom, min(want, have)); + scoped_guard(rwsem_read, &fw_device_rwsem) { + if (a->rom !=3D 0) { + size_t want =3D a->rom_length; + size_t have =3D client->device->config_rom_length * 4; + + ret =3D copy_to_user(u64_to_uptr(a->rom), client->device->config_rom, + min(want, have)); + if (ret !=3D 0) + return -EFAULT; + } + a->rom_length =3D client->device->config_rom_length * 4; } - a->rom_length =3D client->device->config_rom_length * 4; - - up_read(&fw_device_rwsem); - - if (ret !=3D 0) - return -EFAULT; =20 guard(mutex)(&client->device->client_list_mutex); =20 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index 00e9a13e6c45..d695ec2f1efe 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -288,7 +288,7 @@ static ssize_t show_immediate(struct device *dev, const u32 *directories[] =3D {NULL, NULL}; int i, value =3D -1; =20 - down_read(&fw_device_rwsem); + guard(rwsem_read)(&fw_device_rwsem); =20 if (is_fw_unit(dev)) { directories[0] =3D fw_unit(dev)->directory; @@ -317,8 +317,6 @@ static ssize_t show_immediate(struct device *dev, } } =20 - up_read(&fw_device_rwsem); - if (value < 0) return -ENOENT; =20 @@ -339,7 +337,7 @@ static ssize_t show_text_leaf(struct device *dev, char dummy_buf[2]; int i, ret =3D -ENOENT; =20 - down_read(&fw_device_rwsem); + guard(rwsem_read)(&fw_device_rwsem); =20 if (is_fw_unit(dev)) { directories[0] =3D fw_unit(dev)->directory; @@ -382,15 +380,14 @@ static ssize_t show_text_leaf(struct device *dev, } } =20 - if (ret >=3D 0) { - /* Strip trailing whitespace and add newline. */ - while (ret > 0 && isspace(buf[ret - 1])) - ret--; - strcpy(buf + ret, "\n"); - ret++; - } + if (ret < 0) + return ret; =20 - up_read(&fw_device_rwsem); + // Strip trailing whitespace and add newline. + while (ret > 0 && isspace(buf[ret - 1])) + ret--; + strcpy(buf + ret, "\n"); + ret++; =20 return ret; } @@ -466,10 +463,10 @@ static ssize_t config_rom_show(struct device *dev, struct fw_device *device =3D fw_device(dev); size_t length; =20 - down_read(&fw_device_rwsem); + guard(rwsem_read)(&fw_device_rwsem); + length =3D device->config_rom_length * 4; memcpy(buf, device->config_rom, length); - up_read(&fw_device_rwsem); =20 return length; } @@ -478,13 +475,10 @@ static ssize_t guid_show(struct device *dev, struct device_attribute *attr, char *buf) { struct fw_device *device =3D fw_device(dev); - int ret; =20 - down_read(&fw_device_rwsem); - ret =3D sysfs_emit(buf, "0x%08x%08x\n", device->config_rom[3], device->co= nfig_rom[4]); - up_read(&fw_device_rwsem); + guard(rwsem_read)(&fw_device_rwsem); =20 - return ret; + return sysfs_emit(buf, "0x%08x%08x\n", device->config_rom[3], device->con= fig_rom[4]); } =20 static ssize_t is_local_show(struct device *dev, @@ -524,7 +518,8 @@ static ssize_t units_show(struct device *dev, struct fw_csr_iterator ci; int key, value, i =3D 0; =20 - down_read(&fw_device_rwsem); + guard(rwsem_read)(&fw_device_rwsem); + fw_csr_iterator_init(&ci, &device->config_rom[ROOT_DIR_OFFSET]); while (fw_csr_iterator_next(&ci, &key, &value)) { if (key !=3D (CSR_UNIT | CSR_DIRECTORY)) @@ -533,7 +528,6 @@ static ssize_t units_show(struct device *dev, if (i >=3D PAGE_SIZE - (8 + 1 + 8 + 1)) break; } - up_read(&fw_device_rwsem); =20 if (i) buf[i - 1] =3D '\n'; @@ -729,10 +723,10 @@ static int read_config_rom(struct fw_device *device, = int generation) goto out; } =20 - down_write(&fw_device_rwsem); - device->config_rom =3D new_rom; - device->config_rom_length =3D length; - up_write(&fw_device_rwsem); + scoped_guard(rwsem_write, &fw_device_rwsem) { + device->config_rom =3D new_rom; + device->config_rom_length =3D length; + } =20 kfree(old_rom); ret =3D RCODE_COMPLETE; @@ -826,11 +820,11 @@ struct fw_device *fw_device_get_by_devt(dev_t devt) { struct fw_device *device; =20 - down_read(&fw_device_rwsem); + guard(rwsem_read)(&fw_device_rwsem); + device =3D idr_find(&fw_device_idr, MINOR(devt)); if (device) fw_device_get(device); - up_read(&fw_device_rwsem); =20 return device; } @@ -882,9 +876,8 @@ static void fw_device_shutdown(struct work_struct *work) device_for_each_child(&device->device, NULL, shutdown_unit); device_unregister(&device->device); =20 - down_write(&fw_device_rwsem); - idr_remove(&fw_device_idr, minor); - up_write(&fw_device_rwsem); + scoped_guard(rwsem_write, &fw_device_rwsem) + idr_remove(&fw_device_idr, minor); =20 fw_device_put(device); } @@ -958,7 +951,7 @@ static int lookup_existing_device(struct device *dev, v= oid *data) if (!is_fw_device(dev)) return 0; =20 - down_read(&fw_device_rwsem); /* serialize config_rom access */ + guard(rwsem_read)(&fw_device_rwsem); // serialize config_rom access spin_lock_irq(&card->lock); /* serialize node access */ =20 if (memcmp(old->config_rom, new->config_rom, 6 * 4) =3D=3D 0 && @@ -990,7 +983,6 @@ static int lookup_existing_device(struct device *dev, v= oid *data) } =20 spin_unlock_irq(&card->lock); - up_read(&fw_device_rwsem); =20 return match; } @@ -1099,13 +1091,11 @@ static void fw_device_init(struct work_struct *work) device_initialize(&device->device); =20 fw_device_get(device); - down_write(&fw_device_rwsem); - minor =3D idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS, - GFP_KERNEL); - up_write(&fw_device_rwsem); - - if (minor < 0) - goto error; + scoped_guard(rwsem_write, &fw_device_rwsem) { + minor =3D idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS, GFP_KERNE= L); + if (minor < 0) + goto error; + } =20 device->device.bus =3D &fw_bus_type; device->device.type =3D &fw_device_type; @@ -1165,9 +1155,8 @@ static void fw_device_init(struct work_struct *work) return; =20 error_with_cdev: - down_write(&fw_device_rwsem); - idr_remove(&fw_device_idr, minor); - up_write(&fw_device_rwsem); + scoped_guard(rwsem_write, &fw_device_rwsem) + idr_remove(&fw_device_idr, minor); error: fw_device_put(device); /* fw_device_idr's reference */ =20 --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 C2FE256B7C for ; Sun, 4 Aug 2024 13:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776561; cv=none; b=HbZH/mnknSxQl9u/AgeFYj8DhnwhJ0/fiZMed6If5y4mCh6n3yC51GhKHluyqKwS2o26RIWUo56hrt36s7+hkwAOw8+Gawu+zpjZGJnTfopea1NuckMV+fRKxSpGGwT9bxoBCL06TfFTRjgXbmrLpKpZFrfMfH/VqkrKLsgsXJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776561; c=relaxed/simple; bh=cWH7ne9vlR3TeVR1Q85Yfp2ze/ZNy4hqU1VPnNmO3sk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mZaE3ZYHCpHGDDz9ZOnTtFinl2FQNP6TUxssEM/QroHYJkknTOzPiKa9jPx0TYVDjTQ8lAX/0ZPpndqhFeQUvf+qc9mBv28OD08bodg3ugOEg87AUwUljG6QSnzH6WgA+Xm1m7GV8TUITTQDaJB1Ain3ltXRCum0wBgWyrcXrP4= 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=gnaPNysJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lMw4/ZLx; arc=none smtp.client-ip=103.168.172.146 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="gnaPNysJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lMw4/ZLx" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 0163B138801E; Sun, 4 Aug 2024 09:02:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 04 Aug 2024 09:02:38 -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=1722776558; x= 1722862958; bh=ylV0FAWwnqnELWHfpdHvBmEJyKerlndDqM/PUzAtIHU=; b=g naPNysJyaGopYZ5fgjSO4g90gA8Q1rKmpj0nji9jgMnXGnts3fIwdaS4GQ0F/aZD wFqAxOjZ9mWZIfN58KPjXZYtyc27GpWJMhybpJO3WqBRuxmMsawXX2pLezpibeXV aVXr9BO7dOxeNp84XHJArMGKMSjpRj/H3UvNO7T3gkAvmF798dVDHcGBi8y6Jscs BGgf1+5e+iPeQEkXkwuf1rIeVQ1AdmzkUA7HVQyvdYO4wnRtKtbZqDWbcxKxfPxq 8tZGMP7j25jD9/n2721LxGp6WHn68awCW0MjUhwT6xN3l7WeNS8KLGr1XsMSfQoU R7daiFsQz/tQ7zjWcNVEA== 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=1722776558; x= 1722862958; bh=ylV0FAWwnqnELWHfpdHvBmEJyKerlndDqM/PUzAtIHU=; b=l Mw4/ZLxSlRnbV2W9QRAbxs0ef+oIcTyYz5oup64YrPLF4cajYFbgm0lxRNygjE92 /45rBUihM9XK8HkGOjR47Y1JmucpFNs8rVnJuF2tzJJhOncW6rQuIWxhcgwwUkHT OMxrpF3IlsPIUEoUZKM45bNDEgVcCzTYt3hz376qNFGd4jUcAJrY3gL5q1q/bkY+ V0zDRM6csZQASWzcyBtAvHzWsiaB6TCefACi5s8Jlrpif5GQockNT/HDZNY51bld BOIViJW1a78dACzS16/tkTVgwJCzYEGq34gSr8Ovl2iuQmAxXo6EvSrgsgNTQDZx 39ZklYxmCDRqlOPmoqN5Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:37 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 07/17] firewire: core: use guard macro to maintain the list of address handler for transaction Date: Sun, 4 Aug 2024 22:02:14 +0900 Message-ID: <20240804130225.243496-8-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function maintains address handlers by list. It is protected by spinlock to insert and remove entry to the list. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-transaction.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index a0224d4d8e11..a006daf385e9 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -596,7 +596,7 @@ int fw_core_add_address_handler(struct fw_address_handl= er *handler, handler->length =3D=3D 0) return -EINVAL; =20 - spin_lock(&address_handler_list_lock); + guard(spinlock)(&address_handler_list_lock); =20 handler->offset =3D region->start; while (handler->offset + handler->length <=3D region->end) { @@ -615,8 +615,6 @@ int fw_core_add_address_handler(struct fw_address_handl= er *handler, } } =20 - spin_unlock(&address_handler_list_lock); - return ret; } EXPORT_SYMBOL(fw_core_add_address_handler); @@ -632,9 +630,9 @@ EXPORT_SYMBOL(fw_core_add_address_handler); */ void fw_core_remove_address_handler(struct fw_address_handler *handler) { - spin_lock(&address_handler_list_lock); - list_del_rcu(&handler->link); - spin_unlock(&address_handler_list_lock); + scoped_guard(spinlock, &address_handler_list_lock) + list_del_rcu(&handler->link); + synchronize_rcu(); } EXPORT_SYMBOL(fw_core_remove_address_handler); --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 3D7456A8CF for ; Sun, 4 Aug 2024 13:02:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776562; cv=none; b=S99YtDRqUbd+TGUepjYPsUzyWHjjST6z1IAAaqgGtuVwJCFknrrZjaYQt6zGc+O3uFEopBBQISAwB6b90fewvZrHAnWigN3goLaVQPA11QBvQH2cJxV82T4qvy6lf7RofBuSZoCsYE9CO4Fa9Ty3fouLpfEUurqmIJi8tEXBwjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776562; c=relaxed/simple; bh=0zT4ELUdypbLDPtYPoNIq0nN4q+2KRKcNt9sf1SBc84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VVkeczvl6DW3r1p9b2BXLRM1FR33+cn7/ilPm+yE1AJI0Ew+zqDW3buQf9D7W8mzzmVOEDusTJ24cPQIgCIlxAoroGNpL0wWkhuE0wcgGD7jqoqqohSbH7fvE53vgMzE1rjB3No/x88UC6NSN6es6ZvQ0S8kPiO9UTGItbtkl1E= 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=jsgF6qVn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ic0zytln; arc=none smtp.client-ip=103.168.172.146 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="jsgF6qVn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ic0zytln" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 55AAA1388062; Sun, 4 Aug 2024 09:02:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 04 Aug 2024 09:02:40 -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=1722776560; x= 1722862960; bh=riXT/ZPaI3yITLXofYuDWzvYYTW64WraJqRL8dIk1u8=; b=j sgF6qVnFxJ9MLP3LeORc+R1PNncoIFM9zgGsyGdkUPE+VW3VN1Ja51EWMWpxnSn3 pDNsVO6yLFDl2ScXZEHuzZnSfv2ykIZDHijt2kW6/QsIb9Fx/D0OY98NNIWykKbh iPV2Czbb6d2OuGdw9st6R4DiVm3pT3bEsk8nu5BNfyWESaER8n/MhUKE3+JsA337 eLlFgs/qkmBL3nYZQnzWFtwIRDhQTFO8IRC5NnIKPBDYqjeX2FbfSx1hB+Yieg5P XR6e4O4m0fIu386ZteCH6GA0fzCxMDoXoUnDbaADxMsVVaAoheReARD3XBkuGb+M E073eCAh4cc6dHG4Z4P1w== 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=1722776560; x= 1722862960; bh=riXT/ZPaI3yITLXofYuDWzvYYTW64WraJqRL8dIk1u8=; b=i c0zytlny3tW5mxYP9Q96bT+HC5/eGZ4+XbqhrHtj7oSPjGkgdsIQsvvj8qOaGyZX TdafKBoqN1ovXhgOHMWNTdlbTHTD+W3KVfVXGV7iqVxDn0UTn74gDuI0dAB3ic2X zS0CfxxJZIw1ypWuUjvYGyyh9W8QkX0xqRs19QMxBBTbW5ZNthDASwtO5D2Dyrqj B3hnqJRuOKezzOJuR/oO36IKSHw1nEDsqwNtBbnj1QtvZgW4OftQYY2d7CRHrshT cKm3SZ2NmI5p7A5Q7ZHeziG/HdhSXA4h+/PJVca5P6zbLk3gggNgcA60PiKED+my krK5Rus4OlhIzvV125SHg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:39 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 08/17] firewire: core: use guard macro to disable local IRQ Date: Sun, 4 Aug 2024 22:02:15 +0900 Message-ID: <20240804130225.243496-9-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function provides an operation for userspace application to retrieve current value of CYCLE_TIMER register with several types of system time. In the operation, local interrupt is disables so that the access of the register and ktime are done atomically. This commit uses guard macro to disable/enable local interrupts. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index c3baf688bb70..90e9dfed8681 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -1263,29 +1263,27 @@ static int ioctl_get_cycle_timer2(struct client *cl= ient, union ioctl_arg *arg) struct fw_card *card =3D client->device->card; struct timespec64 ts =3D {0, 0}; u32 cycle_time =3D 0; - int ret =3D 0; + int ret; =20 - local_irq_disable(); + guard(irq)(); =20 ret =3D fw_card_read_cycle_time(card, &cycle_time); if (ret < 0) - goto end; + return ret; =20 switch (a->clk_id) { case CLOCK_REALTIME: ktime_get_real_ts64(&ts); break; case CLOCK_MONOTONIC: ktime_get_ts64(&ts); break; case CLOCK_MONOTONIC_RAW: ktime_get_raw_ts64(&ts); break; default: - ret =3D -EINVAL; + return -EINVAL; } -end: - local_irq_enable(); =20 a->tv_sec =3D ts.tv_sec; a->tv_nsec =3D ts.tv_nsec; a->cycle_timer =3D cycle_time; =20 - return ret; + return 0; } =20 static int ioctl_get_cycle_timer(struct client *client, union ioctl_arg *a= rg) --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 57E7876048 for ; Sun, 4 Aug 2024 13:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776563; cv=none; b=Rqn6bq8GiY4L4mDYJ58r65w6OlkooU5RfGaQVChzLtuCohXvmSNIpVW6M9dcvxNFQ44zDjtCcmcQeUvLc2mX9CnMgFl76ODAsklGjx1L2VFLK9YtQay9QDcPSxrKm5ylBGvOYzrL0388bOfwnAc5ts406x0MfBlFs4EarPdSWJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776563; c=relaxed/simple; bh=3M4QOIj5f1Z1b9G9IJV0Sp/2cF6cD0jloZp0mRO2NP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQvwy08PWJg4uctSmGm7ZgngMu2r1Gh1EVebNqAhwAzQ4nrhYOnwz6hqjOi7iM6j4caL9VrTThh08hIcsXCOsmQ5CgjJR00aM+FIJyj1Zfk6yNThfF6KIO6oWfFBL3fS0a06vkDbtX/VST5TEXkYl3QNpyygsE9eZ28qXTfV4wE= 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=IhSBqh1g; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SFki4GMw; arc=none smtp.client-ip=103.168.172.146 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="IhSBqh1g"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SFki4GMw" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id A388F138817A; Sun, 4 Aug 2024 09:02:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 04 Aug 2024 09:02:41 -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=1722776561; x= 1722862961; bh=cnExW14OrezM7AAY2ZcP4bF1stBaSNMPihuGoMDdgLg=; b=I hSBqh1gvrjtcsEc0nKOcGMM5dpTiQtMkhlsnKMX/GrX748Mwsxc99mAOuSCoRAdH W+QoaDEg4pCiOVqk4jF2EdNjX0R0XTc55c9+jkq3fz1jJLpScfsiIT7bL8+bcRO8 TTC4ybgMzEhQpG1zRrXDpU7aOJb9mY5aMBw9dSifXONmfY6RNYOeu1T3gTT8ZCJ3 mH+VgTfkHufa4KXNmroiSuPJhSigHPeB/4W825hL4HPuE1m2V1GBXuI2aOD4xHa2 rnBNn90kz3RDfO4bmzUdmvDBjb/6a16fBO8wefeC+SO79RVj0dx+E29QE+X1u2Ng 1W9b2hskRPQenduOZfwrg== 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=1722776561; x= 1722862961; bh=cnExW14OrezM7AAY2ZcP4bF1stBaSNMPihuGoMDdgLg=; b=S Fki4GMwOEDoZK8ctjVyZ3LgSQvwT+4TaR8tQcI8KUVK92bw3C3ODJvQgNoicwyo4 aboA8yb0tYl4Ekbb00KkphIZSb8NP7A0r/ykQOIA4UOSETXqNRfLAowERfS2oamU vUA7PtJ2AlCXhr+beIgxhpvFQzvxtEF9edtdatCBuD3iubjPze75AHkbq0Z1UTty OYDn7n+v/GX+LuV208ESMPIa3HX1xpznXVUrfSDaBu7uMp3vr91oPyjWOwKh4ojV E+LlKpSvaEq0sfwyD+JW8Kh0pa4YRTQt/nwKDZLzOlBlVvUq1FLHFjJyotUCv53z aR4ToR4EwREGRHTM6euxw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:40 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 09/17] firewire: core: use guard macro to maintain list of events for userspace clients Date: Sun, 4 Aug 2024 22:02:16 +0900 Message-ID: <20240804130225.243496-10-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function maintains events to userspace by list in the instance of client. The concurrent access to the list is protected by spinlock in the instance. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 90e9dfed8681..2e2199eaa05b 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -287,19 +287,17 @@ static int fw_device_op_open(struct inode *inode, str= uct file *file) static void queue_event(struct client *client, struct event *event, void *data0, size_t size0, void *data1, size_t size1) { - unsigned long flags; - event->v[0].data =3D data0; event->v[0].size =3D size0; event->v[1].data =3D data1; event->v[1].size =3D size1; =20 - spin_lock_irqsave(&client->lock, flags); - if (client->in_shutdown) - kfree(event); - else - list_add_tail(&event->link, &client->event_list); - spin_unlock_irqrestore(&client->lock, flags); + scoped_guard(spinlock_irqsave, &client->lock) { + if (client->in_shutdown) + kfree(event); + else + list_add_tail(&event->link, &client->event_list); + } =20 wake_up_interruptible(&client->wait); } @@ -321,10 +319,10 @@ static int dequeue_event(struct client *client, fw_device_is_shutdown(client->device)) return -ENODEV; =20 - spin_lock_irq(&client->lock); - event =3D list_first_entry(&client->event_list, struct event, link); - list_del(&event->link); - spin_unlock_irq(&client->lock); + scoped_guard(spinlock_irq, &client->lock) { + event =3D list_first_entry(&client->event_list, struct event, link); + list_del(&event->link); + } =20 total =3D 0; for (i =3D 0; i < ARRAY_SIZE(event->v) && total < count; i++) { @@ -1887,9 +1885,8 @@ static int fw_device_op_release(struct inode *inode, = struct file *file) fw_iso_buffer_destroy(&client->buffer, client->device->card); =20 /* Freeze client->resource_idr and client->event_list */ - spin_lock_irq(&client->lock); - client->in_shutdown =3D true; - spin_unlock_irq(&client->lock); + scoped_guard(spinlock_irq, &client->lock) + client->in_shutdown =3D true; =20 wait_event(client->tx_flush_wait, !has_outbound_transactions(client)); =20 --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 DBAAA12E1DB for ; Sun, 4 Aug 2024 13:02:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776565; cv=none; b=KZm4UlIyXjT6+xXUCw61DVZJ2ZpgSS5Lmf9xe8iYmiz+h+4IM9wNFCYUKGAytDAG7NIxOqesGU3RYUYuybUhQyjgQJ5xECIAZsKCMzjJSaJkPLwRPSx7XRFoCzXjzyhrE98TlIQPmGEnRTprAKDK/XK8kLhQVKJHew0UMFdJhK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776565; c=relaxed/simple; bh=uzVMeTX0BbvAA/TdPM5pqNjVCufYr9cCNWLDVrjaoUU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JOmPi6NQgh77EXw+yw0vO9VEFKlIiU64/UPU+HaeR6Jm3uANSOdldQ1ebjLytgUwgB3iP+RXQlRxxYK92UWoeHoyNfjXYd3/9I3iC2Q4eIPMS50oLlQAjV1PSH9KPDwKYKgWGRUcLr9EkGEWuZP3zv8a2JuwrXT0At/H0vXUahk= 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=KwAn0Dmm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cBCyvJZA; arc=none smtp.client-ip=103.168.172.159 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="KwAn0Dmm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cBCyvJZA" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 08BC21146FED; Sun, 4 Aug 2024 09:02:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Sun, 04 Aug 2024 09:02:43 -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=1722776563; x= 1722862963; bh=z5mX0VvBucVVAQ3hVsBzbK3EagpAINO+dbqWRzZbXyg=; b=K wAn0Dmm8EP66ftwA1UfXu/YuaeSi/ekZ5wS6rJBuTodqkgxOdo3UfY/y378K5KKx hY54sGBPcaau/hzyKNNEmHs3Vu2eoxY/S//bwv6oRGRUxiLy2EubkyaI0w9U6cdK Xkks8ZGBJFOxKi6Kxs7dA+s5EtJBnUdMoIh+LxtxwKZ+S8BvOZmI7Gl+a3fVxa60 N0QY8Y7+s4HNRqQYBMFvkRUTiIbmgFQi7ZX8iRkIY5kYxNgp8z5RTbTUUlUJ6ZdX KZMXDn8oyTKE7sZwgb7a7r9Iv9n9eQT0i70BJb/a74DmG6LRfPGqiKWJpzb3zl+p WA5S6W8uycZh0wksWBP0w== 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=1722776563; x= 1722862963; bh=z5mX0VvBucVVAQ3hVsBzbK3EagpAINO+dbqWRzZbXyg=; b=c BCyvJZA1pMufc0/Jft9+oMbPFJiaDgj1G+36aCVefN20VVI7u1eeZDc3CiB/vbXE SWCVMaiBw6vKA6A8FGuKePt8tEQBXReJHwy+hRoHv2ru5dDn5Qc1PPnQOH1GWxUy mB6VCpIy5nwMAcp6jyXgfDs6bk/vuEEMybhI3iCpGYwimrvDdCjoZJscY9649d5x X1jFGwhYYIFw2ZmgQsE1ZuH/SeJ1t/EaxxSdolXL/9bMe+4bclnNvZL8z4F1Pjfz RfB7ljEi7GBprJ+mZslb4cyvkRBNl4mEWpa6VQJ4N/1zcJexZxZF+yHAfcC0sRoC IGeItAShRoingxjQ9fRPQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:41 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 10/17] firewire: core: use guard macro to maintain IDR of isochronous resources for userspace clients Date: Sun, 4 Aug 2024 22:02:17 +0900 Message-ID: <20240804130225.243496-11-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function provides UAPI to maintain isochronous resources allocated by userspace clients across bus resets automatically. The resources are maintained by IDR and the concurrent access to it is protected by spinlock in the instance of client. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 131 ++++++++++++++++------------------- 1 file changed, 59 insertions(+), 72 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 2e2199eaa05b..c2d24cc5c1f1 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -399,9 +399,9 @@ static void queue_bus_reset_event(struct client *client) queue_event(client, &e->event, &e->reset, sizeof(e->reset), NULL, 0); =20 - spin_lock_irq(&client->lock); + guard(spinlock_irq)(&client->lock); + idr_for_each(&client->resource_idr, schedule_reallocations, client); - spin_unlock_irq(&client->lock); } =20 void fw_device_cdev_update(struct fw_device *device) @@ -483,25 +483,23 @@ static int add_client_resource(struct client *client, struct client_resource *resource, gfp_t gfp_mask) { bool preload =3D gfpflags_allow_blocking(gfp_mask); - unsigned long flags; int ret; =20 if (preload) idr_preload(gfp_mask); - spin_lock_irqsave(&client->lock, flags); =20 - if (client->in_shutdown) - ret =3D -ECANCELED; - else - ret =3D idr_alloc(&client->resource_idr, resource, 0, 0, - GFP_NOWAIT); - if (ret >=3D 0) { - resource->handle =3D ret; - client_get(client); - schedule_if_iso_resource(resource); + scoped_guard(spinlock_irqsave, &client->lock) { + if (client->in_shutdown) + ret =3D -ECANCELED; + else + ret =3D idr_alloc(&client->resource_idr, resource, 0, 0, GFP_NOWAIT); + if (ret >=3D 0) { + resource->handle =3D ret; + client_get(client); + schedule_if_iso_resource(resource); + } } =20 - spin_unlock_irqrestore(&client->lock, flags); if (preload) idr_preload_end(); =20 @@ -514,14 +512,14 @@ static int release_client_resource(struct client *cli= ent, u32 handle, { struct client_resource *resource; =20 - spin_lock_irq(&client->lock); - if (client->in_shutdown) - resource =3D NULL; - else - resource =3D idr_find(&client->resource_idr, handle); - if (resource && resource->release =3D=3D release) - idr_remove(&client->resource_idr, handle); - spin_unlock_irq(&client->lock); + scoped_guard(spinlock_irq, &client->lock) { + if (client->in_shutdown) + resource =3D NULL; + else + resource =3D idr_find(&client->resource_idr, handle); + if (resource && resource->release =3D=3D release) + idr_remove(&client->resource_idr, handle); + } =20 if (!(resource && resource->release =3D=3D release)) return -EINVAL; @@ -546,13 +544,12 @@ static void complete_transaction(struct fw_card *card= , int rcode, u32 request_ts { struct outbound_transaction_event *e =3D data; struct client *client =3D e->client; - unsigned long flags; =20 - spin_lock_irqsave(&client->lock, flags); - idr_remove(&client->resource_idr, e->r.resource.handle); - if (client->in_shutdown) - wake_up(&client->tx_flush_wait); - spin_unlock_irqrestore(&client->lock, flags); + scoped_guard(spinlock_irqsave, &client->lock) { + idr_remove(&client->resource_idr, e->r.resource.handle); + if (client->in_shutdown) + wake_up(&client->tx_flush_wait); + } =20 switch (e->rsp.without_tstamp.type) { case FW_CDEV_EVENT_RESPONSE: @@ -1307,25 +1304,24 @@ static void iso_resource_work(struct work_struct *w= ork) int generation, channel, bandwidth, todo; bool skip, free, success; =20 - spin_lock_irq(&client->lock); - generation =3D client->device->generation; - todo =3D r->todo; - /* Allow 1000ms grace period for other reallocations. */ - if (todo =3D=3D ISO_RES_ALLOC && - time_before64(get_jiffies_64(), - client->device->card->reset_jiffies + HZ)) { - schedule_iso_resource(r, DIV_ROUND_UP(HZ, 3)); - skip =3D true; - } else { - /* We could be called twice within the same generation. */ - skip =3D todo =3D=3D ISO_RES_REALLOC && - r->generation =3D=3D generation; + scoped_guard(spinlock_irq, &client->lock) { + generation =3D client->device->generation; + todo =3D r->todo; + // Allow 1000ms grace period for other reallocations. + if (todo =3D=3D ISO_RES_ALLOC && + time_before64(get_jiffies_64(), client->device->card->reset_jiffies = + HZ)) { + schedule_iso_resource(r, DIV_ROUND_UP(HZ, 3)); + skip =3D true; + } else { + // We could be called twice within the same generation. + skip =3D todo =3D=3D ISO_RES_REALLOC && + r->generation =3D=3D generation; + } + free =3D todo =3D=3D ISO_RES_DEALLOC || + todo =3D=3D ISO_RES_ALLOC_ONCE || + todo =3D=3D ISO_RES_DEALLOC_ONCE; + r->generation =3D generation; } - free =3D todo =3D=3D ISO_RES_DEALLOC || - todo =3D=3D ISO_RES_ALLOC_ONCE || - todo =3D=3D ISO_RES_DEALLOC_ONCE; - r->generation =3D generation; - spin_unlock_irq(&client->lock); =20 if (skip) goto out; @@ -1348,24 +1344,20 @@ static void iso_resource_work(struct work_struct *w= ork) =20 success =3D channel >=3D 0 || bandwidth > 0; =20 - spin_lock_irq(&client->lock); - /* - * Transit from allocation to reallocation, except if the client - * requested deallocation in the meantime. - */ - if (r->todo =3D=3D ISO_RES_ALLOC) - r->todo =3D ISO_RES_REALLOC; - /* - * Allocation or reallocation failure? Pull this resource out of the - * idr and prepare for deletion, unless the client is shutting down. - */ - if (r->todo =3D=3D ISO_RES_REALLOC && !success && - !client->in_shutdown && - idr_remove(&client->resource_idr, r->resource.handle)) { - client_put(client); - free =3D true; + scoped_guard(spinlock_irq, &client->lock) { + // Transit from allocation to reallocation, except if the client + // requested deallocation in the meantime. + if (r->todo =3D=3D ISO_RES_ALLOC) + r->todo =3D ISO_RES_REALLOC; + // Allocation or reallocation failure? Pull this resource out of the + // idr and prepare for deletion, unless the client is shutting down. + if (r->todo =3D=3D ISO_RES_REALLOC && !success && + !client->in_shutdown && + idr_remove(&client->resource_idr, r->resource.handle)) { + client_put(client); + free =3D true; + } } - spin_unlock_irq(&client->lock); =20 if (todo =3D=3D ISO_RES_ALLOC && channel >=3D 0) r->channels =3D 1ULL << channel; @@ -1403,10 +1395,10 @@ static void release_iso_resource(struct client *cli= ent, struct iso_resource *r =3D container_of(resource, struct iso_resource, resource); =20 - spin_lock_irq(&client->lock); + guard(spinlock_irq)(&client->lock); + r->todo =3D ISO_RES_DEALLOC; schedule_iso_resource(r, 0); - spin_unlock_irq(&client->lock); } =20 static int init_iso_resource(struct client *client, @@ -1845,14 +1837,9 @@ static int is_outbound_transaction_resource(int id, = void *p, void *data) =20 static int has_outbound_transactions(struct client *client) { - int ret; + guard(spinlock_irq)(&client->lock); =20 - spin_lock_irq(&client->lock); - ret =3D idr_for_each(&client->resource_idr, - is_outbound_transaction_resource, NULL); - spin_unlock_irq(&client->lock); - - return ret; + return idr_for_each(&client->resource_idr, is_outbound_transaction_resour= ce, NULL); } =20 static int shutdown_resource(int id, void *p, void *data) --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 49EEF137750 for ; Sun, 4 Aug 2024 13:02:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776566; cv=none; b=H1bdkeB8Pr8xMMrSNNg7SJrut2IZbFFUBimidUO+7CDKIkxZyAH3RGvG5E0sVLYvFBVCidnPWcZsABWz8LcaFR67C6FA9cefUhtywCJDqcs15X0KH2NLRwQ1DBCeeuOIbn3q8m4gRrPn+VzaZA/Zb3vySoz1vAHmqnwDHUGTt7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776566; c=relaxed/simple; bh=50aZcCKLJeunfclbsZ1zlynb/h3MqzlmknN/YhwoRVM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iknv/SE72vUPL1O4gPaXCl3o5YXqy2yzWk4C5/oY4D3whQfWfONW9x5LDZF6KFIIJsR1tZCcHYwsDsRps1vUfoaglZjNWzTWY04DMvFzx/JZHkJng8n4czqGO+kcnKGmaTNavEJ2rtaC3dFm/6o983PiAFJu4ZdSopWluY4REgU= 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=m1VxmdCp; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RCRizvaM; arc=none smtp.client-ip=103.168.172.146 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="m1VxmdCp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RCRizvaM" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 5A54C1388033; Sun, 4 Aug 2024 09:02:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 04 Aug 2024 09:02:44 -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=1722776564; x= 1722862964; bh=CAposS/X5iD+uiuVXyMO8x9mAy4UkjQlQ0BVV7Nspq0=; b=m 1VxmdCpR5B92ufIdj30S9Vp5Vp1uDmMXYuxzOQGsq2nPpcscHeRjmJ6ull63MvwY q+j/wgCU263ClEi+B/Y13eSrAIeq4vO/1bUBjt8/bL32T8BTF+U1/9eN0NGPeaZi lov3HfIuU2Fh4AkDkhIJWvI/ic1M6oeM1F4Q9pZAApW/nmbi5kGlF1zmxJPqS0Jw GF3twUGPao7pUqJ9eH0tAMCHzwWtlLTd3IZK+Jdy3NkjrSB/WWExMlUJK3mtnp9J VXJEh0D3u49VS4xcJZQemHzSqH6ZFkTyjDxkl8zY28/MDE+1bNjnpadtqhGBL4sS GXa/ERDhxdeIqS6YjyXYQ== 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=1722776564; x= 1722862964; bh=CAposS/X5iD+uiuVXyMO8x9mAy4UkjQlQ0BVV7Nspq0=; b=R CRizvaMLeFGcShVXHNZWTW+0DXkUQbKv/tkOnZL7mLYx9lE/3zyR+hHzbsK6tVv0 P9dhJOLXFkAaKg3Yct512qbMvrJD59GL5cR+gkGiVuopTRqflJTeKBOmOO8c0th0 PvhJ5kai5haN3CeH71cBW/ootmLYT7SMFgHzQQprRz9bofGTkbutqaN/TcMgaw5V eIRg4yU4Sbma+HlYyExRrEVwJm/As0NG0p+awti8MP0X+DCls0NYdZgPU4Y/vl+n tZMTD0eEzcEUnL8GJ8JQS30poNs59iPlc/swOfTnXO9NPTK7yjPdB7JDBzqxQmVe XRXF4p3Li1UG74n4qUtLw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:43 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 11/17] firewire: core: use guard macro to maintain isochronous context for userspace client Date: Sun, 4 Aug 2024 22:02:18 +0900 Message-ID: <20240804130225.243496-12-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function allows one isochronous contexts per userspace client. The concurrent access to the context is protected by spinlock in the instance of client. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index c2d24cc5c1f1..ac6f9ad9e88e 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -1062,10 +1062,10 @@ static int ioctl_create_iso_context(struct client *= client, union ioctl_arg *arg) if (client->version < FW_CDEV_VERSION_AUTO_FLUSH_ISO_OVERFLOW) context->drop_overflow_headers =3D true; =20 - /* We only support one context at this time. */ - spin_lock_irq(&client->lock); + // We only support one context at this time. + guard(spinlock_irq)(&client->lock); + if (client->iso_context !=3D NULL) { - spin_unlock_irq(&client->lock); fw_iso_context_destroy(context); =20 return -EBUSY; @@ -1075,7 +1075,6 @@ static int ioctl_create_iso_context(struct client *cl= ient, union ioctl_arg *arg) client->device->card, iso_dma_direction(context)); if (ret < 0) { - spin_unlock_irq(&client->lock); fw_iso_context_destroy(context); =20 return ret; @@ -1084,7 +1083,6 @@ static int ioctl_create_iso_context(struct client *cl= ient, union ioctl_arg *arg) } client->iso_closure =3D a->closure; client->iso_context =3D context; - spin_unlock_irq(&client->lock); =20 a->handle =3D 0; =20 @@ -1806,16 +1804,15 @@ static int fw_device_op_mmap(struct file *file, str= uct vm_area_struct *vma) if (ret < 0) return ret; =20 - spin_lock_irq(&client->lock); - if (client->iso_context) { - ret =3D fw_iso_buffer_map_dma(&client->buffer, - client->device->card, - iso_dma_direction(client->iso_context)); - client->buffer_is_mapped =3D (ret =3D=3D 0); + scoped_guard(spinlock_irq, &client->lock) { + if (client->iso_context) { + ret =3D fw_iso_buffer_map_dma(&client->buffer, client->device->card, + iso_dma_direction(client->iso_context)); + if (ret < 0) + goto fail; + client->buffer_is_mapped =3D true; + } } - spin_unlock_irq(&client->lock); - if (ret < 0) - goto fail; =20 ret =3D vm_map_pages_zero(vma, client->buffer.pages, client->buffer.page_count); --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 6B0A1139D00 for ; Sun, 4 Aug 2024 13:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776567; cv=none; b=ADnEC+wrLNOVbonai02OdDYMhXbMqfKw5zmIuhihpdogtQpq4zCOzVgm6KCGF8YJWhdNe3AcmywYY2N5c9xXZ5nfzvBzJJU+s43jkRLgJWstyBElor6DG0eJMHr8uBoEVRg2g1b4G+jX30/NMcf2k+/yegZxsTjxRRAaHSbAKFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776567; c=relaxed/simple; bh=byjeyaU0KCacHc1trU6Nd+xN8T9yKFSqZfE68WM9laI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jgy1QYFXKLcegXQMeQtNyABGz7oStpVCDX68Xz6w189VxN8ycREBUkdZ4k73ni9QeCw68SA+CvfBTiLv4foIuhvZQmrUkib8XfDD2drjMTmNIukS6pOPchlE1IT+9NK+4HuS5RzLQlEmvLIcjjE4JWQg5b5QMaXh/wC1hqju+U4= 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=z5gvarZW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bVxsJfQV; arc=none smtp.client-ip=103.168.172.146 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="z5gvarZW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bVxsJfQV" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 9FE011388027; Sun, 4 Aug 2024 09:02:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 04 Aug 2024 09:02:45 -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=1722776565; x= 1722862965; bh=p2/8Uhv2yJT1ffx5iSM4w272zr0fR0S1Kk6bKcSHexE=; b=z 5gvarZWqQrNiNMIo/CN1xbPcW5e+Nof6TdwEmjGNaGubH+PBYOfGMupzl/wkhUPz FbOGdR99Xa+oHlU2ht9dCkubTBZUTwoKR0qUpNfE86qSAPN5rLhqek7VPhlvOYeV ggdXepP04nnJ5FKgGBB4rE7U3gCeujoVXEOiI2WyI6F7k5z3s4nUrKoGtWZRtfJu lx86VSQO4GKtM8zhFvk35kaKZGAsVkaP6yX1J+X4B1MSS8T5ybVmRJnO7erkbf0z d5iF84buqWABw6ZIz8CZb8L/yDFQACtl6KrglcJ3M6e0IuADm9keIdJZ2gA7nfN7 9C0kLOhEvtgS5m8TgCirw== 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=1722776565; x= 1722862965; bh=p2/8Uhv2yJT1ffx5iSM4w272zr0fR0S1Kk6bKcSHexE=; b=b VxsJfQV5eZWeCL+YAhRC6p3WLoJx8ca8F/n/HSlFbrDmazLpKA6pb/Smsxt0SZ+l J5JsR2+F4fBegC/ZWpEjU0hW7BXGUVj0iidjPlu/ljLeubTXiRgzPP5XsMnVvFOZ 3vLNurdKW+1HBP68TA34C3dFJ1wHKHSDLeONjKOPdSPI15U4o1N8d/GSSxmZnCzM VUPIW1UhlHtx3+3F942rcgIJY4wXTKPIm/HoaA/OAk0Oq3k0YQbewah4HuB7QVhG auuGweGuCcOjfeIcoXVom+Q/XJFhLegkkUIfe0h3kI/NZRAjwBuSebHR6UKlam9G e/z61NRnnYhW7ePBCARMQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:44 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 12/17] firewire: core: use guard macro to maintain list of receivers for phy configuration packets Date: Sun, 4 Aug 2024 22:02:19 +0900 Message-ID: <20240804130225.243496-13-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function maintains clients to receive phy configuration packets by list in the instance of fw_card. The concurrent access to the list is protected by spinlock in the instance. This commit uses guard macro to maintain the list. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index ac6f9ad9e88e..f32f8667ef2c 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -1659,26 +1659,22 @@ static int ioctl_receive_phy_packets(struct client = *client, union ioctl_arg *arg if (!client->device->is_local) return -ENOSYS; =20 - spin_lock_irq(&card->lock); + guard(spinlock_irq)(&card->lock); =20 list_move_tail(&client->phy_receiver_link, &card->phy_receiver_list); client->phy_receiver_closure =3D a->closure; =20 - spin_unlock_irq(&card->lock); - return 0; } =20 void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p) { struct client *client; - struct inbound_phy_packet_event *e; - unsigned long flags; =20 - spin_lock_irqsave(&card->lock, flags); + guard(spinlock_irqsave)(&card->lock); =20 list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { - e =3D kmalloc(sizeof(*e) + 8, GFP_ATOMIC); + struct inbound_phy_packet_event *e =3D kmalloc(sizeof(*e) + 8, GFP_ATOMI= C); if (e =3D=3D NULL) break; =20 @@ -1706,8 +1702,6 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, = struct fw_packet *p) queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0= ); } } - - spin_unlock_irqrestore(&card->lock, flags); } =20 static int (* const ioctl_handlers[])(struct client *, union ioctl_arg *) = =3D { @@ -1855,9 +1849,8 @@ static int fw_device_op_release(struct inode *inode, = struct file *file) struct client *client =3D file->private_data; struct event *event, *next_event; =20 - spin_lock_irq(&client->device->card->lock); - list_del(&client->phy_receiver_link); - spin_unlock_irq(&client->device->card->lock); + scoped_guard(spinlock_irq, &client->device->card->lock) + list_del(&client->phy_receiver_link); =20 scoped_guard(mutex, &client->device->client_list_mutex) list_del(&client->link); --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 B33BD1386D8 for ; Sun, 4 Aug 2024 13:02:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776569; cv=none; b=nHg7AdHD/jNhbPsc8G9rPHbEezii7C78QfzvYPNx8TFjLAYOTT7kdMPdEgs8W7RJ5FkQtiuTXTNFZ4IOUrkJMCLrJI9iHwDajQlfku25FnQ/M2SJfjfSUFG8hUMU36A0vBsz5vCeAHdMjdFTGapNcOqDFtHf3rP4DihNMPFOHQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776569; c=relaxed/simple; bh=49GxbGlyfanU/y+/2A/yh+GRQDGyrxQpzb/j493tJX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nd9MjmZzwFW9VTYwOTltKcAI7JqqGps6gZt0eEkbcMh9YnKqoElqSlyYh3Ry+G+GlCSNhr5Jl7TuOzmuzJDX0dxGTI6mgTRhYHQOdALzf8/Vy++QegJuoH8aLzotJr6zMrLZY1MeOw13kSwngPY2T82fcwwoR0zHUD7yVw3zlBo= 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=Tnd5eC+R; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PkR2XVIF; arc=none smtp.client-ip=103.168.172.159 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="Tnd5eC+R"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PkR2XVIF" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EEB471147EEC; Sun, 4 Aug 2024 09:02:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 04 Aug 2024 09:02:46 -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=1722776566; x= 1722862966; bh=g2ZYQpdmVR2Qgn3ioWPYVE8uCIbn3OBt2eoIeM+wq4M=; b=T nd5eC+Rb8fuBOlh0O1ynU4gSoXL7iS0VicHZjA4YzmPCbEAO/YAKPgnrpyzvK93H bzPTF/j57xKacc4vn/RdlFDbf+jG1U8QEh9VGr4Yi/B9sW2bhkeiqHfluiNFfaw8 Yh89EHJvUWHYhGXYrmzinrVMefk11OBuG2Gw7lcrhEWd/KmIbBWneM+gDIGB18WK CjbJNbPVzeQ19rEw/XzGEkzroMj5BljaqrPuIOQMeeRPNB4uJ9gYXdA24Ls+EjAV wmiHmwqxu+PTI8F6io0dTMK6OSyBIl6cyH6RJ12JQAnqsJJIWrDslV5xrJd1nPEy 92c87GJdwAuk+8lVSIKqA== 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=1722776566; x= 1722862966; bh=g2ZYQpdmVR2Qgn3ioWPYVE8uCIbn3OBt2eoIeM+wq4M=; b=P kR2XVIFBD5HNS1hL3MB0ROi2Ylab6TbrXzWpMDyhZN1Xo5i6KIk4vqQd7MelGpuO x3mUcs5VYvBoElsLJLI1MK1NyZliisSYtF5vKfnzJxdIQicUIWHOluSHPdnPeCzM mPclUg6+NM4EPtf7RurLHpMkM9OVUocUTybzKvZ1884/DOi0PG4LPE7gWqiLKS+Q 4JEeQNq8TVKUswcDtGUDT6vUifjM3Ek1OUxfquFti21mtBw03P1Px3WMbL+1zmUK fjkTvSOvwKopV4GXxg1M+lk1W597zFtUEY8Obwg6bAw22P+EOWclSWqU45rSJZq6 +wUoqEU0tARQXgUurwjvQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:45 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 13/17] firewire: core: use guard macro to maintain list of asynchronous transaction Date: Sun, 4 Aug 2024 22:02:20 +0900 Message-ID: <20240804130225.243496-14-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core function maintains pending asynchronous transactions by list in the instance of fw_card. The concurrent access to the list is protected by spinlock in the instance. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-transaction.c | 85 ++++++++++++----------------- 1 file changed, 34 insertions(+), 51 deletions(-) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index a006daf385e9..0f58a5d13d28 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -49,35 +49,31 @@ static int close_transaction(struct fw_transaction *tra= nsaction, struct fw_card u32 response_tstamp) { struct fw_transaction *t =3D NULL, *iter; - unsigned long flags; =20 - spin_lock_irqsave(&card->lock, flags); - list_for_each_entry(iter, &card->transaction_list, link) { - if (iter =3D=3D transaction) { - if (!try_cancel_split_timeout(iter)) { - spin_unlock_irqrestore(&card->lock, flags); - goto timed_out; + scoped_guard(spinlock_irqsave, &card->lock) { + list_for_each_entry(iter, &card->transaction_list, link) { + if (iter =3D=3D transaction) { + if (try_cancel_split_timeout(iter)) { + list_del_init(&iter->link); + card->tlabel_mask &=3D ~(1ULL << iter->tlabel); + t =3D iter; + } + break; } - list_del_init(&iter->link); - card->tlabel_mask &=3D ~(1ULL << iter->tlabel); - t =3D iter; - break; } } - spin_unlock_irqrestore(&card->lock, flags); =20 - if (t) { - if (!t->with_tstamp) { - t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data); - } else { - t->callback.with_tstamp(card, rcode, t->packet.timestamp, response_tsta= mp, - NULL, 0, t->callback_data); - } - return 0; + if (!t) + return -ENOENT; + + if (!t->with_tstamp) { + t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data); + } else { + t->callback.with_tstamp(card, rcode, t->packet.timestamp, response_tstam= p, NULL, 0, + t->callback_data); } =20 - timed_out: - return -ENOENT; + return 0; } =20 /* @@ -121,16 +117,13 @@ static void split_transaction_timeout_callback(struct= timer_list *timer) { struct fw_transaction *t =3D from_timer(t, timer, split_timeout_timer); struct fw_card *card =3D t->card; - unsigned long flags; =20 - spin_lock_irqsave(&card->lock, flags); - if (list_empty(&t->link)) { - spin_unlock_irqrestore(&card->lock, flags); - return; + scoped_guard(spinlock_irqsave, &card->lock) { + if (list_empty(&t->link)) + return; + list_del(&t->link); + card->tlabel_mask &=3D ~(1ULL << t->tlabel); } - list_del(&t->link); - card->tlabel_mask &=3D ~(1ULL << t->tlabel); - spin_unlock_irqrestore(&card->lock, flags); =20 if (!t->with_tstamp) { t->callback.without_tstamp(card, RCODE_CANCELLED, NULL, 0, t->callback_d= ata); @@ -143,20 +136,14 @@ static void split_transaction_timeout_callback(struct= timer_list *timer) static void start_split_transaction_timeout(struct fw_transaction *t, struct fw_card *card) { - unsigned long flags; + guard(spinlock_irqsave)(&card->lock); =20 - spin_lock_irqsave(&card->lock, flags); - - if (list_empty(&t->link) || WARN_ON(t->is_split_transaction)) { - spin_unlock_irqrestore(&card->lock, flags); + if (list_empty(&t->link) || WARN_ON(t->is_split_transaction)) return; - } =20 t->is_split_transaction =3D true; mod_timer(&t->split_timeout_timer, jiffies + card->split_timeout_jiffies); - - spin_unlock_irqrestore(&card->lock, flags); } =20 static u32 compute_split_timeout_timestamp(struct fw_card *card, u32 reque= st_timestamp); @@ -1015,7 +1002,6 @@ EXPORT_SYMBOL(fw_core_handle_request); void fw_core_handle_response(struct fw_card *card, struct fw_packet *p) { struct fw_transaction *t =3D NULL, *iter; - unsigned long flags; u32 *data; size_t data_length; int tcode, tlabel, source, rcode; @@ -1054,26 +1040,23 @@ void fw_core_handle_response(struct fw_card *card, = struct fw_packet *p) break; } =20 - spin_lock_irqsave(&card->lock, flags); - list_for_each_entry(iter, &card->transaction_list, link) { - if (iter->node_id =3D=3D source && iter->tlabel =3D=3D tlabel) { - if (!try_cancel_split_timeout(iter)) { - spin_unlock_irqrestore(&card->lock, flags); - goto timed_out; + scoped_guard(spinlock_irqsave, &card->lock) { + list_for_each_entry(iter, &card->transaction_list, link) { + if (iter->node_id =3D=3D source && iter->tlabel =3D=3D tlabel) { + if (try_cancel_split_timeout(iter)) { + list_del_init(&iter->link); + card->tlabel_mask &=3D ~(1ULL << iter->tlabel); + t =3D iter; + } + break; } - list_del_init(&iter->link); - card->tlabel_mask &=3D ~(1ULL << iter->tlabel); - t =3D iter; - break; } } - spin_unlock_irqrestore(&card->lock, flags); =20 trace_async_response_inbound((uintptr_t)t, card->index, p->generation, p-= >speed, p->ack, p->timestamp, p->header, data, data_length / 4); =20 if (!t) { - timed_out: fw_notice(card, "unsolicited response (source %x, tlabel %x)\n", source, tlabel); return; --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 0ACF313AA2E for ; Sun, 4 Aug 2024 13:02:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776570; cv=none; b=f7rrey2iJkKv1WRzSjMBB6dzCvdtFbxQLIpV/VT9fTjnYrBsCsEvFNkLVeOcAuzDWC0wAocGWKzHoFXrT25NqkWc6D3ux4H+BqT/Ai8bvYdXLFT9oSS4fhT0il1lqAAMAex8IeAnFEb5nO1Ihq/pLfj2iAU3R5+fIDIGn73mlLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776570; c=relaxed/simple; bh=VkOGpKEZJl+vIZAQe3yTz+MuuquZjfY8NHLB4zRcw+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JoN5UqNrJWCnM7odGvs3b9Dl2WRa9wr28moTU1YGEw+eUfoM9wUcbEnELg9OXKHt7e+Va+XbTEWcOpH13GwY33JRUArUxtqQ/oKz+ey3iEFhTV08dk/NP2AV0noUmUVZUDm+VDIkK2HtKCLDJkJO5f0XlSb4vS+i7gfAJ72CPDE= 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=vr4QYuo/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Mr9ObnPK; arc=none smtp.client-ip=103.168.172.146 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="vr4QYuo/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Mr9ObnPK" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 57F7E1388026; Sun, 4 Aug 2024 09:02:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Sun, 04 Aug 2024 09:02:48 -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=1722776568; x= 1722862968; bh=2M63XuIcnOs2zgB0Of1R5tPvEt2hh1y3Apg8Rw8WgRE=; b=v r4QYuo/mZW3tKT4BcN5A0rRhyi3MD7iAXgq5bhzO0h3l5AGZRFk0paDaLM2ys7l7 ptwNLntIsSKfrqAh1POu/EhrqHeaYQB24tu/Ls8Ny8kSGz6O2xh+rV30qk36Bj/G JcP3O+vCiiuaK9W5pQv5uXjVb7mvrzN02t7lr4xuug/L3Ff8ZqmKsjyegg1kBVZ4 nAYpABlRXFolZuAIzrQFKelb+g3s5CXiVWYTvdVAzFnlPmLGYYA8b2RM5uQ4BOgl 4SchO/ni5a61FTopW2iWFTYRymlTOkfeOFfra1UdBtJpe9GBwhJae1dvMOslJXDt JWSXuALv5fCHVfTbwjSBg== 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=1722776568; x= 1722862968; bh=2M63XuIcnOs2zgB0Of1R5tPvEt2hh1y3Apg8Rw8WgRE=; b=M r9ObnPKEzJvA2JW/frTYrRHKYohvNxw4iwKIrbQkV4Jc4W8yXimxPnE52/i5iLor HP6Oi6HyWmW18owp2SeCtlNpIxB2eGtekagkkqd+eIi4WOpuHsC3WXIAQa0luTp7 GtOTT7x+aN2irVX++KJBmbg8znR31o0IRlC3NfX5KHJ7PYHqeR9e6ca9BhEurnYj xvNJBdhpajXG4yrfZSEx2J0f5TWxKw/rYhwNnTPYVaGYVC/fVXumxIF9AAFWCLcS hZuvdtA2L26tnHd2QM6XBJN4HksVtn4ISpJjoyh/LkJjYLuVFWAtlT2oDX05OSzO JSIQo+1TO0E+w58C57n8A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:47 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 14/17] firewire: core: use guard macro to maintain properties of fw_card Date: Sun, 4 Aug 2024 22:02:21 +0900 Message-ID: <20240804130225.243496-15-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 core functions uses spinlock in instance of fw_card structure to protect concurrent access to properties in the instance. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-card.c | 16 +++++++--------- drivers/firewire/core-cdev.c | 4 +--- drivers/firewire/core-device.c | 10 +++------- drivers/firewire/core-iso.c | 5 ++--- drivers/firewire/core-topology.c | 5 +---- drivers/firewire/core-transaction.c | 12 +++++------- 6 files changed, 19 insertions(+), 33 deletions(-) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index 79a5b19e9d18..e80b762888fa 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -374,11 +374,11 @@ static void bm_work(struct work_struct *work) =20 bm_id =3D be32_to_cpu(transaction_data[0]); =20 - spin_lock_irq(&card->lock); - if (rcode =3D=3D RCODE_COMPLETE && generation =3D=3D card->generation) - card->bm_node_id =3D - bm_id =3D=3D 0x3f ? local_id : 0xffc0 | bm_id; - spin_unlock_irq(&card->lock); + scoped_guard(spinlock_irq, &card->lock) { + if (rcode =3D=3D RCODE_COMPLETE && generation =3D=3D card->generation) + card->bm_node_id =3D + bm_id =3D=3D 0x3f ? local_id : 0xffc0 | bm_id; + } =20 if (rcode =3D=3D RCODE_COMPLETE && bm_id !=3D 0x3f) { /* Somebody else is BM. Only act as IRM. */ @@ -707,7 +707,6 @@ EXPORT_SYMBOL_GPL(fw_card_release); void fw_core_remove_card(struct fw_card *card) { struct fw_card_driver dummy_driver =3D dummy_driver_template; - unsigned long flags; =20 card->driver->update_phy_reg(card, 4, PHY_LINK_ACTIVE | PHY_CONTENDER, 0); @@ -721,9 +720,8 @@ void fw_core_remove_card(struct fw_card *card) dummy_driver.stop_iso =3D card->driver->stop_iso; card->driver =3D &dummy_driver; =20 - spin_lock_irqsave(&card->lock, flags); - fw_destroy_nodes(card); - spin_unlock_irqrestore(&card->lock, flags); + scoped_guard(spinlock_irqsave, &card->lock) + fw_destroy_nodes(card); =20 /* Wait for all users, especially device workqueue jobs, to finish. */ fw_card_put(card); diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index f32f8667ef2c..672a37fa8343 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -354,7 +354,7 @@ static void fill_bus_reset_event(struct fw_cdev_event_b= us_reset *event, { struct fw_card *card =3D client->device->card; =20 - spin_lock_irq(&card->lock); + guard(spinlock_irq)(&card->lock); =20 event->closure =3D client->bus_reset_closure; event->type =3D FW_CDEV_EVENT_BUS_RESET; @@ -364,8 +364,6 @@ static void fill_bus_reset_event(struct fw_cdev_event_b= us_reset *event, event->bm_node_id =3D card->bm_node_id; event->irm_node_id =3D card->irm_node->node_id; event->root_node_id =3D card->root_node->node_id; - - spin_unlock_irq(&card->lock); } =20 static void for_each_client(struct fw_device *device, diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index d695ec2f1efe..bec7e05f6ab8 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c @@ -886,16 +886,14 @@ static void fw_device_release(struct device *dev) { struct fw_device *device =3D fw_device(dev); struct fw_card *card =3D device->card; - unsigned long flags; =20 /* * Take the card lock so we don't set this to NULL while a * FW_NODE_UPDATED callback is being handled or while the * bus manager work looks at this node. */ - spin_lock_irqsave(&card->lock, flags); - device->node->data =3D NULL; - spin_unlock_irqrestore(&card->lock, flags); + scoped_guard(spinlock_irqsave, &card->lock) + device->node->data =3D NULL; =20 fw_node_put(device->node); kfree(device->config_rom); @@ -952,7 +950,7 @@ static int lookup_existing_device(struct device *dev, v= oid *data) return 0; =20 guard(rwsem_read)(&fw_device_rwsem); // serialize config_rom access - spin_lock_irq(&card->lock); /* serialize node access */ + guard(spinlock_irq)(&card->lock); // serialize node access =20 if (memcmp(old->config_rom, new->config_rom, 6 * 4) =3D=3D 0 && atomic_cmpxchg(&old->state, @@ -982,8 +980,6 @@ static int lookup_existing_device(struct device *dev, v= oid *data) match =3D 1; } =20 - spin_unlock_irq(&card->lock); - return match; } =20 diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c index b3eda38a36f3..101433b8bb51 100644 --- a/drivers/firewire/core-iso.c +++ b/drivers/firewire/core-iso.c @@ -375,9 +375,8 @@ void fw_iso_resource_manage(struct fw_card *card, int g= eneration, u32 channels_lo =3D channels_mask >> 32; /* channels 63...32 */ int irm_id, ret, c =3D -EINVAL; =20 - spin_lock_irq(&card->lock); - irm_id =3D card->irm_node->node_id; - spin_unlock_irq(&card->lock); + scoped_guard(spinlock_irq, &card->lock) + irm_id =3D card->irm_node->node_id; =20 if (channels_hi) c =3D manage_channel(card, irm_id, generation, channels_hi, diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topol= ogy.c index 46e6eb287d24..6adadb11962e 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c @@ -455,11 +455,10 @@ void fw_core_handle_bus_reset(struct fw_card *card, i= nt node_id, int generation, int self_id_count, u32 *self_ids, bool bm_abdicate) { struct fw_node *local_node; - unsigned long flags; =20 trace_bus_reset_handle(card->index, generation, node_id, bm_abdicate, sel= f_ids, self_id_count); =20 - spin_lock_irqsave(&card->lock, flags); + guard(spinlock_irqsave)(&card->lock); =20 /* * If the selfID buffer is not the immediate successor of the @@ -500,7 +499,5 @@ void fw_core_handle_bus_reset(struct fw_card *card, int= node_id, int generation, } else { update_tree(card, local_node); } - - spin_unlock_irqrestore(&card->lock, flags); } EXPORT_SYMBOL(fw_core_handle_bus_reset); diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-tr= ansaction.c index 0f58a5d13d28..14af84541e83 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -1160,7 +1160,6 @@ static void handle_registers(struct fw_card *card, st= ruct fw_request *request, int reg =3D offset & ~CSR_REGISTER_BASE; __be32 *data =3D payload; int rcode =3D RCODE_COMPLETE; - unsigned long flags; =20 switch (reg) { case CSR_PRIORITY_BUDGET: @@ -1202,10 +1201,10 @@ static void handle_registers(struct fw_card *card, = struct fw_request *request, if (tcode =3D=3D TCODE_READ_QUADLET_REQUEST) { *data =3D cpu_to_be32(card->split_timeout_hi); } else if (tcode =3D=3D TCODE_WRITE_QUADLET_REQUEST) { - spin_lock_irqsave(&card->lock, flags); + guard(spinlock_irqsave)(&card->lock); + card->split_timeout_hi =3D be32_to_cpu(*data) & 7; update_split_timeout(card); - spin_unlock_irqrestore(&card->lock, flags); } else { rcode =3D RCODE_TYPE_ERROR; } @@ -1215,11 +1214,10 @@ static void handle_registers(struct fw_card *card, = struct fw_request *request, if (tcode =3D=3D TCODE_READ_QUADLET_REQUEST) { *data =3D cpu_to_be32(card->split_timeout_lo); } else if (tcode =3D=3D TCODE_WRITE_QUADLET_REQUEST) { - spin_lock_irqsave(&card->lock, flags); - card->split_timeout_lo =3D - be32_to_cpu(*data) & 0xfff80000; + guard(spinlock_irqsave)(&card->lock); + + card->split_timeout_lo =3D be32_to_cpu(*data) & 0xfff80000; update_split_timeout(card); - spin_unlock_irqrestore(&card->lock, flags); } else { rcode =3D RCODE_TYPE_ERROR; } --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 95BF513B2A9 for ; Sun, 4 Aug 2024 13:02:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776572; cv=none; b=R1upaQ8uv5HzA0AEGRcZd/RR3bBHnkAoPW5HhKMb9LbWtNn2zSvxeiLvc11MDxIMfM27zqPKdvKvErrbWx3g83zBH7mHUIjw78f48Lf8tupzCRvej0QdYRx0rGkYHIKGWYyt9Ra20FTXvHP1vZ8nywZ2DdEgx0VHR0CEziomTHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776572; c=relaxed/simple; bh=SYjPXH2iD1U1cMCRf7nypmxIm+fUZop8Ce0hqIrOg30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kYrJJXoKD3EgoSjUt5wdfKHLe+UzPjUreVatioi0/uDSHd/EUcZ4tQWjcQ7hVk78ula8yJWmXREfRIJoX0TYGmDW4uCLQMuu7GbyTPU+PO+LGBr98TdAEkGgJ+GQur5wsZl8tXHfKruPnnEs+94CUjy86NC9IsaaRtmjhlVvPww= 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=KtvtMoTc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kEOTm/Uh; arc=none smtp.client-ip=103.168.172.159 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="KtvtMoTc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kEOTm/Uh" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A6259114814F; Sun, 4 Aug 2024 09:02:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 04 Aug 2024 09:02:49 -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=1722776569; x= 1722862969; bh=bU5KUiELPtrWttit1O/f/6nD4P98n+MP8Do0wq0HKos=; b=K tvtMoTcmx5jSUiz10zOZ0vgMH/H0UGOgxo/4kx8kArjArkdqZDjuDjVyxFK5AuM0 bt4uKKg08zH1uGCcPFAyEedGtnKV1ZIk4YPQMtzHdYnODuzAxUSk8+f7ZCDp0Ey2 RoMpZFb6jej80tpRpUWWVnB3XP7YAhiyHtosqnkF6mYL7YbCgutPbdKKkwelfuY+ G0g9wfmjhN9DTAsgQuRYA18Td+fpVeiz8jNctJ+Fc1jbTrLXPtFvopk/za/R42G5 nEstd4Vfol7UM7Q071PIcCQW0rCCf2R/Iyg1/ipDbWY2sjDbqaI+sad8UaoY26JJ dmZ+r86P6IluKyf2xU3NA== 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=1722776569; x= 1722862969; bh=bU5KUiELPtrWttit1O/f/6nD4P98n+MP8Do0wq0HKos=; b=k EOTm/UhtajSp8x0G807qlS6XiRnrqervBMh0oBatOketmDqjYfQHhnipGGabLbT+ /g1w+f6d3wZTgt0aV7q8FPRxE3qBOQpiR9J1eknZbNcx0hxCN47gpZ6VnlaMoFqL 5FFY3i7YwAxnKzyQWAcLKovG0Go9XnSG42O/GxWAqKE1UktW+JyIJPjVZorO1nul cu6W6uukLfUgK6pZaoGqM7pm0iqoj1p+LklgXaSwpPCnndt9KcvxHub3jqZ1q+p1 AvrdGr3kZ6+b4m+E09QjfpnH+5e9gslaQ5Xs/kex0UdHaQbDpJmapJIULLmmJ1C7 KLwEWtNGV+lufLtDY+Teg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:48 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 15/17] firewire: ohci: use guard macro to maintain bus time Date: Sun, 4 Aug 2024 22:02:22 +0900 Message-ID: <20240804130225.243496-16-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 maintains bus time to respond to querying request. The concurrent access to the bus time is protected by spinlock. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 1461e008d265..5cb7c7603c2c 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -2300,9 +2300,8 @@ static irqreturn_t irq_handler(int irq, void *data) handle_dead_contexts(ohci); =20 if (event & OHCI1394_cycle64Seconds) { - spin_lock(&ohci->lock); + guard(spinlock)(&ohci->lock); update_bus_time(ohci); - spin_unlock(&ohci->lock); } else flush_writes(ohci); =20 @@ -2762,7 +2761,6 @@ static int ohci_enable_phys_dma(struct fw_card *card, static u32 ohci_read_csr(struct fw_card *card, int csr_offset) { struct fw_ohci *ohci =3D fw_ohci(card); - unsigned long flags; u32 value; =20 switch (csr_offset) { @@ -2786,16 +2784,14 @@ static u32 ohci_read_csr(struct fw_card *card, int = csr_offset) return get_cycle_time(ohci); =20 case CSR_BUS_TIME: - /* - * We might be called just after the cycle timer has wrapped - * around but just before the cycle64Seconds handler, so we - * better check here, too, if the bus time needs to be updated. - */ - spin_lock_irqsave(&ohci->lock, flags); - value =3D update_bus_time(ohci); - spin_unlock_irqrestore(&ohci->lock, flags); - return value; + { + // We might be called just after the cycle timer has wrapped around but = just before + // the cycle64Seconds handler, so we better check here, too, if the bus = time needs + // to be updated. =20 + guard(spinlock_irqsave)(&ohci->lock); + return update_bus_time(ohci); + } case CSR_BUSY_TIMEOUT: value =3D reg_read(ohci, OHCI1394_ATRetries); return (value >> 4) & 0x0ffff00f; @@ -2813,7 +2809,6 @@ static u32 ohci_read_csr(struct fw_card *card, int cs= r_offset) static void ohci_write_csr(struct fw_card *card, int csr_offset, u32 value) { struct fw_ohci *ohci =3D fw_ohci(card); - unsigned long flags; =20 switch (csr_offset) { case CSR_STATE_CLEAR: @@ -2849,12 +2844,11 @@ static void ohci_write_csr(struct fw_card *card, in= t csr_offset, u32 value) break; =20 case CSR_BUS_TIME: - spin_lock_irqsave(&ohci->lock, flags); - ohci->bus_time =3D (update_bus_time(ohci) & 0x40) | - (value & ~0x7f); - spin_unlock_irqrestore(&ohci->lock, flags); + { + guard(spinlock_irqsave)(&ohci->lock); + ohci->bus_time =3D (update_bus_time(ohci) & 0x40) | (value & ~0x7f); break; - + } case CSR_BUSY_TIMEOUT: value =3D (value & 0xf) | ((value & 0xf) << 4) | ((value & 0xf) << 8) | ((value & 0x0ffff000) << 4); --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 BDDCD13B787 for ; Sun, 4 Aug 2024 13:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776573; cv=none; b=PD+rgWYge/923UjeqyVOTbI9X8fZpFCH3Brl1pEUYMWCcRWQuhYHYDJyzEXza82i8SZV7q3Xt0CxJrsoQezlgJ6ZWBDXVvEYpOI4fwH+a60GQxqxfK/c9va1t2RKl8nsMuSPUGWSH2o6I2x6R0G9u4b0yW/+MvOzhe+IvvQs9o0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776573; c=relaxed/simple; bh=RQbpBuuhcdVRrS45TXow3FvE3qGBFt8WbWvDlTvxDVc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MyDVPxH5GzIlw7cjhWOBTuG/ZurCt2N9KtjqCQAk9DZwOFCBqoS5qIw94SJP0R0Izbu4hqgiRGwBUd+h1NN789OWsvHJ6EpZ6PHSvxtTuW9mrR8+ZF6WdpK5U/AsYMvmShhWgdDFjtcntkSvzl4aUx+lBNDvx3sCz0QC6aOHwnQ= 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=sWfOarf8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uL3z1km6; arc=none smtp.client-ip=103.168.172.146 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="sWfOarf8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uL3z1km6" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 024DE138801E; Sun, 4 Aug 2024 09:02:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 04 Aug 2024 09:02:51 -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=1722776570; x= 1722862970; bh=oi4YF8S7QF5qtDuzwiUeYwReqaCDQcNumgOf6dEv5Us=; b=s WfOarf8pTTKkWEaVKu9pBTPICmfeNPNQnHPFPAPxY59lVmI7drnRcn3xXWqROPOy Twjb2bZaA2ID1VT7mgY7KLivKERvAEfryrJEN6pC9LCbRrUog8j9Jz9HfoOaL8EB /iL0i3bBwfJhFrbpGARPzIWj46NOw+cEl3BFWOssGXEVjkZ+/Lm93cjgj56HF+go VdV3GTNAwxMz1eogwPpp5kyqpTy1+iquS+zzAPb7L630JLJVI6EqeK0fWeSRpjv/ 5S6s/lsxJwLOCv3ABTHtkjOugoKtfSpv9dzkqbNXUrNu4CfdHBr6vxOMHIun34ri 9EZlzpRThpP0XjOhRg62A== 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=1722776570; x= 1722862970; bh=oi4YF8S7QF5qtDuzwiUeYwReqaCDQcNumgOf6dEv5Us=; b=u L3z1km6hJFFOgL1MWoUp39QyfdlPr9Z7RiOmeVd/b7bFrzJGD1AeGSfLWExezhg8 iiS4BwtMKwooNKvVJ1o4aSpeBRwJNmYXtX+GObrkWchGMi7rQrgBc1zJFBUZYOIH PlfSqd3YI+Cn8gryxZ8LpYtkHfweTvHe2ow/FVOYPuldgQQJHGzj4/AGoRfMvU41 hSIZDYsJEeevYAnyo9wxSN3Yk1oN6ypmlPtkznRVOtwFFIVmBX7DpU9lbYQKmm8f 1ZGcynn2cUl5T0M1L8CzHXfV6NIU7xNfYWkq1C1SBKIYOJ4OPmYMHYMeeEEZwAZE WZcxo6qfKfYHUYmna2h/A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:49 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 16/17] firewire: ohci: use guard macro to maintain image of configuration ROM Date: Sun, 4 Aug 2024 22:02:23 +0900 Message-ID: <20240804130225.243496-17-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 for the process to update local configuration ROM. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 116 +++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 67 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 5cb7c7603c2c..368420e4b414 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -2139,53 +2139,42 @@ static void bus_reset_work(struct work_struct *work) at_context_flush(&ohci->at_request_ctx); at_context_flush(&ohci->at_response_ctx); =20 - spin_lock_irq(&ohci->lock); - - ohci->generation =3D generation; - reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset); - reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset); - - if (ohci->quirks & QUIRK_RESET_PACKET) - ohci->request_generation =3D generation; - - /* - * This next bit is unrelated to the AT context stuff but we - * have to do it under the spinlock also. If a new config rom - * was set up before this reset, the old one is now no longer - * in use and we can free it. Update the config rom pointers - * to point to the current config rom and clear the - * next_config_rom pointer so a new update can take place. - */ - - if (ohci->next_config_rom !=3D NULL) { - if (ohci->next_config_rom !=3D ohci->config_rom) { - free_rom =3D ohci->config_rom; - free_rom_bus =3D ohci->config_rom_bus; + scoped_guard(spinlock_irq, &ohci->lock) { + ohci->generation =3D generation; + reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset); + reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset); + + if (ohci->quirks & QUIRK_RESET_PACKET) + ohci->request_generation =3D generation; + + // This next bit is unrelated to the AT context stuff but we have to do = it under the + // spinlock also. If a new config rom was set up before this reset, the = old one is + // now no longer in use and we can free it. Update the config rom pointe= rs to point + // to the current config rom and clear the next_config_rom pointer so a = new update + // can take place. + if (ohci->next_config_rom !=3D NULL) { + if (ohci->next_config_rom !=3D ohci->config_rom) { + free_rom =3D ohci->config_rom; + free_rom_bus =3D ohci->config_rom_bus; + } + ohci->config_rom =3D ohci->next_config_rom; + ohci->config_rom_bus =3D ohci->next_config_rom_bus; + ohci->next_config_rom =3D NULL; + + // Restore config_rom image and manually update config_rom registers. + // Writing the header quadlet will indicate that the config rom is read= y, + // so we do that last. + reg_write(ohci, OHCI1394_BusOptions, be32_to_cpu(ohci->config_rom[2])); + ohci->config_rom[0] =3D ohci->next_header; + reg_write(ohci, OHCI1394_ConfigROMhdr, be32_to_cpu(ohci->next_header)); } - ohci->config_rom =3D ohci->next_config_rom; - ohci->config_rom_bus =3D ohci->next_config_rom_bus; - ohci->next_config_rom =3D NULL; =20 - /* - * Restore config_rom image and manually update - * config_rom registers. Writing the header quadlet - * will indicate that the config rom is ready, so we - * do that last. - */ - reg_write(ohci, OHCI1394_BusOptions, - be32_to_cpu(ohci->config_rom[2])); - ohci->config_rom[0] =3D ohci->next_header; - reg_write(ohci, OHCI1394_ConfigROMhdr, - be32_to_cpu(ohci->next_header)); - } - - if (param_remote_dma) { - reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0); - reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0); + if (param_remote_dma) { + reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0); + reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0); + } } =20 - spin_unlock_irq(&ohci->lock); - if (free_rom) dmam_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, free_rom, free_ro= m_bus); =20 @@ -2626,33 +2615,26 @@ static int ohci_set_config_rom(struct fw_card *card, if (next_config_rom =3D=3D NULL) return -ENOMEM; =20 - spin_lock_irq(&ohci->lock); - - /* - * If there is not an already pending config_rom update, - * push our new allocation into the ohci->next_config_rom - * and then mark the local variable as null so that we - * won't deallocate the new buffer. - * - * OTOH, if there is a pending config_rom update, just - * use that buffer with the new config_rom data, and - * let this routine free the unused DMA allocation. - */ - - if (ohci->next_config_rom =3D=3D NULL) { - ohci->next_config_rom =3D next_config_rom; - ohci->next_config_rom_bus =3D next_config_rom_bus; - next_config_rom =3D NULL; - } + scoped_guard(spinlock_irq, &ohci->lock) { + // If there is not an already pending config_rom update, push our new al= location + // into the ohci->next_config_rom and then mark the local variable as nu= ll so that + // we won't deallocate the new buffer. + // + // OTOH, if there is a pending config_rom update, just use that buffer w= ith the new + // config_rom data, and let this routine free the unused DMA allocation. + if (ohci->next_config_rom =3D=3D NULL) { + ohci->next_config_rom =3D next_config_rom; + ohci->next_config_rom_bus =3D next_config_rom_bus; + next_config_rom =3D NULL; + } =20 - copy_config_rom(ohci->next_config_rom, config_rom, length); + copy_config_rom(ohci->next_config_rom, config_rom, length); =20 - ohci->next_header =3D config_rom[0]; - ohci->next_config_rom[0] =3D 0; + ohci->next_header =3D config_rom[0]; + ohci->next_config_rom[0] =3D 0; =20 - reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus); - - spin_unlock_irq(&ohci->lock); + reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus); + } =20 /* If we didn't use the DMA allocation, delete it. */ if (next_config_rom !=3D NULL) { --=20 2.43.0 From nobody Mon Feb 9 10:14:40 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 3BE8413C661 for ; Sun, 4 Aug 2024 13:02:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776574; cv=none; b=r2naN+wEapAQFkPMW6W6cjHu0WDwqHehe+uJn4m/UVFmXa9tbHrftU4msNIcn5DfUHxpOI5bYE9vKSBH2C0LaogCisDhlRIBx0U4ROtXz2Pda4eExhJqO7SQlC0T0VdZMznNFkE8mMJPGdVrHNVLKYIUD3GBNIFCtg17in4CbPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722776574; c=relaxed/simple; bh=QvOuD/5y8rCGroBROVtigY3efPBGAl1FYLFEGbesjng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VFOCVsclwGnfS/CmDsABtKA3koUynNSdjQDYVUQtctgBfDJMkBO/7F5+9BW+WyTNRp0MTEf84C1e3yT44thMFka09m9OAHa6jvVbkFUKtKvqSwpSVLx+boVB4BTLWltWtXdb6DMbu7+H0BFtIV6tXscxouv47j0U8I8iRNkluLg= 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=EWkCcxkd; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GGt8fz1f; arc=none smtp.client-ip=103.168.172.159 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="EWkCcxkd"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GGt8fz1f" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 6726A11481AC; Sun, 4 Aug 2024 09:02:52 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 04 Aug 2024 09:02:52 -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=1722776572; x= 1722862972; bh=ce1PvFpqfMZ6coYFn9GbZNurf1sO48K6AvhhScalZL0=; b=E WkCcxkdxBsvVGip1trnbama6KMLb54d8OWVoUzQnZXjrM4pO9xXTRIsxoToSky1I 3cDHtpZAjXsnNLVD+gVFZXhxe54w/mwWbyYky9IS6efd28nUBqdT+HHZdZSm1em/ OKb6+gO7jjskau+L3mbrWjBJdQ8+8Af3abbDEEl5/CFPtGfRi9X/md8Rbxr2EnJC S+CpEBnptBZ2ji5BwvgsRZ8O9qhF/bK/Yd1ZKwn/8sVo9i5xoOa3jqzS7AFKXuDu 2z/iaqLYMu0MDYkJlTUl7knduAQped1zM+fCmT+6c/8zm6svNmg2gx5s2EdrUtrx hIUmFgAh0z6Bl7l62UIRg== 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=1722776572; x= 1722862972; bh=ce1PvFpqfMZ6coYFn9GbZNurf1sO48K6AvhhScalZL0=; b=G Gt8fz1fAfLbK4x606Rw1ZAC+GazGslRtjrxccs4Qd4cQy7WjpQ2+qiwD5kHBijkS O6TMt0EWevU1pqJbK/OwyB4hw/iwUm9OZZAbvcddIga4uI4ql9FhiaSH5fcpPIbH 2/3HQv9yF4qjan2TtqRP+k9vrpFJ6ZvhjQAxHhP2gSOy3Em/zl9iRYTdp5FyYu0O VvLnZ2zUcTmysYzDRcG84DNkKGIPhGibIRneTWLbDcIRl08OEHVeyWgbLTA4ZRA4 C3yQ4/bQG5X6Q1FxL94jIBPx7MMQDdaEd1elVK/yzwubkZNFid/HTnrMfAATgIlD z9VA5cj+SntmksN9CarhQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeggdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepgeenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 4 Aug 2024 09:02:51 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 17/17] firewire: ohci: use guard macro to serialize operations for isochronous contexts Date: Sun, 4 Aug 2024 22:02:24 +0900 Message-ID: <20240804130225.243496-18-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240804130225.243496-1-o-takashi@sakamocchi.jp> References: <20240804130225.243496-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 | 164 +++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 96 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 368420e4b414..f36a0c853673 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,7 +3135,7 @@ static struct fw_iso_context *ohci_allocate_iso_conte= xt(struct fw_card *card, out_with_header: free_page((unsigned long)ctx->header); out: - spin_lock_irq(&ohci->lock); + guard(spinlock_irq)(&ohci->lock); =20 switch (type) { case FW_ISO_CONTEXT_RECEIVE: @@ -3159,8 +3148,6 @@ static struct fw_iso_context *ohci_allocate_iso_conte= xt(struct fw_card *card, } *mask |=3D 1 << index; =20 - spin_unlock_irq(&ohci->lock); - return ERR_PTR(ret); } =20 @@ -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