From nobody Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 399A11474D7 for ; Mon, 5 Aug 2024 08:54:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848055; cv=none; b=FQMq2h3usrg1bItY9Y6sLeUC7iNPF4f0qQUIo4ovezQoEJwX4kZOGzaYLj0U+T8hRDz2CDTGRiTMQ8QR0zJjGPrxd7ler3Q7SvQKbSSHMDfEuegiAywH7kiObeIBlX0pBxJCOMaH66hT4MLCDVtUSD9A9qyak68/hfRMeP+yXz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848055; c=relaxed/simple; bh=LTZgk4Q7yEHgsYa/3BCj3o9FpVWAGqL0/melW16hM1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dj51mPrw4N8ODmjYwWsRd7gXA9gD0BLP+DcB2MEVeRu85QdlQzcGQamzcROZEa2n/ssrN7jCdKe9tSZO63UB6UizBFtr+2wIq+k038hfOCZ1UpZXPabjlovLSM1ciwbNwK5LBVxpJ08Q9gFHhpv+L8y8XhjZ0sVMpZ7AnH8LqmA= 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=Xw7nI+os; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RvmDsTtE; arc=none smtp.client-ip=103.168.172.155 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="Xw7nI+os"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RvmDsTtE" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 502F31151C9B; Mon, 5 Aug 2024 04:54:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 05 Aug 2024 04:54:13 -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=1722848053; x= 1722934453; bh=96B7qG2RXUCqvEU76ArBM5B2OlW27Ke00tHiDtOnSak=; b=X w7nI+oseErLaEdC9C5UVw1plc2OMYvt8gD2mtUUdGw3z/zw6jbYYcGa8Hw2EFipd fh/eYqbEdZ9NJWZql5GZQ10mroMgNquxChFOGrJfEW8BC5Ejm5+eYzj3ajcajxj0 33uhXTgEP8ETqFrYDD8qtIz1R21J4eFPe9WyzYlaNPWlHt8lNE7FyURKliGChIeE SYc2QLx5JEvgPoetdHi4rqsVxETUHXdMUMKbz8vREedaj9FSXc/f4zT/hnRAIhU4 MXAKOMV/K21fcUYzOFO/rT/qx00hAyDshfbMbXTKLzt8KQ0rRHsMb8+8pZTkHqIy Hq/nxEmpqXznXprR5jAKQ== 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=1722848053; x= 1722934453; bh=96B7qG2RXUCqvEU76ArBM5B2OlW27Ke00tHiDtOnSak=; b=R vmDsTtEp62s22RsWxZ5jSNfUEf/uutbAtTgXeOG1g3ypoXUFW4OBZo3hZ/yDEHh/ 5HzjcTfdr++j87U3Aw7fDm2DJ9l3MDoiOcvrA9O6KC3kMZSbqGiWTiC3Fvrv3FcA A7L10NzQUrVBLujWzki+SSQ3OrcErMxwgXvUvArevRPCD8Kh2JvlXyeBZfcohq9E 2XZH8C28XbuBZfmtpSsGyZ5gyzHrkmN5TMQNw7Pdm4UUGERcFMB0i++DbZHQgvK0 mz49FREaOh/xJOPDa8mvvA2pvuxSKJa4F5bSeKVJgDiYFl7VS+y9bc8eeOurzJKY Z9tqhwdAsJ2SumziwObAw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:12 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 01/17] firewire: core: use guard macro to maintain static packet data for phy configuration Date: Mon, 5 Aug 2024 17:53:52 +0900 Message-ID: <20240805085408.251763-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 7CCE214B965 for ; Mon, 5 Aug 2024 08:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848057; cv=none; b=YCLgIg88sLNhYeQ9do3q8ng9btnU68XVim+y5EpSYv6uWndEM+4I5bKNlgvN0HWp67mE+DULSZcBDXdVn1JpnCL4SmVkGpSQCQtfsXk3WtnOopI3ElRMP7tcXcVJvSTttfL9dRQjl8SIEuhFKQGgqoxOexjUI4vel38fZPbg5CE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848057; c=relaxed/simple; bh=w7k0vH2F9MOx4njtAUYL+RMBDZfz4ElgK8jF9a0p6F4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EqahygqdS7O9D/HnsXPoAMXNmIpFB+vb/Jq5N0RavZ/KMXI7aj9NEbGPJ3KONY+BAESfvJieAv0JsSMi8PT9zf24/coeqXZc/FdoOgZ+cjbIcuI3CemizC1V41ditcq6vCCJVinUSGYUIEWSBTYn8BM1Zmw+6nXYgAYanzRHKiY= 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=0ZnoUAWc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VGTmbNPQ; arc=none smtp.client-ip=103.168.172.155 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="0ZnoUAWc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VGTmbNPQ" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A76671151C9F; Mon, 5 Aug 2024 04:54:14 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 05 Aug 2024 04:54:14 -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=1722848054; x= 1722934454; bh=o9vF7u9NUcybsaqu9wuw/REBguJhypKXIzx9986qq3g=; b=0 ZnoUAWcDrufjuLmbIgf26SSnB7pufxe1TDruZR/ybJtFEpNgQv+ET/qydg/a6ruc WGQ6m2dFz8CyjaDJZeWWWY3WYUjekT28PZLz5h/Ys0cR1W/ENyf0+IJUoom4r+wP J5pBSUjkPr4uWnEVESaALmYDX7Hdgnx+k7RuTF4i9U3FzlpdNfOR28DPt7TwKF8a w6/OitrJRQCT7fsDEU0xRiO6FqgiI1ikB9M+s+ChCPH4h1JNiIl1ltSzPdNuy1e2 aJSShpqXyRsCl6NmDPU15uixf/FibiuXcJiF3h0AR+3hhkpnGH5//EKAMyZTe9dH o1AOz049c+jrPM3RsqJNg== 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=1722848054; x= 1722934454; bh=o9vF7u9NUcybsaqu9wuw/REBguJhypKXIzx9986qq3g=; b=V GTmbNPQufO/mBa1N3vctZHfkH96XmOFcRLmRooWHfPgPPDXoxwPmIdKJx8i3R4Ze SMl0Yy416lREBRVQzeOoMCePudfCEyTeyW7O5MmiGCJ9wtvdaRlMgM2KwwWlWf8H K/BcI89Mt35474kxpv9IoeBWn85eqd5rzeSXAvHkiWvXr9fILvNU7nWgfZQlUQAH NY/WVRvWTPnmPnknsYy1yuN9LlTlXNLYrlEEi/ctajs31zG4EFPwOPh9tZyjunvc KuUYz9NNdYWCKTZ6oCrQDVlSB4Ao55eb6DtveNvCZmvaNq5+9K0UrOQHH9B3CYni KOfjANQfiAI/4F5Db349w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:13 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 02/17] firewire: core: use guard macro to maintain the list of card Date: Mon, 5 Aug 2024 17:53:53 +0900 Message-ID: <20240805085408.251763-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 AEBAE14F9E6 for ; Mon, 5 Aug 2024 08:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848058; cv=none; b=Lt5IQzU7ugY1lvySEG1EKDMjJxw5ve5ApyBj5r6hZ3R2ORSTXYXnJnrN6dJNa7Y9DUGYV1s48oItDZTa/vM/W4BkEA3CywL5cZU+U3hvVcZR6+SgIyof1649qqf5NkfXeV+W/L9KVAzfDKR4ZQ14qhpYVNLN/D8Cq1dWPRfba14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848058; c=relaxed/simple; bh=JeyYRSMCwYlr7qNMG60tXxpFd6Zjzxm4aN90qQy7yKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lWc2+CwSlUztx5BUihHTQcuEwrmL4r1wo14GqhXxYyTRlTcxQP9Brq4Pxl+tkfO8v0SYAhvKwKG2hj7sJD3hTMS8m937zWZyKcWxviFSrf6dTjNvNU6YgOZQTwnzNFDLKDcr0tEyK9stMJN1WR9cfRn9+zRDfZLtcPJx9mgLDpI= 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=AANgKhgW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=t5GVy5Ck; arc=none smtp.client-ip=103.168.172.155 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="AANgKhgW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="t5GVy5Ck" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 10DAA1151CA4; Mon, 5 Aug 2024 04:54:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Mon, 05 Aug 2024 04:54:16 -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=1722848056; x= 1722934456; bh=8IZ5bfVFLX4rIiQS2rZQ4M3BHJvsAdGdGKx2Wo29X3M=; b=A ANgKhgW8x+mJuguKWNA9VpSSjsBdqALT9LkFuuX90aNcSNe+5XXJGYegN4s2FjMY Q2j1JiLm9yuypis5IB52w63n6s7i+M1eqfRZcqXl94CLuPvzlxzTAQJbb7jD0UXI xbwACCI0HIEmlks4O7EjpOX7uOqO3D1SAQwzaoiSACbkl1j4r0WGdelFhM+pxlw5 M+gRBip0EVB9u6xnwfkuX65NbIt7ZPCc4214994O/hELj9xGn0SH5k3GdiMg7biQ 22M3GsFWHUZy8DTg2NoQs0E/WpZZriCvCKKOWWMoJKp8K9sRQgZv6M79BDaxdAgr YXiCfstirIuuLS6b4jzKA== 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=1722848056; x= 1722934456; bh=8IZ5bfVFLX4rIiQS2rZQ4M3BHJvsAdGdGKx2Wo29X3M=; b=t 5GVy5Ck17hD6N+cd6fF/dIcoSLiyyMgGL1zkeYC8942J1TrdxK48J3BOBcBp+D3B 70bF3aKJ0kNIBHhg3Gear/6HCw+dHjwtPNhsdPnzVFLIvo8PejB+6QTfmnpdEtA9 Hl0sABwKSUCzV+gWaWA/oXuhwVfWGgEsuZ/WVpc+k8IuRCn62S07msvchqdGTqiv 4AM9s0VwTzx0T8Xy/hj5b0WqZycwBwz+9FTUK6tWkw6y+9S1CHhumIXgykUq4oyK agvId98UW12PH4NeLLchKMOLULt9JULzTE18cI1bV4P/IP+aRmUwvfu05AJTgU7u h0upm/l4RukVPIm2zuOHQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:14 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 03/17] firewire: core: use guard macro to maintain the list of cdev clients Date: Mon, 5 Aug 2024 17:53:54 +0900 Message-ID: <20240805085408.251763-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 49DCE15350D for ; Mon, 5 Aug 2024 08:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848059; cv=none; b=uBGe2HAC3LT4Gyxn6J/P6vTJUHOMD5T9kNqYSuhDFNrWRBdUDTFWWPvIQMintsaOmaI6hixOa+ty9MJVx+3H0tlaOV+dvfwg4qF7hbgLXF0xz7BR0QxwZvvHZA0PY3/xdxOOGxBdYc+0dqKKgpqTVFgZeCd4HhwfVeJISkplt6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848059; c=relaxed/simple; bh=vA0kDygfFj7ZpFqinqieUC76/4F6R76Vd+hTvrPc/oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nk3RHLoluIakkHZKtRQWA+ku6nUp7RGczHsYl/zwXdyBeYlRyeMNrn/dHOmrr/GCGHDnDJTGpY4sCWVWd+MEIwqVjiU8glQVjPPC0HtU7HCysot7KLFeHjpyFY66Bwsjb/XyGnLQRtPASe25aUSLJtMQWSxB7EKIHpAsMreL5pU= 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=F6wgqHZX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SB9bGZBy; arc=none smtp.client-ip=103.168.172.155 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="F6wgqHZX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SB9bGZBy" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 614531151CA6; Mon, 5 Aug 2024 04:54:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 05 Aug 2024 04:54:17 -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=1722848057; x= 1722934457; bh=umV/dIhWSMe39OeV812KLlWHxNO+f3xTH4ZsEWLWI7U=; b=F 6wgqHZXg39kTnm3T8j5MRN6vGAeUXp2OzE8Y0e+DEq9klB7sl9hbs84ua+dbe9oS GXTJepztE2mFJsGLSZ6XMQUmdL//kkFt3C0xo4m8J1Y6//kIWCPcZGypuF7S8uy4 tWS79sVwWi5C3+kG9R/QepEApYZjVWi9yyEIbvY3+LHXvgIuCNnM1FFPSYMCZzzN jlwIdcGkTbf1r/toTyXL1IMBDtwvP7UcOY+XpEIoqficDuYKjltm+nMjFj5ZZVVk c0iFPxJBawM1HsBunt+J7C7xUVYBw1jB4EcP0UoByplzWXY0IV7qg4L1V7MVLy0A OpBOA8SA6DuoGQbbrSOTw== 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=1722848057; x= 1722934457; bh=umV/dIhWSMe39OeV812KLlWHxNO+f3xTH4ZsEWLWI7U=; b=S B9bGZByiULOj/sr3qcsKlDy78dwcDrYDB2EH4hcusTdb76Rfx8ldEpgTxRB/KV/O QVScxOp44U8K27FhsNqpBw5SAbZBHizuTG8H/g7vrfMoDoZSWd30O34pwz0xppTm qAABLlN0x9Aze7emnYBCjFWIDYxCYfnwY8H5PZfBmI0i3zIq3cM/NXqftEHjodWO X83HrIg4KiSkJE2NiCow1jYnTir+SEB3IjNFwWO0F9ACyfdKRIWQcZcc+PthwGFe sxTTzyaHgukJLpmuwjaBVFPIOULon9OEDdqCBHgO2JIVwyRKyv4lX26fcznpa8z/ lEx7Xpp5CT8j5R//J93bA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:16 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 04/17] firewire: ohci: use guard macro to serialize accesses to phy registers Date: Mon, 5 Aug 2024 17:53:55 +0900 Message-ID: <20240805085408.251763-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 1394 OHCI driver 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 Fri Dec 19 19:21:41 2025 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75D04153BE8 for ; Mon, 5 Aug 2024 08:54:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848061; cv=none; b=m9ceL13mSzmp+1nWafBufF09pq49lNZwX5sxnJZqgmDvJ5riZ7it/xy+73a5GKX5qxtyRFsss5ZcrVfxmWKfCetz8bbFqmTJVg2n9OALNlsTnfdMDa16iTIuo9alkFqt7NIxfluHYQSq2KxQWHosvcXTALauVq5o2d0v4oLpZnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848061; c=relaxed/simple; bh=cscKU5uPCciyY7dYw/8esZBE005/LOUY76gf8+d1Fko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DUcW1p1xx5vBd+7lqyZZJnBwiJvmES6qgSxzILSmoHEtLQSDgDajG7esoBtnmuvQUVHsmH04OoVeE30ui0t5lqi9AWLsl7R0BwPG1AJ/lF7utxkXq3uccNBhrIBwL2nmyJLhgFJPr5ue+/1z+Te3NNIYG1weTNzQmbUoqUTmLj0= 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=nilAbEbG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U9SWiOXW; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="nilAbEbG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U9SWiOXW" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id B0358138FD80; Mon, 5 Aug 2024 04:54:18 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Mon, 05 Aug 2024 04:54:18 -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=1722848058; x= 1722934458; bh=Qc/S6YXZ+4o3poTVbyilyGCeWi9HX+4N+cgNY9BibBI=; b=n ilAbEbG2omaCte4zRoqkz89Be0gWKCrs08zudKNowYZpU7T3+il94kohdq7vAGpM sSrfa0iiFRQJpjIMarG4ftE3+dw064VL9277vx+MoUoEm+DTdRghuiZzCEJ3qQ8G z6YCNr4hc5aB6VR4hKuPAw484tpAjTGWFwidceYrgHoYSLoyjnbjfoeWSd9oamfF FPkXA37f5e+dNgx64jGUEFl75nrd26u2F1Sb+Qt8J7e742hjC1BpIGea+XYaWAXk aBhsceK+zlVPzowOlLeEbb9YtDiMJKbyQJT8W44DZDYgmWTDbI9PdqjtbQEdhACE 9pHD5bMeux9tkbIjydvng== 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=1722848058; x= 1722934458; bh=Qc/S6YXZ+4o3poTVbyilyGCeWi9HX+4N+cgNY9BibBI=; b=U 9SWiOXWfPBTsV98mfVsZx2ImU6H906iY1bvCvhkAIM6mKhXdO66O0inuoFmQoWPp BaCp85k8HsL82et6jRol8WtPsbHdC+1mIqMcCcwAHeo/u3ImKZ/1FVbhqu0cR8ex LMJuioCfsR80vAXzqVWQbbFImDhcf1aOcBwo82Ati1iPgDAivpv9IIb4Lh0DlbjO K6ueboBW/gnfH7GRrCBvSp8b0D6atvdLMSWWzlmT0e896kloKeyijOTlvhPzlkk1 xcC+3keb7ZIsYQIeRLRX1ocSv/MgrWCFw6G+M/a86x6Su9eLOf83enfYGTsdu/mw sL3wigY/LL0/lLkkmOJLg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:17 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 05/17] firewire: core: use guard macro to maintain RCU scope for transaction address handler Date: Mon, 5 Aug 2024 17:53:56 +0900 Message-ID: <20240805085408.251763-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 E8DB51547CD for ; Mon, 5 Aug 2024 08:54:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848062; cv=none; b=iVbCOWhKd9qdS4OHlRGBpSBeeMjmAkpd8gdmH2XOHCYqO8U9pDuJfbErEXwapIRJ/H2RXGlWgdugv+Imcx8nsOojZMMC9qvv6Q/KuTMAeNOpialNArfTzuiKObohWsdgfNYk9jWvqZUj95C7OZNa6OHscRWxuVWMg9Dh0ojzyOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848062; c=relaxed/simple; bh=6gNVdCbKVSjJWTIrAa6h7j/OsYRdI7mtMVNyParzw+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IxH9mexjqoxukg7xcCzGO2D9phM5FFRxqBAONv8R2ffK6Ppk2P6UqLQ4lTQH2YSqFrH272Eip0c/vN0tMwdn+bQARXPjvFjR8SPtAmmYcZTcoDPCXH3EkeNeeXck6kPdKLkIM1DpfpRSsIUNzJKUQFoTRHsDOOs2KKUbWL2Zh6c= 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=QESFpjO1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=syntl4K6; arc=none smtp.client-ip=103.168.172.155 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="QESFpjO1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="syntl4K6" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 0E4A91151C99; Mon, 5 Aug 2024 04:54:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 05 Aug 2024 04:54:20 -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=1722848060; x= 1722934460; bh=GZl0F95VKdVRmO/VEzrXjIFDoXhwf1ZOuWhytnJzBf0=; b=Q ESFpjO1WMJ0IxA5WS8kFEFDst+Ncf5cw8lvUXDSYCh1J3QvrMWwZq7yQwn1TE3w7 ZdAmPLVbzJKdYoSqbAAygDmgMzmWVmGLyTjvevzwv4PgC+Ei7pUypHLmytIs9r3V mt34v0iJLYzXUgRWcZjaCHFNJ3TJA44fKkeYIkn+Eo4G6V4qPfvCpJfvFtap+J1u XTtTFWkTnvOUtl+6JFz6b98NzRhErQlRjUBO7xT5CeR3adwyIPdCcq1IzGn63hZk r8dLfHevTg3s5eAvBREbJGM1T0yQ54IAwV9Thv41ILybNKn0MuwH7u4IhLXwvQk2 9ApLvjziqZDMs6eTfEptA== 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=1722848060; x= 1722934460; bh=GZl0F95VKdVRmO/VEzrXjIFDoXhwf1ZOuWhytnJzBf0=; b=s yntl4K6algimwx9gUV+Jpik9rGMqO2QWAbxfeBcn53OCOG0CCqysSIH6bUI2qWLu culCLT8nm2W0q7vGMVBRRxdD/ortYvOq+VTTcHOwvN9UVItrk8mZucG9EbCZCPju UZJfSXqhoW+SL61l1CseAFcis3BkSQ44c2dJbXGoHVcwGze8fBIpVnayHCbKmBhH 1jdunL2X0gnABCF2zxPTA+J6mA3+qP7h00CAjLMHd6opROvGml7Duhuyf62Bw44i 710OTchL13KqCeK/cm8Oi63xPYVHekLZLIbWunpBI8OmSsozNa21Nnwt8KngpxE+ W6Yz+SsaHmNNhWIboy0vQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:18 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 06/17] firewire: core: use guard macro to access to IDR for fw_device Date: Mon, 5 Aug 2024 17:53:57 +0900 Message-ID: <20240805085408.251763-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 2EB7614B965 for ; Mon, 5 Aug 2024 08:54:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848063; cv=none; b=rjYp5boHLW5izTY37ot5RcEkKbZaSBiki3+rKu8aSEVASCZHCI7XnvnNtMqpkFR41NGzx8L7W+2/nSaGWhQ///p0Yw/Si6nB/F6voqoJfRhELb2P1+Jyid1yaESj5QlsSCweV8PTJRT7GhTSo9ti1yNKa8pBX87We6vgwnmn3P4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848063; c=relaxed/simple; bh=cWH7ne9vlR3TeVR1Q85Yfp2ze/ZNy4hqU1VPnNmO3sk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YrE3F4QzzDYkG3jVEt/BcvY1/kyw+BvxlKU09Ob0fbm0ZIY1wQ6J27OQv1VXRF9xcFVF/isBkTJdUJI+g3ulDwZf+36zh7YzxbXdty4/u1QOpiERDQmo5521nw3mD6TTlDUAMk1o/lPAB7QG4/7MArWIFP3Devewgky/mXAuwZ0= 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=bMU9vwIG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Q7gSO2to; arc=none smtp.client-ip=103.168.172.155 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="bMU9vwIG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q7gSO2to" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 5D9551146CF3; Mon, 5 Aug 2024 04:54:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 05 Aug 2024 04:54:21 -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=1722848061; x= 1722934461; bh=ylV0FAWwnqnELWHfpdHvBmEJyKerlndDqM/PUzAtIHU=; b=b MU9vwIGsccQJysQDz1zz3I8fN6RG3UJNLHZpLiAsf8eW+5JjtLES+J3OoQM7fCNp pcgvLjNd9faLG/K8xiTGqnfr/tz+9ketzmnzP/UTKWmf6OghQbDn0o6HzOssLI/T FliVMM+VGovFKn/zrroWCzt5R/VgTFmZ3o04c6FZ2IOuUKV9TbOCC04f7vxawu7U HycJ+waaQGb/fbfxHQAuaff1spFEduZVcM94/XvxaElhKnYJ8qOFJuXTHfy2YLeo dXCHkZ/i6mBsG3FIynhMq+GqD+cvIL+JU6nYxwAlL8xWLZzBPIOSpuAxFnWf0sO0 U2iNScWh6iBZIvBsGHXJw== 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=1722848061; x= 1722934461; bh=ylV0FAWwnqnELWHfpdHvBmEJyKerlndDqM/PUzAtIHU=; b=Q 7gSO2tog4qr6Xnc7Yd4aluTsVam2eWo7VfkAbIGTkuuCUazPHLBUSJs2DVrs6Np9 ga2H6QMnmQsFQhEjR8ik+wDWeDZyxNVH2Amxgp2y99lhPpnvThkYMgkFYsCCxEJo K+rgKK/3YlSXn/MXEVKWMK5VNVdgYsGG00ggWrdsJxtSup4xndHK37xviZ9NzV9B 6XqvnYLPEu0UmdTC/5Brz4rvgsyG0ioLsXiGBnWCLx2MNg9616uhnlhkhVdL7X5E /Gk0v42PCWWowxGFCZ/8cw/ZMAYL2oMXacF4aHI94MHnUO8PDODSyYslVAmP4TBO qohgKSRgfSZevhm7Uc7Jg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:20 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 07/17] firewire: core: use guard macro to maintain the list of address handler for transaction Date: Mon, 5 Aug 2024 17:53:58 +0900 Message-ID: <20240805085408.251763-8-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 90878154C07 for ; Mon, 5 Aug 2024 08:54:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848065; cv=none; b=NrUNX6ID4DVnJ02N76VQ40uDVnmCFYQepa2Eyuw9PM8PrzP3Lw99XMHjwndY/QmgOwvnDBAo5EgbUoQozYwsO2ygiqx1Zz8vlvtYdLI4X4rgn1HLh/HqZ0/dOk8cPWRU98NS/FqJIZqtWxSJxS8juG5Ap1PmapXRAO+EV06Vitw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848065; c=relaxed/simple; bh=0zT4ELUdypbLDPtYPoNIq0nN4q+2KRKcNt9sf1SBc84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NtLaPGbKFGmbQLwY1MqhhlVSoZz8ZVvxQ1gBt8w6KB8KBbHoqzy1bxY9fssSy3ynz/1lE2SFpY9rVy1FSdU5MPN2eyDwPBUvRlgiRQjI1zBwFNX4YOv5zsXy7FBj0x9bhPZ6+ojmepqBp9HYqAezUllapzinYz+IKiAD88dlmMo= 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=iqKRgPbw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=M2UwNJvp; arc=none smtp.client-ip=103.168.172.155 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="iqKRgPbw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="M2UwNJvp" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id B07D01151CA4; Mon, 5 Aug 2024 04:54:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 05 Aug 2024 04:54:22 -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=1722848062; x= 1722934462; bh=riXT/ZPaI3yITLXofYuDWzvYYTW64WraJqRL8dIk1u8=; b=i qKRgPbw0F/BGTICG2Ydurr0ShavqcHfeJhR7ZjMxVKBf6gw+QoFrRqfhS7CrDdYE 2H4tq3lZYvfKFgylGT2OwE38yKynX9Q69O27YS/zmu3CK/LzgJubF1j/9MKSwOIM MCck80POWvGWTNcXmjGxEqx9OdwyMFuKLMsr1lskIWQSEtQdE+HumKPllnkD2U1C tr45Q9l/zNMhXb/krF3mFzAMBdWqM2c86Sjg8a+byxtnMf9eH7rjWPVuN6ltFgDA OUGoWcF3QjhWal3tJRvmYZgUCyFepqy3ftR4V8QYMIFyWxGlLYCXryFbnOlec6br xrc1yo7dSgXWzIpZRFXWQ== 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=1722848062; x= 1722934462; bh=riXT/ZPaI3yITLXofYuDWzvYYTW64WraJqRL8dIk1u8=; b=M 2UwNJvpWAS6JyvrfRUSaNDXXT7sWnp8tL2ndCoLvlURB32kJd+5DfJEmMZTd1/AZ zhTUDb0ku4+LEK342LbFWY9ImyYKnfjoPjPFMefjKDuvgXJu5K8yViy68LKQeINa ttUfy08jspUSiYjRCPAk0ax667aiRPyhnZGmzpcL95ohXYiNjq20s2l8k6fOSRdg 7rc8bVVVtVotfyXc2tEKOvK6M9PLKBcVxly5FFrNkkSEpIrOGFzWxswEcgWQBUXn YSYb1jNTbFOiuQrPMpnGEI5hCWx/krGObHSwPKdoxl/0Cyi3mRm2Q1//iOTQYA6c a17wm5qn8L3TTWmiZbYMQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:21 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 08/17] firewire: core: use guard macro to disable local IRQ Date: Mon, 5 Aug 2024 17:53:59 +0900 Message-ID: <20240805085408.251763-9-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 ED54B155389 for ; Mon, 5 Aug 2024 08:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848066; cv=none; b=Z48Y1qpQijljBYWUIlb3IwxLnzOA4mhe60KR+c+HvZW7izDYfsOvgQfnPterarjVBpIREH+l3gXrOqqbKozgpSGTqwGu9pGHlNdrP+PuZIFW6VjH1RcRR+Ph9PiJKTeNP0YInRMlacog/Iye/0rKkBYoYUA7OnCw4gsBLdiSp1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848066; c=relaxed/simple; bh=3M4QOIj5f1Z1b9G9IJV0Sp/2cF6cD0jloZp0mRO2NP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rSLuD3WgpH8wl8w7vkUOgkFKZD2pf9WS0rkT7vhhasz1iuBUQBNprV0MGRnXOM+fzyla+GdWZ3EVFRJLOmFDXkGGBuuS7dHIOmCHuM2aAP3E+Xa4PoEuJBhumA/F/Hi6sk4oQ5l8GLNVoJui2Q1Bx+vtR0CHQFMSkyefOsk7nHI= 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=orDCVfoT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SE/CGVgO; arc=none smtp.client-ip=103.168.172.155 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="orDCVfoT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SE/CGVgO" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 081151151CA1; Mon, 5 Aug 2024 04:54:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 05 Aug 2024 04:54:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1722848064; x= 1722934464; bh=cnExW14OrezM7AAY2ZcP4bF1stBaSNMPihuGoMDdgLg=; b=o rDCVfoTtUc/UYhoAS6nscznEnCaUXU0brCBRTBpaFIHOZLi/oqE20jibt3t+ybgq ajHzY9r9z7yXJ+XPYLcLsJZmkYw3sulBL3ShSdqyZHwJjMDHVcUcREG6kNT85+Xl bBA+9UhJqu6LAZ3nxIK2Nlm72iw7qP3zrCf4/V/QroTza5G4mGKEob0B2OsRGWim oB4KoQ4+JWldFTHEl7H89n8d5vWMSPhVbPsQfz0TYuceYnfPiwQlCVGT6LYKwUZh PSFgiUsRnzqGrbmg7TnOWXPDUjKmeYmF8YhQsYXmhqkchnYGntdzirp5exOyqeOQ 0VFTavG9XZj7omK8QlaOg== 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=1722848064; x= 1722934464; bh=cnExW14OrezM7AAY2ZcP4bF1stBaSNMPihuGoMDdgLg=; b=S E/CGVgOWXPN3sF+d1kh3rpplEhvb9tDX6vqnP4eB9OqJtqR7tKYwlQVAq7n1v1k8 1bbysimWOi5HMCHX7U46jLiYxdv54jYma5u72akT8Ic4Isar4Ticrl6g3xpcYjpo tDZVf+P0Oh6wRU65SpwLeFiCcdQ5ymw+/WAWaPFtMzZgwnL2P+WMiNJz0W6yP97U XM3tjbVVW/ZXu+w/3vhio+91lwp9y04itFY+OYobeKrd1+J0ixRrcOSteol45zZF 4b6kqCp2skXPs2mQkuDwL7ipI0L1okh1YpixvlnQzcb06HkIud2Lc5M4flTKgyD4 daPa3WnH1/zJOitvUftsQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:22 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 09/17] firewire: core: use guard macro to maintain list of events for userspace clients Date: Mon, 5 Aug 2024 17:54:00 +0900 Message-ID: <20240805085408.251763-10-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62B43155744 for ; Mon, 5 Aug 2024 08:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848068; cv=none; b=OOCR5AfjsVcozfMzaopdfwmsNKUV+UVHl4zDxlgIBhzAZur/RCpMVWcNJQtCWBDEt4opgo3FRB4pb8gkusRZ6nWSOGmaYfaxFg8FiHxDdCL6cQGywEsBLzllL+YxruQaWkgzlAD/KYEFMwlXs1dGdnSBtoZo42i9wojwf5GNvKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848068; c=relaxed/simple; bh=uzVMeTX0BbvAA/TdPM5pqNjVCufYr9cCNWLDVrjaoUU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uqu90K6rJv0m0TKVt1oosrvCVOSh79PGWQXYK8PZUpGIrXX7vj4UJs0lgJZ1icIgLnfraSICWOGeZzbmM3KC+S2JSst5a2ZLJaaFE5sPgGlxdUw6E7WkDKYJHdiZ2R0fBK0B5p3HQBbNrBj6mC4XEhn5bm+FVzU5Z2GAYpS09pM= 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=Xh6g7ejx; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EIMnte++; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="Xh6g7ejx"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EIMnte++" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 62370138FDB9; Mon, 5 Aug 2024 04:54:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 05 Aug 2024 04:54:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1722848065; x= 1722934465; bh=z5mX0VvBucVVAQ3hVsBzbK3EagpAINO+dbqWRzZbXyg=; b=X h6g7ejxo2MhzpEfm9xxoolJvrRH8FOjMP0H4ElIzP1rq/ei13Rqcl1sfdUvB7O59 yiXIlPwT698FehcvZ5+k+RWdu4mDz1w6Ler5EwNbjRypOq6OGcSnknqRXU8FwgdG LON8sIZxgB1Xj1ymh51+pi45DoNwL11esSfZOuDNJZsO69ucSIeUq70yM3iFPfvg k2/goSiMqKHE8pJfscwbThbpd+fZf7YVwpox8Yg5C6wigj0rjDi4PpTWSTeQ0XH2 Cm3AYjiwAeODAqzyqnW1gwWZmrhWmDXn3mXWeHsS1SRUi5NuPwpFaqpN7LAStkMT TzMl/7xc9psNXwXX68UpA== 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=1722848065; x= 1722934465; bh=z5mX0VvBucVVAQ3hVsBzbK3EagpAINO+dbqWRzZbXyg=; b=E IMnte++qSGMUsH4kPyDQq6ah0C1GhMeOYpergolJKTwyBsfdb9UpCOipm0Ltu6LX pbutu1cgMdg/pTRHqTPMGJ2jTYJvj6tYr4Lb45r6vBMCKRNqX5DNfrjdtOzRA8Dd Z3a5+xBfbMvdj4midD7XYYtCzdrdYUK8PFzLCmHVXfolpTPfKOgZSad1OhlGBcfR fbEVy/cX+tnsuk+kLeX/g6M8eRbPCQpihAkEpxCMIrsdnqqBwqGRWDIXOxhst3k4 KEE96wbR5/PyvZ4TqYkB+x+KHOg9WG2TyHItUsUe25NBivwqRiyMUGClFk5p8zHJ LPQOCra2NCmrgFFfu4Dpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:24 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 10/17] firewire: core: use guard macro to maintain IDR of isochronous resources for userspace clients Date: Mon, 5 Aug 2024 17:54:01 +0900 Message-ID: <20240805085408.251763-11-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BC0A155C83 for ; Mon, 5 Aug 2024 08:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848069; cv=none; b=Xd2qQb3XYy+fDJ5xGcRbStJddp1i1dlT18GKeMLoX+XAxlZsedQG/l4QpuJExldYadQo6+4Jzzm+reZXLW9GfkJrop3/uvqUJ7MP/U7S77MVqUkS/c+uLyO+4VrTmhHI+CzoZYnFcBMF0arPAwNqCaGNUyUQWgt46CzZaqifl6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848069; c=relaxed/simple; bh=50aZcCKLJeunfclbsZ1zlynb/h3MqzlmknN/YhwoRVM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cRyJ8548fCvCIEUitzA51AUIfRMzxbLsGluNmdoAe7Y2UcmcvRJSEdhJfuUencoWkXWCxzzPf10Y8t4ZHp6KC4PnFZyTOfA3cbmy/fx/fNJc9IxIkQkL40JdRjb9ncNfOi1TF/4svy0m0ZqgOlJfrDPVxTBvUvwJBZIjaIdC9d0= 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=i4C8WxQh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nWfhaVPR; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="i4C8WxQh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nWfhaVPR" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id B24A3138FCF9; Mon, 5 Aug 2024 04:54:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 05 Aug 2024 04:54:26 -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=1722848066; x= 1722934466; bh=CAposS/X5iD+uiuVXyMO8x9mAy4UkjQlQ0BVV7Nspq0=; b=i 4C8WxQhDARDG+3LiYI4k8O/8nA9xmrjicpvWvTszzuH7q3VVQZQ7930fPHTN8Aaq JZh9sfxmMNtG/Ek6kS2Ig+l7hcf9VZ2yA5g8mtGiFV2UI+WMnr8mef4I0Ro/c3KP b6BnkfyuT2rGAlfbSheB0VOwK/ME5X4jWERfoFlDU8hTCsteCXnn8Y3YqWqpNzo7 mM/zy3/VXpXyodQNBqRTHz92cxZI8FISjrRSf5gxG9A8NDRkS1l1/kndVhOSnWGW 3WeapqNmtMmrtaXo4v4GmO8irzvIiOM9Qs09hnJYmR8yWo7mxHJpjku8cvXbyBWk 4Rs7aA7ojLWBZ/LMX8jOw== 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=1722848066; x= 1722934466; bh=CAposS/X5iD+uiuVXyMO8x9mAy4UkjQlQ0BVV7Nspq0=; b=n WfhaVPRGPMQEvJk48/CneWh/PRAuCf1zhXs+smnQhUGWUU5ZnLxk8Iez8jscf+ub Kh8g/CQyLfY03DqbhWRzCVSQA7VuHve+jCqnnhOcb2actrbwNN145rKab3hXG07c bCkv554Vl6IauRScGMjHSJbMqMr7ObxJOAMbnkvHRE0iSclL9ONsnpbXfipPbzmt dVomF2TsWIaW8K4p9Aq9XPEYcKj7EhteLKXBqURYfCbp9IC2hcgq0lRvYckwCvTD xCb36WCH88dh5oPrtWiAEcqCZ9OlEtnFZDnB6JT41s7Q78mG7KdbD0qpaFWAH74w 3aHlOvSseLV0tWaMHZPMg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:25 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 11/17] firewire: core: use guard macro to maintain isochronous context for userspace client Date: Mon, 5 Aug 2024 17:54:02 +0900 Message-ID: <20240805085408.251763-12-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D530014F9D7 for ; Mon, 5 Aug 2024 08:54:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848070; cv=none; b=GMTx2AwnRkzfXQXFzSu/L0FfYGYm9Z0kPBPu5oIRPLt3tHnphriIwIVZ2bIc+kUHMimPshWUhMgh4YAugA9+7RDzZxlRXYQwTi6c0xqXzTZ2nY/61sGSeTulCJnozapNv8mZJkHNUei09I47obUDiiUU8MMI7e36l6VROH+sdZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848070; c=relaxed/simple; bh=byjeyaU0KCacHc1trU6Nd+xN8T9yKFSqZfE68WM9laI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iEzEOECrVFriNy/abph6ufNdYB2psoYNzGwFWPjB56ttN1XWxHcpo2PWdWBfuPc0j1P87C1drhE+ltsugjLtWPCSVmFjTgHj7wXTYfrHzo2cum48lBv2uqMxoTzVQWXSj11bf1zclUIZz3SbiYXb1xx0aQg8Kh3x56rxNASLHg8= 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=E6LNQtp5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=p6wXme3m; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="E6LNQtp5"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="p6wXme3m" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 14303138FDDD; Mon, 5 Aug 2024 04:54:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 05 Aug 2024 04:54:28 -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=1722848068; x= 1722934468; bh=p2/8Uhv2yJT1ffx5iSM4w272zr0fR0S1Kk6bKcSHexE=; b=E 6LNQtp5AStedNJslYJ4QMrYROoXOrV+Flv4uwvtC2l3JkgAAkNL8zaGxbO8hxayf TAz5JOVl6STAWdeRWk1UZCBolgvOaDKTuUx/lGuqrP+kB286mrAavMHW/CTEVVRp NgcCa3P7dofnCI4JNwmFPkAvxBxm+I8T3j/1n44Vu509utHXOsPpC8x9+MWYgl9v xnvtv51akvF8xBl6XSE5yF6xNh7fARtgBLXIUkts3LpfJXqoUyE3m3OLKfm8LhB9 IFl/eJ6nAr6COqAFwhMNnRtfCWbjK4dc8FpBKS6c2+SiLIMAN6KSCo/CrvTGlxZk WUxFAsH4aG8i5JAqqwY2w== 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=1722848068; x= 1722934468; bh=p2/8Uhv2yJT1ffx5iSM4w272zr0fR0S1Kk6bKcSHexE=; b=p 6wXme3mvRSKs/ieLIGIZpKQ4z9pJ3xRXwkRDazw2Qsl9lQ4MzHAZ8HgDNrJo4aJR bY8QM3iqnyq5zyru6cMDgdLx2YMYfF9SyjWmbOj2qmAecNGguXMErZtgXX+0Jn5/ lI79F0ir99irRKb41UnFxhNmR4oCBmVdLBf/SfBcVrqzN1EDKcNnjVG6SQDTUKKR fcbBjrShhwVAzkfq6wkwS7zOq09ksmc6dh1Wb4DrMKWu0mwUy/gQYj5I1/wgEo7O Qu75g0BLE8eqMtJXiNoDHjUIj5xYi63FumXvCtqIkoRGqPWQBSxclw9DiBQyeQK5 BzZ1oeqMHkcDo9ObVdI+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:26 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 12/17] firewire: core: use guard macro to maintain list of receivers for phy configuration packets Date: Mon, 5 Aug 2024 17:54:03 +0900 Message-ID: <20240805085408.251763-13-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 1903B156971 for ; Mon, 5 Aug 2024 08:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848071; cv=none; b=p+wHZD5SfSrqFm7M8A8K2uX6c7SE+hSlIYC3I5FT0upLge8SYl6V63ssNRbI82JbQZsLrjBCO96BmrgDFx4VOd0TPwlnRRLC6X2ob33rDjQUtXl78bSYCV8IX09te3/ZN3XoZr0pW/07D8uq2M3VRCK/XvMG2Rm/GqZMJpE1NX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848071; 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=ULFFr3pmPFf7FA0Vt66NAX3FG5AYNqjj/H811iiE+r3h65R1vPtzO9xRPRqp2BVo9mIqksnagHXJ93v5XuT8TwinxXletXtv+f+G21Fe/WjnInzp79giVT/g+3dN2X2M/J0YYqLwtfKNmKqYC0riH7xsjJeXNtvQmZe3PyA2UEE= 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=h1hbO/m3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=scOuyjtz; arc=none smtp.client-ip=103.168.172.155 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="h1hbO/m3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="scOuyjtz" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 716101151C98; Mon, 5 Aug 2024 04:54:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Mon, 05 Aug 2024 04:54:29 -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=1722848069; x= 1722934469; bh=g2ZYQpdmVR2Qgn3ioWPYVE8uCIbn3OBt2eoIeM+wq4M=; b=h 1hbO/m3dTERfIpcXjMaQnrRa4ZAijkqeHGIvBIahQ77+RT4ycp37OOQyTgNNLh9u 7Y4n35YNpf9D+eN5wAkVn0bWee2HNLnna9UFRL1ZayizPeI+tcM2GmFbfxTs/vte NG5EIkYTKnQNC01xDD9djFlL8H6Ajl8++aPuoHiIxloTzcI2KgBYA9mgGPo9kosW KGuQmm1jyCtxP5Uj0X5vClCj3pE0KL96gbSMAMa+rYcl6EvBWHjzZt5a0v9+X2va ITC0o0U7bTht+oHuv+8ZqzV+KP4OyQpihg5rUyPXTmRbuAASO9MyZlmzfK83c1+I 9uij5B9FfRDImnvBjglFw== 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=1722848069; x= 1722934469; bh=g2ZYQpdmVR2Qgn3ioWPYVE8uCIbn3OBt2eoIeM+wq4M=; b=s cOuyjtzQypE19EU8ClqxsFqRaZCEDEYeKKMiPXC5e8tcnCehi2I8TXXD6AfQY4Fc VKh2AQSaARYal9xeBxzF2TdgyBkcnK/58e+haqWbrJ41cccUzC6zl7C3SgURY3yB 0VHOUwN8lX53MSrradxBHZfp4O9upSrH2hhN6o37KYxQGgsruD5DmzApn2iistvA W4ZgRT0+YoQi1FEUxhpu/J+Wj7zRjxBpn63rsM3r4shsR+Xehv2s/h5eUF9bs/pC HxPKWvrYIGcbxjScqkNa43Fx2tWMpqqXIMoyJK+LfOSsUD85ztSibvRyVE+YcFou J+7n/nWFPCTydA+x4Lg2w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:28 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 13/17] firewire: core: use guard macro to maintain list of asynchronous transaction Date: Mon, 5 Aug 2024 17:54:04 +0900 Message-ID: <20240805085408.251763-14-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE748156F55 for ; Mon, 5 Aug 2024 08:54:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848075; cv=none; b=l9z15XJtYUA1WeUnpXg2NG7W/rY4nRIK2zeZ3ttbJM+BSwXYiJyWDm5lOp85j6cuZ6HVNq5If3LagQRCCYET5pO3ZXwyFvx6pY9pLQeJkUgBm/4uvE4lcdVNnU+uxfeNsqTEews+N6fZzUEI03W4b4X2qV59AF0S0ltDMO9RlS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848075; c=relaxed/simple; bh=VkOGpKEZJl+vIZAQe3yTz+MuuquZjfY8NHLB4zRcw+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kz/JVh7NUB2fV5exdwjkii9r3I8O7wRdtO3k7xixMlcmzYfqxBjZ4uNrdV1cZ+SIuoRgSBs66gfMWjiWRTbinDdReaQ1c/RNMRMp6y6QC5Qo/czOfvOHv5QmjT85vqpZdhF1CkOe4kMmyRVTtRG/KKOo5Wcb9Qgwovqbdu5U97k= 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=An7FRkSW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GjpwNPR8; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="An7FRkSW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GjpwNPR8" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfout.nyi.internal (Postfix) with ESMTP id C6C8C138FD80; Mon, 5 Aug 2024 04:54:30 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Mon, 05 Aug 2024 04:54: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=1722848070; x= 1722934470; bh=2M63XuIcnOs2zgB0Of1R5tPvEt2hh1y3Apg8Rw8WgRE=; b=A n7FRkSW9KgNiVhNUUszlClnB7Un7ljhFcoJdogiGGBD+And06BBvDvURHYVtkJWf ywD3qKMyqDpjaLol7UM1HDoyZ71o+y5T5VlcwSNiZ+s3LqkSyhHQV2YbBwFbzk2C Vc3XhLK1gRDjFnKFt3g1qcmw3X5YLADCxfF9+FQZVJ/tZ2fkXTJUGni8dE1k+VyZ I3OSGtz5dAWoj9rCE3MMNSZRV6LF98Tjp1Y/6YcH7y5sH3E36V3lOWMjtQBR07X2 25ggVRKpnk5JL951RFyOHJOCGAUNzRlCywX7eezCz+cPVGvweY6QLqYXIqrrAHoL xXso4S6esRxBS52bwyB+A== 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=1722848070; x= 1722934470; bh=2M63XuIcnOs2zgB0Of1R5tPvEt2hh1y3Apg8Rw8WgRE=; b=G jpwNPR8DwgmcddZy2/en9D0T7bmnElNS/qdMMffJoq8lQwgYRKm/KehiRvWWdahL NMJmgoh6AoocD4lByVupQsWadlrsGJZDirJYuypAu/S0KpLDNvOcv0KxUYvBEorZ 7T+Pg4XzwdGDNzjXQU4Xdc3n6m965/g9U9HqwGo97sEgBJ/QA4eRqi6S7Sl1PDq6 9VPHI9rup6g+MVQ0wbVKHNZWKbmWtnJY4HO695pjZqAAh+v6ZzAaPkNaslmyzLis r0hdBU6gSsPI13KpKWfLZQWUdoxChMfOvePKzSmz+5pc2AS67JIJdRAxHWd8Uiiw XzTEi9bGTWZcv+u19Y6Fg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:29 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 14/17] firewire: core: use guard macro to maintain properties of fw_card Date: Mon, 5 Aug 2024 17:54:05 +0900 Message-ID: <20240805085408.251763-15-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 E00BF1509B3 for ; Mon, 5 Aug 2024 08:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848074; cv=none; b=YACdE4d3WCEQ0hmMqhWFf6bfWIIIVjha8bJNlr58brNqFxw388K2RkC795VI7Je+f0wAx+TtHQpFxAXf8xJE87xzM6xsrS2fdvGgrYrOPzVkWPALyXbugP9siPpxcflW6YKb15wbogesyrJXTbwX3DrgN0I+Hf4VlCRRF13oNEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848074; c=relaxed/simple; bh=SYjPXH2iD1U1cMCRf7nypmxIm+fUZop8Ce0hqIrOg30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=djoerRjEG0PEycau6ns6OvpSuGIyyXfh8NSyBTTUwzf1J38sXH1na5+Q5ZbPxdWM0EUU5BZ1JzkhH8On311qYSuFZkKEP5e7Nk+2x43bMw2bvTeu+vebewAAlmj90srU6sJroS751DL47ICnDYv2GL2r9O/FisugcOCxOmR1Zk8= 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=UUWVPq4R; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=T6KwmugR; arc=none smtp.client-ip=103.168.172.155 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="UUWVPq4R"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="T6KwmugR" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 2050E1151C9F; Mon, 5 Aug 2024 04:54:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 05 Aug 2024 04:54: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=1722848072; x= 1722934472; bh=bU5KUiELPtrWttit1O/f/6nD4P98n+MP8Do0wq0HKos=; b=U UWVPq4RhDGuoy+6iLlfbjECLslTp4D+cpXH4gh+uzXBd3sd49MXiYresZR2rAt7U Ua3M8mTVJTcEI57T4VRNkKBBK4EY4ECo+1A9AjZwsTDbZT+9hUjD/XkWq4Howa+7 JAs9HVr4G8Ai2YYtkuLaYuWI5HMsCea/WAoTucRZm5WSGxgNtb4WnK+oyYI0qveK 8I1f9aXqX1m2j/fZ6ClDLqYcdlMT84FwpNaunzOfO05kmkHkpB5OKd8lNSj1REQl kSG+Y6MiuaLPYQF7yQmHydzAwBGyDFx7MLO7An8Ey3z1tKY3bcP1u0ve3hQfc2Mj EiZlZ1x4EPCHBtFUh59KQ== 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=1722848072; x= 1722934472; bh=bU5KUiELPtrWttit1O/f/6nD4P98n+MP8Do0wq0HKos=; b=T 6KwmugROEJoY7e7AddtH/VGvfrbtzCCMq338ggrDLwfQhQarRNzF1L28vTBeqmBS Z6juhpiLZt34+ZAovOPVi1L4rHyfNP76kpDUlrqEcoksILCt6dB9sq0vpyWtaqwt QlAaH9mktITsDjkuwaseVz6XvMCBkszJYEUh42vL/rdhIQKDUmjTdXouoeW6hvSA MZvyr5nv4/OE7rZ6/o5K9Qw+Q6BXr9JmG8r8VAqP6pSrKNJROmZg0B2nZ+MDEt9l /ekEDb2N+j/o+lOqA8jKTpPUq0PGprta0sYOPWJGZwJs8ITEpiPYYHPpMiW2zfly w78D8PL58q8HaAMDAWq2Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepgeenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:31 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 15/17] firewire: ohci: use guard macro to maintain bus time Date: Mon, 5 Aug 2024 17:54:06 +0900 Message-ID: <20240805085408.251763-16-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 1394 OHCI driver 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 Fri Dec 19 19:21:41 2025 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 19827157499 for ; Mon, 5 Aug 2024 08:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848075; cv=none; b=RZoq23SHyJGItgk9lLstVdtuadvyhGypWf4Wv4i9dkSPeFZFtZ897XnAuQleKWgQ7dt8P09IpbpFIYy/PB5NBJqewPMwAPaORtbxbqv9Ey3WsgZkzcwL4CvLvZF7YswAqHxBI62I+f+2K0iYhBZDRdyjr7aCnvmLEl5QVCDYaKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848075; c=relaxed/simple; bh=RQbpBuuhcdVRrS45TXow3FvE3qGBFt8WbWvDlTvxDVc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vCuASfazn6P3UAlRSKj8UxolNTFU0nDW/yTm/EU7SjGbWccOMjrqGjOwpVJGQlwVigFns9zI4cYueDv4KZYF67qxoyIEENY5PhfqT3wAAx1WGErA0xIVw7KcvSTuyfqgMzS+AesTlCmLxgDyQviXRgH1l/0vQVBBpuQKquiHqYs= 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=kl9oVQ4V; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nOORla6/; arc=none smtp.client-ip=103.168.172.155 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="kl9oVQ4V"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nOORla6/" Received: from compute8.internal (compute8.nyi.internal [10.202.2.227]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7053D1146CF3; Mon, 5 Aug 2024 04:54:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute8.internal (MEProxy); Mon, 05 Aug 2024 04:54: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=1722848073; x= 1722934473; bh=oi4YF8S7QF5qtDuzwiUeYwReqaCDQcNumgOf6dEv5Us=; b=k l9oVQ4VWf1ZHKtR0U7bspOKPvUuIK3Ja/mN0JRyMimU+xEtseMtDqLXY8BbFd+tK Iuth4xSawSPSYlR4nXtcSme4jxpsCqsh/47Gc3aJS3jQQYyNyTD2btRnm9QpBbaI djfD7Phe1EPN7o/cXG4xvKW+M23RaE3bh//lCLu6t6v++ft/b0Vzl4xosbk9jCFI ehTrCh44rbKQVehwfBu1mY+ZM+Nh++GpSIq9FEHaheZ0PcJA8H0jG80YklIas63A Qy4EDw7X83he71SpUB7cYNz/IJvUG6URnKrgp0B32LlQ13KRDhtIqKkswnFdXpmN hwpL8+qbm2YbAqr3TUDvg== 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=1722848073; x= 1722934473; bh=oi4YF8S7QF5qtDuzwiUeYwReqaCDQcNumgOf6dEv5Us=; b=n OORla6/K40B/DPuFMbzSUFrvxuUZEX/hpNaRLwU2Kj1qBWGWxtpozzj28rvhWrIS L85NuDNt0nnOXb7hcTU4PRksfvPm504psELLvv0lGoYcGXnlNmaKvfMcrEMUIQyX Fkae2nYJa94XtzK3Q9c9EpoSbMcTgNJId9TG0BxuhKip7Wh+JHIvxS+IJV6WqYwC dPMeQGvDdbHTk6pI7Db+rzgkrhGykP3pEfhmU1TcjRVPnRBNDWtfgOAGspX/nqTc 34FCYYeSYfSmgDEgp7VJTjaJJLqT3Am5hmEUfpFJ2x80/SpYXt1Z69g6QNoFZIXi vw++aPf+T9crzrcRXLvmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:32 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 16/17] firewire: ohci: use guard macro to maintain image of configuration ROM Date: Mon, 5 Aug 2024 17:54:07 +0900 Message-ID: <20240805085408.251763-17-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 1394 OHCI driver uses spinlock 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 Fri Dec 19 19:21:41 2025 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EBA31581F7 for ; Mon, 5 Aug 2024 08:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848077; cv=none; b=jDIcHRrQNZ+vNsg/BkD8TlKg97RpETGqJG0cIK5EeuHzxywflM3ahClWEioc9/QW0pHH3A6wVC6eQpnScsRvsT6UFZgYwvzVzLkM3Be4F7MA1skziJ0MNvyCHMwR4+ER398gxWpLUuFbmf5A1F2dOGfEctxyJrYVLb9Ml1QyOn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722848077; c=relaxed/simple; bh=svBF9jtACmNy7W1IHbAFhFQHdueMPV/of/FXrm7txro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fjlsILxQ9pkBvFVXqpdopFyKb6mRCqhozvPLCPJXZF6TEpIB+d16SvAWWrT/stdDayZt7Cdd4VpCgJxY++GgbZwHXAmJN1muX17rMbSsdX34cQnVoaJCF75/aBqOC7AZqmHHEeYY8zYPmV0cIlNFmfJZJClqNCZV19C4uXNIgUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b=RgVEt70r; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uAXVTM86; arc=none smtp.client-ip=103.168.172.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="RgVEt70r"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uAXVTM86" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id C01D5138FDBC; Mon, 5 Aug 2024 04:54:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 05 Aug 2024 04:54:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1722848074; x= 1722934474; bh=kdsG2PJz0GJocG9ZLnehQX7pZUw+tAe5s31sau+KXtk=; b=R gVEt70rTfS1JwNrhu5vYJEx+jHTnuzPXV8NZNG0z8dC1D0se7MN/u+SJ5PNbx1UD e1pTdSLchBbetska/vHtAu5K3VPwOqOAhRrSimrtyRXlm8co0/GG81EgMzAhsqyx LdGjFfnjpfwgEUhn/d6I+FOI7y9A+AJggL05NeNZRrVNFTOSPEiio/4+0wy1+Jk4 kKZLGfs+r0zwAYV6krnKa6Q+BnHw1bgHkMI+kA6klaf5pxehoHe76JwQZdu7ogSd ZZeH7YTJN4HM1Y4lJkaucdSiXdUmGzYT73kKq+WAS7TmNybwD0DC+HaRAn8vf+/k UhgFc/qF5PPhlz3kfpWaA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1722848074; x= 1722934474; bh=kdsG2PJz0GJocG9ZLnehQX7pZUw+tAe5s31sau+KXtk=; b=u AXVTM86HIotktWfkHbSJ3ErlRO6Mt2xXP/rYheQdXSnZDWQ/VTMWnhzd+lgZaC8o fqI7xBFlSFKM303D/m5Ws5S61AIuxLNwdt6UrrQasVga2pBUDnE+DL6YuNh62YFs 6zeReIOHKn2k9P7XTtx5zv42dLGAaVVGaEUD3S8wnvi3bRT17owIC/EsspNdpiXK rdEKRM4mALE3f7VDdewc8mQyfML3llUMgCvHJ+eAMdowOWUdftrC6DbCPxA23j/b aSiviUS6jbtfV4FsLzslm5f0kia2IbXuz+uy/fHZx+aXGz9I9ls/ryOZ0ShklvtK EBzOsDhFmyAxDQaiy7wOQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrkeeigddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepvdejgfejue dvgfduudekleevtefgtdevhfdtffefiefgveeuteffiedvffekvddtnecuvehluhhsthgv rhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihessh grkhgrmhhotggthhhirdhjphdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Aug 2024 04:54:33 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 17/17] firewire: ohci: use guard macro to serialize operations for isochronous contexts Date: Mon, 5 Aug 2024 17:54:08 +0900 Message-ID: <20240805085408.251763-18-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240805085408.251763-1-o-takashi@sakamocchi.jp> References: <20240805085408.251763-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 1394 OHCI driver uses spinlock to serialize operations for isochronous contexts. This commit uses guard macro to maintain the spinlock. Signed-off-by: Takashi Sakamoto --- drivers/firewire/ohci.c | 182 +++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 105 deletions(-) diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c index 368420e4b414..e1d24e0ec991 100644 --- a/drivers/firewire/ohci.c +++ b/drivers/firewire/ohci.c @@ -1173,13 +1173,11 @@ static void context_tasklet(unsigned long data) break; =20 if (old_desc !=3D desc) { - /* If we've advanced to the next buffer, move the - * previous buffer to the free list. */ - unsigned long flags; + // If we've advanced to the next buffer, move the previous buffer to the + // free list. old_desc->used =3D 0; - spin_lock_irqsave(&ctx->ohci->lock, flags); + guard(spinlock_irqsave)(&ctx->ohci->lock); list_move_tail(&old_desc->list, &ctx->buffer_list); - spin_unlock_irqrestore(&ctx->ohci->lock, flags); } ctx->last =3D last; } @@ -2122,14 +2120,12 @@ static void bus_reset_work(struct work_struct *work) return; } =20 - /* FIXME: Document how the locking works. */ - spin_lock_irq(&ohci->lock); - - ohci->generation =3D -1; /* prevent AT packet queueing */ - context_stop(&ohci->at_request_ctx); - context_stop(&ohci->at_response_ctx); - - spin_unlock_irq(&ohci->lock); + // FIXME: Document how the locking works. + scoped_guard(spinlock_irq, &ohci->lock) { + ohci->generation =3D -1; // prevent AT packet queueing + context_stop(&ohci->at_request_ctx); + context_stop(&ohci->at_response_ctx); + } =20 /* * Per OHCI 1.2 draft, clause 7.2.3.3, hardware may leave unsent @@ -2704,7 +2700,6 @@ static int ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation) { struct fw_ohci *ohci =3D fw_ohci(card); - unsigned long flags; int n, ret =3D 0; =20 if (param_remote_dma) @@ -2715,12 +2710,10 @@ static int ohci_enable_phys_dma(struct fw_card *car= d, * interrupt bit. Clear physReqResourceAllBuses on bus reset. */ =20 - spin_lock_irqsave(&ohci->lock, flags); + guard(spinlock_irqsave)(&ohci->lock); =20 - if (ohci->generation !=3D generation) { - ret =3D -ESTALE; - goto out; - } + if (ohci->generation !=3D generation) + return -ESTALE; =20 /* * Note, if the node ID contains a non-local bus ID, physical DMA is @@ -2734,8 +2727,6 @@ static int ohci_enable_phys_dma(struct fw_card *card, reg_write(ohci, OHCI1394_PhyReqFilterHiSet, 1 << (n - 32)); =20 flush_writes(ohci); - out: - spin_unlock_irqrestore(&ohci->lock, flags); =20 return ret; } @@ -3076,55 +3067,53 @@ static struct fw_iso_context *ohci_allocate_iso_con= text(struct fw_card *card, u32 *mask, regs; int index, ret =3D -EBUSY; =20 - spin_lock_irq(&ohci->lock); + scoped_guard(spinlock_irq, &ohci->lock) { + switch (type) { + case FW_ISO_CONTEXT_TRANSMIT: + mask =3D &ohci->it_context_mask; + callback =3D handle_it_packet; + index =3D ffs(*mask) - 1; + if (index >=3D 0) { + *mask &=3D ~(1 << index); + regs =3D OHCI1394_IsoXmitContextBase(index); + ctx =3D &ohci->it_context_list[index]; + } + break; =20 - switch (type) { - case FW_ISO_CONTEXT_TRANSMIT: - mask =3D &ohci->it_context_mask; - callback =3D handle_it_packet; - index =3D ffs(*mask) - 1; - if (index >=3D 0) { - *mask &=3D ~(1 << index); - regs =3D OHCI1394_IsoXmitContextBase(index); - ctx =3D &ohci->it_context_list[index]; - } - break; + case FW_ISO_CONTEXT_RECEIVE: + channels =3D &ohci->ir_context_channels; + mask =3D &ohci->ir_context_mask; + callback =3D handle_ir_packet_per_buffer; + index =3D *channels & 1ULL << channel ? ffs(*mask) - 1 : -1; + if (index >=3D 0) { + *channels &=3D ~(1ULL << channel); + *mask &=3D ~(1 << index); + regs =3D OHCI1394_IsoRcvContextBase(index); + ctx =3D &ohci->ir_context_list[index]; + } + break; =20 - case FW_ISO_CONTEXT_RECEIVE: - channels =3D &ohci->ir_context_channels; - mask =3D &ohci->ir_context_mask; - callback =3D handle_ir_packet_per_buffer; - index =3D *channels & 1ULL << channel ? ffs(*mask) - 1 : -1; - if (index >=3D 0) { - *channels &=3D ~(1ULL << channel); - *mask &=3D ~(1 << index); - regs =3D OHCI1394_IsoRcvContextBase(index); - ctx =3D &ohci->ir_context_list[index]; - } - break; + case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: + mask =3D &ohci->ir_context_mask; + callback =3D handle_ir_buffer_fill; + index =3D !ohci->mc_allocated ? ffs(*mask) - 1 : -1; + if (index >=3D 0) { + ohci->mc_allocated =3D true; + *mask &=3D ~(1 << index); + regs =3D OHCI1394_IsoRcvContextBase(index); + ctx =3D &ohci->ir_context_list[index]; + } + break; =20 - case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: - mask =3D &ohci->ir_context_mask; - callback =3D handle_ir_buffer_fill; - index =3D !ohci->mc_allocated ? ffs(*mask) - 1 : -1; - if (index >=3D 0) { - ohci->mc_allocated =3D true; - *mask &=3D ~(1 << index); - regs =3D OHCI1394_IsoRcvContextBase(index); - ctx =3D &ohci->ir_context_list[index]; + default: + index =3D -1; + ret =3D -ENOSYS; } - break; =20 - default: - index =3D -1; - ret =3D -ENOSYS; + if (index < 0) + return ERR_PTR(ret); } =20 - spin_unlock_irq(&ohci->lock); - - if (index < 0) - return ERR_PTR(ret); - memset(ctx, 0, sizeof(*ctx)); ctx->header_length =3D 0; ctx->header =3D (void *) __get_free_page(GFP_KERNEL); @@ -3146,20 +3135,18 @@ static struct fw_iso_context *ohci_allocate_iso_con= text(struct fw_card *card, out_with_header: free_page((unsigned long)ctx->header); out: - spin_lock_irq(&ohci->lock); - - switch (type) { - case FW_ISO_CONTEXT_RECEIVE: - *channels |=3D 1ULL << channel; - break; + scoped_guard(spinlock_irq, &ohci->lock) { + switch (type) { + case FW_ISO_CONTEXT_RECEIVE: + *channels |=3D 1ULL << channel; + break; =20 - case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: - ohci->mc_allocated =3D false; - break; + case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: + ohci->mc_allocated =3D false; + break; + } + *mask |=3D 1 << index; } - *mask |=3D 1 << index; - - spin_unlock_irq(&ohci->lock); =20 return ERR_PTR(ret); } @@ -3243,14 +3230,13 @@ static void ohci_free_iso_context(struct fw_iso_con= text *base) { struct fw_ohci *ohci =3D fw_ohci(base->card); struct iso_context *ctx =3D container_of(base, struct iso_context, base); - unsigned long flags; int index; =20 ohci_stop_iso(base); context_release(&ctx->context); free_page((unsigned long)ctx->header); =20 - spin_lock_irqsave(&ohci->lock, flags); + guard(spinlock_irqsave)(&ohci->lock); =20 switch (base->type) { case FW_ISO_CONTEXT_TRANSMIT: @@ -3272,38 +3258,29 @@ static void ohci_free_iso_context(struct fw_iso_con= text *base) ohci->mc_allocated =3D false; break; } - - spin_unlock_irqrestore(&ohci->lock, flags); } =20 static int ohci_set_iso_channels(struct fw_iso_context *base, u64 *channel= s) { struct fw_ohci *ohci =3D fw_ohci(base->card); - unsigned long flags; - int ret; =20 switch (base->type) { case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: + { + guard(spinlock_irqsave)(&ohci->lock); =20 - spin_lock_irqsave(&ohci->lock, flags); - - /* Don't allow multichannel to grab other contexts' channels. */ + // Don't allow multichannel to grab other contexts' channels. if (~ohci->ir_context_channels & ~ohci->mc_channels & *channels) { *channels =3D ohci->ir_context_channels; - ret =3D -EBUSY; + return -EBUSY; } else { set_multichannel_mask(ohci, *channels); - ret =3D 0; + return 0; } - - spin_unlock_irqrestore(&ohci->lock, flags); - - break; + } default: - ret =3D -EINVAL; + return -EINVAL; } - - return ret; } =20 #ifdef CONFIG_PM @@ -3573,24 +3550,19 @@ static int ohci_queue_iso(struct fw_iso_context *ba= se, unsigned long payload) { struct iso_context *ctx =3D container_of(base, struct iso_context, base); - unsigned long flags; - int ret =3D -ENOSYS; =20 - spin_lock_irqsave(&ctx->context.ohci->lock, flags); + guard(spinlock_irqsave)(&ctx->context.ohci->lock); + switch (base->type) { case FW_ISO_CONTEXT_TRANSMIT: - ret =3D queue_iso_transmit(ctx, packet, buffer, payload); - break; + return queue_iso_transmit(ctx, packet, buffer, payload); case FW_ISO_CONTEXT_RECEIVE: - ret =3D queue_iso_packet_per_buffer(ctx, packet, buffer, payload); - break; + return queue_iso_packet_per_buffer(ctx, packet, buffer, payload); case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL: - ret =3D queue_iso_buffer_fill(ctx, packet, buffer, payload); - break; + return queue_iso_buffer_fill(ctx, packet, buffer, payload); + default: + return -ENOSYS; } - spin_unlock_irqrestore(&ctx->context.ohci->lock, flags); - - return ret; } =20 static void ohci_flush_queue_iso(struct fw_iso_context *base) --=20 2.43.0