From nobody Mon Feb 9 20:36:46 2026 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 B2AC918A6B0 for ; Mon, 12 Aug 2024 23:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506737; cv=none; b=kELTzo5kK+QPx+cPgGeCz+/+qzTV91p5M1t7FDnr5cWJk+x+OQDqcp1GaD8K85LzI5Tze62wfeJ/DwmeYXbOBmDYyZSOBA6htNfLaW8xc+TdgoldPXRrkih6wIwFGPy+t8qj+mDEh8jSNBnH3H5ZcCdOcdR90xHMVeLTu7rQ0wM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506737; c=relaxed/simple; bh=OndbeOxmzP/dufq0N5DWULRQV8Qz9Vmmhrwj824vVV4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ABb00z90VJPdX2YY4CX8Cx9n/RtaMxCgLuMYC7vuL94R7aoY+msM3tnO5Pl6TpgaUu2M8pchredzNlu5T/J994NPzlr+ofARAFde7ThbOTT7P0hpMe2poK8U65W7+nPzf6gVMGr1dX9ge2suJy9PWSaUypRU+H/Pb4D7jXEPXVo= 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=2lRfy2fo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BA5ismDI; arc=none smtp.client-ip=103.168.172.148 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="2lRfy2fo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BA5ismDI" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id B0DC9138CCDE; Mon, 12 Aug 2024 19:52:14 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Mon, 12 Aug 2024 19:52: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=1723506734; x= 1723593134; bh=hYAgmHW3sPNyEffqeWqwPUE6kfVNpSaXPU2TRDZTgeo=; b=2 lRfy2fo6ZI9gH/XB+QRhqZeuApk/XSjQLH0YGD1S47JXPWnjH3gPLYB9/4f8DCWs IyV+3KLbsnNu1oa4oDoxdt47gBQgQoNZi7qialTNb009k7eqlSgIWKH5p2gPJFSG ebaMbL86MaB9vKn2hLIhiHPtlY+T/OEqM3ZxPxXgqS46PsLSd4Dk6Geh+JP2FLP1 hHoajiGFWaR2QOMMtoz6oZ379SCTdjSem+j06OYRM5DR/bkb/QAbMi3MxM43r/bb K1crR7AWlS0KXzerdPc5O3UN3bIH/Z7pY1zxTkQwT0ButTaaaEdE3mUBf+6EdI1E Z0hu04UCm0mmENd/nwOkg== 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=1723506734; x= 1723593134; bh=hYAgmHW3sPNyEffqeWqwPUE6kfVNpSaXPU2TRDZTgeo=; b=B A5ismDIxYid2WnHTNdIifFtgiXpHKAbXXwhY+8BUBM7H6BuC732qE9dIPW96sTT0 HdlLlWDpkON+Esc/SR/mgNSqeyweuueGX0zvfPB3UHWljABXglyJBUlGT4ZMaXZn Pox9pfkoFz6AGMkAY5Xj/TRlx9jgyVfAzCtE9EZLkYVUuynrDoaVS+rCIOZcWJwy 2ZDXgSXHTnQXg7KJ8XJM5ni8yIG676rG0ZzUWca7ZzZvze4i6JJsv756+LVESoX5 RcbSVcfGSDtag0T/mC1cW34VxwmFB2waHxUeJpdagSyO60Vo1rrz7Ujd7lPr7yrI kr5YWVYM920k6TpPEUesA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghm ohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrg htthgvrhhnpedvjefgjeeuvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdff kedvtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopedv pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvg hlsehlihhsthhsrdhsohhurhgtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhu gidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Aug 2024 19:52:13 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/5] firewire: core: minor code refactoring to release client resource Date: Tue, 13 Aug 2024 08:52:06 +0900 Message-ID: <20240812235210.28458-2-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812235210.28458-1-o-takashi@sakamocchi.jp> References: <20240812235210.28458-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" Current implementation checks and validates the result to find resource entry two times. It is redundant. This commit refactors the redundancy. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index c211bb19c94e..81fdb2be9063 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -512,15 +512,14 @@ static int release_client_resource(struct client *cli= ent, u32 handle, =20 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); - } + return -EINVAL; =20 - if (!(resource && resource->release =3D=3D release)) - return -EINVAL; + resource =3D idr_find(&client->resource_idr, handle); + if (!resource || resource->release !=3D release) + return -EINVAL; + + idr_remove(&client->resource_idr, handle); + } =20 if (return_resource) *return_resource =3D resource; --=20 2.43.0 From nobody Mon Feb 9 20:36:46 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1820C190045 for ; Mon, 12 Aug 2024 23:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506738; cv=none; b=L2hRbWinsvpmyddySuz9djQX4iOx+cVNLKYG2r7UbYIyyct+1jCPkTt23K6S0cXXDmnpwTrv73JToYYTPeUB7Z6uajsNHzvnBIjOr5cYCtMPYmTcMghMM2LX2bavGMsf6dOE5X7SvLPDPyjo8yjzcEoNXHTMB4w3eySWOtK9Uhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506738; c=relaxed/simple; bh=BmYNNHTv8Hiygq2iGMLsf4WXKKE+I2XbSULDmqIS6NU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pYYunbzjJLjQ1QH3L++uvewz7xVazl4wgGKc7govKzkMwrxkLxh4GSc7QZxRr4wefN1wZyMm+vPpLIXz4xkjMh0SsHXpa4cXyGOw9oO19FOP5yUqqZTHM6NzNEzriL2EGjygTFuliVWqIKL1RqiDcYLA7APH2Nq3L1k9mr9sFQ8= 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=YRpE7b6W; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Wgqpdc6N; arc=none smtp.client-ip=103.168.172.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="YRpE7b6W"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Wgqpdc6N" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 14AC41151B5E; Mon, 12 Aug 2024 19:52:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 12 Aug 2024 19:52: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=1723506736; x= 1723593136; bh=yTavZwoWWndaIcFeLmMMJMeYE1jdKFbFedyzqbIcn6U=; b=Y RpE7b6WwckgERmmOHazpf9b0b/oWlE4VaJEKD32CyfRQymLlTKit7VfZC+TM+Mi/ OZypy4b+BsjMYCk6Gqs8q/Dh1QqbF6SRhsCbCKfs4JOnYSnJUyuRAKUUgosrQt/0 qJAzLmqdpZvt4gPUJbHoviS4Vk+48JEgn3J/EGNH44hbVjtKTjVK2QRXE6gWt2Uq MEtRjjX+hLPpwM0rNzvFTqhm7/pvAm5MS1kjUarUkdukQM07LnZs6MOQeKbCQqxc PeUcwV03OVEomV/AiSrK+NdtDlIJzoixM1FR5DBecNEvu7ydy/p6JqxtXdJ4s7uW 5W2GQSBKgd6a/mRt2l2hA== 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=1723506736; x= 1723593136; bh=yTavZwoWWndaIcFeLmMMJMeYE1jdKFbFedyzqbIcn6U=; b=W gqpdc6NMIHIyLw1ig8F0MckPo2efB+yDt+E8XybJV9cjOCue4OGQD1OkczR9GFdg P3Ts6tWtjQKSzHPeUhsueqGXTYGk3jaaguMsS/4pczzGoahsRrhAacu1jkdwzvFt G5ryCS81fCm+18hW/59VSud9Yz1uHc6Epeyefjc0cf6HkBFXd9zeJr54FcwZV8vw eswQDPMCAJcW5lRHDU6LlmvBtUMUGy0S/AdaqQInaNf+DcKBBX8nNk8sA+ij05dM BmttuPXGLOUOHWecsYhYTTYWeweHoAU60nUV7XES5ZbZ7VzFUVzesQ/FxJZLNti8 dmCoTqGtEx0oSIhjPLlyw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghm ohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrg htthgvrhhnpedvjefgjeeuvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdff kedvtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopedv pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvg hlsehlihhsthhsrdhsohhurhgtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhu gidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Aug 2024 19:52:14 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/5] firewire: core: add helper functions to convert to parent resource structure Date: Tue, 13 Aug 2024 08:52:07 +0900 Message-ID: <20240812235210.28458-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812235210.28458-1-o-takashi@sakamocchi.jp> References: <20240812235210.28458-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" All of local resource structure commonly have data of client_resource type in its first member. This design sometimes requires usage of container_of to retrieve parent structure by the first member. This commit adds some helper functions for this purpose. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 38 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 81fdb2be9063..e72f91cc3711 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -139,6 +139,26 @@ struct iso_resource { struct iso_resource_event *e_alloc, *e_dealloc; }; =20 +static struct address_handler_resource *to_address_handler_resource(struct= client_resource *resource) +{ + return container_of(resource, struct address_handler_resource, resource); +} + +static struct inbound_transaction_resource *to_inbound_transaction_resourc= e(struct client_resource *resource) +{ + return container_of(resource, struct inbound_transaction_resource, resour= ce); +} + +static struct descriptor_resource *to_descriptor_resource(struct client_re= source *resource) +{ + return container_of(resource, struct descriptor_resource, resource); +} + +static struct iso_resource *to_iso_resource(struct client_resource *resour= ce) +{ + return container_of(resource, struct iso_resource, resource); +} + static void release_iso_resource(struct client *, struct client_resource *= ); =20 static void schedule_iso_resource(struct iso_resource *r, unsigned long de= lay) @@ -151,8 +171,7 @@ static void schedule_iso_resource(struct iso_resource *= r, unsigned long delay) static void schedule_if_iso_resource(struct client_resource *resource) { if (resource->release =3D=3D release_iso_resource) - schedule_iso_resource(container_of(resource, - struct iso_resource, resource), 0); + schedule_iso_resource(to_iso_resource(resource), 0); } =20 /* @@ -682,8 +701,7 @@ static int ioctl_send_request(struct client *client, un= ion ioctl_arg *arg) static void release_request(struct client *client, struct client_resource *resource) { - struct inbound_transaction_resource *r =3D container_of(resource, - struct inbound_transaction_resource, resource); + struct inbound_transaction_resource *r =3D to_inbound_transaction_resourc= e(resource); =20 if (r->is_fcp) fw_request_put(r->request); @@ -793,8 +811,7 @@ static void handle_request(struct fw_card *card, struct= fw_request *request, static void release_address_handler(struct client *client, struct client_resource *resource) { - struct address_handler_resource *r =3D - container_of(resource, struct address_handler_resource, resource); + struct address_handler_resource *r =3D to_address_handler_resource(resour= ce); =20 fw_core_remove_address_handler(&r->handler); kfree(r); @@ -858,8 +875,7 @@ static int ioctl_send_response(struct client *client, u= nion ioctl_arg *arg) release_request, &resource) < 0) return -EINVAL; =20 - r =3D container_of(resource, struct inbound_transaction_resource, - resource); + r =3D to_inbound_transaction_resource(resource); if (r->is_fcp) { fw_request_put(r->request); goto out; @@ -893,8 +909,7 @@ static int ioctl_initiate_bus_reset(struct client *clie= nt, union ioctl_arg *arg) static void release_descriptor(struct client *client, struct client_resource *resource) { - struct descriptor_resource *r =3D - container_of(resource, struct descriptor_resource, resource); + struct descriptor_resource *r =3D to_descriptor_resource(resource); =20 fw_core_remove_descriptor(&r->descriptor); kfree(r); @@ -1387,8 +1402,7 @@ static void iso_resource_work(struct work_struct *wor= k) static void release_iso_resource(struct client *client, struct client_resource *resource) { - struct iso_resource *r =3D - container_of(resource, struct iso_resource, resource); + struct iso_resource *r =3D to_iso_resource(resource); =20 guard(spinlock_irq)(&client->lock); =20 --=20 2.43.0 From nobody Mon Feb 9 20:36:46 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1659319A2A8 for ; Mon, 12 Aug 2024 23:52:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506739; cv=none; b=GlOfu49CFgrutnAFWtYkwDF51DUXoBKzNv39432UiKsOTUtjX4DTPRComeBeXvOmnp34KcJAFbKrI13EYiq8BMmuJRos0srACZ6dgyWQnms3jhWearuCPjfXtNzQshAVWB13s3EIOqrAhwdQNxetUe7mCeAruSQiwRS9hEl/Wzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506739; c=relaxed/simple; bh=SpFGBLIbLQB/bD48Q4t0kgiqOP6/LXv8rODlIjG1qM0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NIBbx1s1TdOxDV8LmfdeJP6tEgcaNSmz5hh0CnSWtb4ctX/2ucZGrZ/BYAn/WSI4NPdQ8rOJK6SDuoUffXBjpa+RNzUY9sCs+Ftc2h5l7FDQo9QEeb8XfiwJQw4KdonX6UeHDfmevgTY3wWtYEwhsQAE8le3c50YAwOynsb636g= 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=wGsIIMOH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YlPHK8RL; arc=none smtp.client-ip=103.168.172.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="wGsIIMOH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YlPHK8RL" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 5FB721151AD8; Mon, 12 Aug 2024 19:52:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 12 Aug 2024 19:52: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=1723506737; x= 1723593137; bh=Kh9i0JPlzid5BWuq583j3AOPTE1mAiuU5Or9KJgOb3o=; b=w GsIIMOHF5FK5H2GlsoUKvFaD0nhKCODOrnGNWNx4flm3lkyBrvZwGXRwiLmQH63h bynUJQqGOP6edJx8tO6MmNwe7sM76HufChB/tlZp9kiuVTn4c689TxwfMXhHjTW4 93liREkkbdrzvGFleZi4E0FE7ymHH2TFrcNXHXvKkL50W/u7XBiT9TVugBp+/N8W ETOvJSGB8Ws0jWyJsvKkaTVUCe2/XKM+PwDJ3xZwunRKRXGQaSv9owypONWVbtCj nnU5FoTKz46j2D7faTb70W4JAaGda94QmtCWtDqPf+evxMOwrt+JEH6YnQXIx1dt dj905UxNwsilESG2kgPJw== 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=1723506737; x= 1723593137; bh=Kh9i0JPlzid5BWuq583j3AOPTE1mAiuU5Or9KJgOb3o=; b=Y lPHK8RLjsxRbrJp5YRv6Opse/RaZM5VaJuNuUfKd6jZPOgABdqq6CUjy674Zo3rm irfE4l51TX9LI4o/L6lily8A+9owyIruAEWmqpOy4IUb7wAvjKrAz0Ryb2lg/AAw vCO7GsPio5caJaxb2JUuLnCecG9L0hNR7rhiuOOZa10FgrA5exoigizAdR0hkAY+ Ilvhqxcp39xzEuQSO1FbeYNSU/158qqtq2TMqnzbfOFA5QONSpYI7FAhZtZpaAZe B/P0Pf5oe/N8m2eWATuASgAhMFoLGsRioNVa7Pnb+RUhK784t6zfWJzW21KTTr1d LoWiy7cWMuQjy9JAcSLZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghm ohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrg htthgvrhhnpedvjefgjeeuvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdff kedvtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopedv pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvg hlsehlihhsthhsrdhsohhurhgtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhu gidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Aug 2024 19:52:16 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/5] firewire: core: add helper function to detect data of iso resource structure Date: Tue, 13 Aug 2024 08:52:08 +0900 Message-ID: <20240812235210.28458-4-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812235210.28458-1-o-takashi@sakamocchi.jp> References: <20240812235210.28458-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" It depends on the function assigned to release member to identify resource structure. This commit adds a helper function to identify iso_resource structure. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index e72f91cc3711..6fe2a2ea9869 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -161,6 +161,11 @@ static struct iso_resource *to_iso_resource(struct cli= ent_resource *resource) =20 static void release_iso_resource(struct client *, struct client_resource *= ); =20 +static int is_iso_resource(const struct client_resource *resource) +{ + return resource->release =3D=3D release_iso_resource; +} + static void schedule_iso_resource(struct iso_resource *r, unsigned long de= lay) { client_get(r->client); @@ -170,7 +175,7 @@ static void schedule_iso_resource(struct iso_resource *= r, unsigned long delay) =20 static void schedule_if_iso_resource(struct client_resource *resource) { - if (resource->release =3D=3D release_iso_resource) + if (is_iso_resource(resource)) schedule_iso_resource(to_iso_resource(resource), 0); } =20 --=20 2.43.0 From nobody Mon Feb 9 20:36:46 2026 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 9DB3919AD70 for ; Mon, 12 Aug 2024 23:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506741; cv=none; b=QyGopoNnZ4qPIuP856TyV3HvUde7hz/u+cusIJ/ZxOOZCKt+VpV5ABk90Z850YRXnogcyb/fxu2rRUAXvCtp7m0PtgMej+MY3KG8toH1If1ERm449SUjelTYcO+Sh3QhdooSyrWBZYpw2RTm/igTrl+QrqhTSslJ+RJiMhX/XUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506741; c=relaxed/simple; bh=7gZaV1NwIDtvHlJpJ3V3qGuEELjev6bzXIvy3ZTuFBA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pqx51hSq1jCelIVnxOncLxb0FYhHjYxqMe7HtMXNhoTv6KBVzUsA4k9DZt21TNVVZFq4+n/3eh/Jxns+Xbpoq1depZ3EKmZJNCRX70qctU1bSktpeTVZV+a0rNfNHvZbpYTo9JSbONC15c4rnA+3ZGxp4RmI+yMn9cEmXlg6i7g= 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=MX0qAGEs; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=An3p7uOS; arc=none smtp.client-ip=103.168.172.148 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="MX0qAGEs"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="An3p7uOS" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id B6970138FA1B; Mon, 12 Aug 2024 19:52:18 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Mon, 12 Aug 2024 19:52: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=1723506738; x= 1723593138; bh=5bXNDaC24651cPJeU5X4QWrCWjWlUV0d17UsuhjZ27U=; b=M X0qAGEszJA45C513C85LPWSVOb/amHFFVOPVTdQnSib5WEISJnq1EqHVMS8bTBAJ g9/2/plpvuUXod28nnd/b+XU79F3NuNi8+hbksR3X+5JH4aUo+g8vWsJqIcoQm3X CoL4+yGsj3FLDLmH0EzLMCTL7++WWmUxSWezi4a7xQkuZBVUJwLRFnPBTSTWxsYX NVGatZYeiqKzng3XyfI/gqbHVLgEKFnzkM8DsJc43OFi6i1y+f431oMFXod8+vEr lxPMY4QOnztT6Vvjg8KHhVMWQv9CbJxA4QhMQVGZrLgE6ciDnovGR+WVl0QzIACt BYrOwJvMEwCLStedd452w== 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=1723506738; x= 1723593138; bh=5bXNDaC24651cPJeU5X4QWrCWjWlUV0d17UsuhjZ27U=; b=A n3p7uOS1iNgyqjIyhUBTzcgWgYK9+1VSpqWtt7XAhqY+0sCIDNolNjW9bzXge71X 5ZzswPwHEiB16S8d5uDt2IdmoBsgkYHLGgDxv/nrQXjguwnhRLWdelN0WlOfA1Br MhCBDKsUrjidHB3bQ3Ot8338TWQV9FqPJ21tu7CDdGcbbWFCG96UuiQCY0zX7+qf +CLYPMSkNMH6F6QexeuJS41+3SFx8PQOUs6DLaJIm29WAkrLQHDINJlh2F2mmvkX 6u4JkuKHYq+4hBR2aBw4M7E/mWJ4WChRcZ0/MGGB2mvCrOEghZOi1A9OV0OeUWDM IBNmDa0VkAlCbDkvOYB6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghm ohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrg htthgvrhhnpedvjefgjeeuvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdff kedvtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopedv pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvg hlsehlihhsthhsrdhsohhurhgtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhu gidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Aug 2024 19:52:17 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/5] firewire: core: code refactoring to use idr_for_each_entry() macro instead of idr_for_each() function Date: Tue, 13 Aug 2024 08:52:09 +0900 Message-ID: <20240812235210.28458-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812235210.28458-1-o-takashi@sakamocchi.jp> References: <20240812235210.28458-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" This commit is a preparation to use xa_for_each() macro. Current implementation uses idr_for_each() function and has a disadvantage to replace with the macro. The IDR framework has idr_for_each_entry() macro for the similar purpose. This commit replace the function with the macro with minor code refactoring. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 64 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 6fe2a2ea9869..83d25327c1d3 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -166,6 +166,14 @@ static int is_iso_resource(const struct client_resourc= e *resource) return resource->release =3D=3D release_iso_resource; } =20 +static void release_transaction(struct client *client, + struct client_resource *resource); + +static int is_outbound_transaction_resource(const struct client_resource *= resource) +{ + return resource->release =3D=3D release_transaction; +} + static void schedule_iso_resource(struct iso_resource *r, unsigned long de= lay) { client_get(r->client); @@ -173,12 +181,6 @@ static void schedule_iso_resource(struct iso_resource = *r, unsigned long delay) client_put(r->client); } =20 -static void schedule_if_iso_resource(struct client_resource *resource) -{ - if (is_iso_resource(resource)) - schedule_iso_resource(to_iso_resource(resource), 0); -} - /* * dequeue_event() just kfree()'s the event, so the event has to be * the first field in a struct XYZ_event. @@ -401,16 +403,11 @@ static void for_each_client(struct fw_device *device, callback(c); } =20 -static int schedule_reallocations(int id, void *p, void *data) -{ - schedule_if_iso_resource(p); - - return 0; -} - static void queue_bus_reset_event(struct client *client) { struct bus_reset_event *e; + struct client_resource *resource; + int id; =20 e =3D kzalloc(sizeof(*e), GFP_KERNEL); if (e =3D=3D NULL) @@ -423,7 +420,10 @@ static void queue_bus_reset_event(struct client *clien= t) =20 guard(spinlock_irq)(&client->lock); =20 - idr_for_each(&client->resource_idr, schedule_reallocations, client); + idr_for_each_entry(&client->resource_idr, resource, id) { + if (is_iso_resource(resource)) + schedule_iso_resource(to_iso_resource(resource), 0); + } } =20 void fw_device_cdev_update(struct fw_device *device) @@ -518,7 +518,8 @@ static int add_client_resource(struct client *client, if (ret >=3D 0) { resource->handle =3D ret; client_get(client); - schedule_if_iso_resource(resource); + if (is_iso_resource(resource)) + schedule_iso_resource(to_iso_resource(resource), 0); } } =20 @@ -1835,35 +1836,27 @@ static int fw_device_op_mmap(struct file *file, str= uct vm_area_struct *vma) return ret; } =20 -static int is_outbound_transaction_resource(int id, void *p, void *data) +static bool has_outbound_transactions(struct client *client) { - struct client_resource *resource =3D p; - - return resource->release =3D=3D release_transaction; -} + struct client_resource *resource; + int id; =20 -static int has_outbound_transactions(struct client *client) -{ guard(spinlock_irq)(&client->lock); =20 - return idr_for_each(&client->resource_idr, is_outbound_transaction_resour= ce, NULL); -} - -static int shutdown_resource(int id, void *p, void *data) -{ - struct client_resource *resource =3D p; - struct client *client =3D data; - - resource->release(client, resource); - client_put(client); + idr_for_each_entry(&client->resource_idr, resource, id) { + if (is_outbound_transaction_resource(resource)) + return true; + } =20 - return 0; + return false; } =20 static int fw_device_op_release(struct inode *inode, struct file *file) { struct client *client =3D file->private_data; struct event *event, *next_event; + struct client_resource *resource; + int id; =20 scoped_guard(spinlock_irq, &client->device->card->lock) list_del(&client->phy_receiver_link); @@ -1883,7 +1876,10 @@ static int fw_device_op_release(struct inode *inode,= struct file *file) =20 wait_event(client->tx_flush_wait, !has_outbound_transactions(client)); =20 - idr_for_each(&client->resource_idr, shutdown_resource, client); + idr_for_each_entry(&client->resource_idr, resource, id) { + resource->release(client, resource); + client_put(client); + } idr_destroy(&client->resource_idr); =20 list_for_each_entry_safe(event, next_event, &client->event_list, link) --=20 2.43.0 From nobody Mon Feb 9 20:36:46 2026 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0392819ADBB for ; Mon, 12 Aug 2024 23:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506743; cv=none; b=bwflAse7SfkMFQHHO3k2yqDqygO1OKTSAnm8fFe8soyKCYrIF6J4G1a/gztDSa55zn9lYSAcJ6MIma0wM9xsM3HEyOKI1w66bwZwTYrZt7UFSx9hioTrefD3XQLIK1t18yw7aMqq7cMhf0ONNno/i8cd+2+IfWamb8eqkaEBPe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723506743; c=relaxed/simple; bh=kohYd9tWqkktZ/r6GCVdidIRPztYnRzPFgJogqa383E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N2QN6HxUrWEkTfc9k6vNDTN9Bb4QrfjqhHD3IGVsTp93z6AbNC0b5W3nPojYYZ5RdmjpTK1wBgfx3ymt57TFUIkCgqWsOgKwBQVpP4eOrhMbmbnWhrfFKCdX6pBWEhv5A5OjVyHr6onTSAasXZYsniL2YGA5/Zks30Sq41h1b54= 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=Yj+NBlbM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=tgMS1M/1; arc=none smtp.client-ip=103.168.172.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="Yj+NBlbM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="tgMS1M/1" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1BE981151B66; Mon, 12 Aug 2024 19:52:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 12 Aug 2024 19:52: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=1723506740; x= 1723593140; bh=AGCPcXuZ+EA8kPdWP5AdSF60xmqg9P1trpkWAYoUGEs=; b=Y j+NBlbMicM5yraVen81NvyprMxGoB2u/JKxxtxNOoHzRjXV9h1Mr4OvjHyH3qma0 V+TmeOMeJ4VrTyfk0H736ioGrWIlwrCjwkaKYMlu2sdrlRVRsCWRQ+NRYEa15uNb x49iWoKdgOgpftVkrMc9IHLxSOD0NDbbRCQwK9VY5NQWtKHUxGac1wkG2k5zgWdd kKvHKWkUg1LiS/P67b6rPG3lLe7Taz83ys513En5lr1UvdP/Gag3O47+no1mvFF3 a5Hogz9jeRlCykTz3NdG6J9bldnhE4acBktxsQ6YDiHEnYs7Na83rDwoaBTfcX0g O2tWxuPdw26afeKQ9oM8w== 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=1723506740; x= 1723593140; bh=AGCPcXuZ+EA8kPdWP5AdSF60xmqg9P1trpkWAYoUGEs=; b=t gMS1M/1oZ3c+jAsRYbMdyJmoWXICDdDpneYCYRVOTgHspDK7D8RNq+hBvgmgNOoA Y00Nm1mlmWYSHcshavfR+xLbJWVbh3nkHNzy/nrFvHNxkHYKQarC0Rclau5alegQ KKWKwzKo4zgHpyh+DThHX6fV7jYqjrYcRswYcvOYvFu2KaK+uIKftcyJAuXM3OJK LhtPo72IRE/NWIiAgaVITF1yDCC8X9xneZCH+Par/+BIbP4NdAjWArMLk8pETytV 0VhEhuLNRU1ErizdKieHYgkwIR7uKyeE3L8TwDdwVCLOnm3T1gxQULtIuLKNc5wS wuTBimEve7o1o6I8CUnOA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghm ohhtohcuoehoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhpqeenucggtffrrg htthgvrhhnpedvjefgjeeuvdfguddukeelveetgfdtvefhtdfffeeigfevueetffeivdff kedvtdenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpe hoqdhtrghkrghshhhisehsrghkrghmohgttghhihdrjhhppdhnsggprhgtphhtthhopedv pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlihhnuhigudefleegqdguvghvvg hlsehlihhsthhsrdhsohhurhgtvghfohhrghgvrdhnvghtpdhrtghpthhtoheplhhinhhu gidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Aug 2024 19:52:18 -0400 (EDT) From: Takashi Sakamoto To: linux1394-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/5] firewire: core: use xarray instead of idr to maintain client resource Date: Tue, 13 Aug 2024 08:52:10 +0900 Message-ID: <20240812235210.28458-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812235210.28458-1-o-takashi@sakamocchi.jp> References: <20240812235210.28458-1-o-takashi@sakamocchi.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In core function, the instances of some client resource structures are maintained by IDR. As of kernel v6.0, IDR has been superseded by XArray and deprecated. This commit replaces the usage of IDR with XArray to maintain the resource instances. The instance of XArray is allocated per client with XA_FLAGS_ALLOC1 so that the index of allocated entry is greater than zero and returns to user space client as handle of the resource. Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-cdev.c | 66 +++++++++++++++++++----------------- drivers/firewire/core.h | 1 - 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c index 83d25327c1d3..3ea220d96c31 100644 --- a/drivers/firewire/core-cdev.c +++ b/drivers/firewire/core-cdev.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -54,7 +53,7 @@ struct client { =20 spinlock_t lock; bool in_shutdown; - struct idr resource_idr; + struct xarray resource_xa; struct list_head event_list; wait_queue_head_t wait; wait_queue_head_t tx_flush_wait; @@ -297,7 +296,7 @@ static int fw_device_op_open(struct inode *inode, struc= t file *file) =20 client->device =3D device; spin_lock_init(&client->lock); - idr_init(&client->resource_idr); + xa_init_flags(&client->resource_xa, XA_FLAGS_ALLOC1 | XA_FLAGS_LOCK_BH); INIT_LIST_HEAD(&client->event_list); init_waitqueue_head(&client->wait); init_waitqueue_head(&client->tx_flush_wait); @@ -407,7 +406,7 @@ static void queue_bus_reset_event(struct client *client) { struct bus_reset_event *e; struct client_resource *resource; - int id; + unsigned long index; =20 e =3D kzalloc(sizeof(*e), GFP_KERNEL); if (e =3D=3D NULL) @@ -420,7 +419,7 @@ static void queue_bus_reset_event(struct client *client) =20 guard(spinlock_irq)(&client->lock); =20 - idr_for_each_entry(&client->resource_idr, resource, id) { + xa_for_each(&client->resource_xa, index, resource) { if (is_iso_resource(resource)) schedule_iso_resource(to_iso_resource(resource), 0); } @@ -501,31 +500,33 @@ static int ioctl_get_info(struct client *client, unio= n ioctl_arg *arg) return ret ? -EFAULT : 0; } =20 -static int add_client_resource(struct client *client, - struct client_resource *resource, gfp_t gfp_mask) +static int add_client_resource(struct client *client, struct client_resour= ce *resource, + gfp_t gfp_mask) { - bool preload =3D gfpflags_allow_blocking(gfp_mask); int ret; =20 - if (preload) - idr_preload(gfp_mask); - scoped_guard(spinlock_irqsave, &client->lock) { - if (client->in_shutdown) + u32 index; + + if (client->in_shutdown) { ret =3D -ECANCELED; - else - ret =3D idr_alloc(&client->resource_idr, resource, 0, 0, GFP_NOWAIT); + } else { + if (gfpflags_allow_blocking(gfp_mask)) { + ret =3D xa_alloc(&client->resource_xa, &index, resource, xa_limit_32b, + GFP_NOWAIT); + } else { + ret =3D xa_alloc_bh(&client->resource_xa, &index, resource, + xa_limit_32b, GFP_NOWAIT); + } + } if (ret >=3D 0) { - resource->handle =3D ret; + resource->handle =3D index; client_get(client); if (is_iso_resource(resource)) schedule_iso_resource(to_iso_resource(resource), 0); } } =20 - if (preload) - idr_preload_end(); - return ret < 0 ? ret : 0; } =20 @@ -533,17 +534,18 @@ static int release_client_resource(struct client *cli= ent, u32 handle, client_resource_release_fn_t release, struct client_resource **return_resource) { + unsigned long index =3D handle; struct client_resource *resource; =20 scoped_guard(spinlock_irq, &client->lock) { if (client->in_shutdown) return -EINVAL; =20 - resource =3D idr_find(&client->resource_idr, handle); + resource =3D xa_load(&client->resource_xa, index); if (!resource || resource->release !=3D release) return -EINVAL; =20 - idr_remove(&client->resource_idr, handle); + xa_erase(&client->resource_xa, handle); } =20 if (return_resource) @@ -566,9 +568,10 @@ 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 index =3D e->r.resource.handle; =20 scoped_guard(spinlock_irqsave, &client->lock) { - idr_remove(&client->resource_idr, e->r.resource.handle); + xa_erase(&client->resource_xa, index); if (client->in_shutdown) wake_up(&client->tx_flush_wait); } @@ -619,7 +622,7 @@ static void complete_transaction(struct fw_card *card, = int rcode, u32 request_ts break; } =20 - /* Drop the idr's reference */ + // Drop the xarray's reference. client_put(client); } =20 @@ -1317,6 +1320,7 @@ static void iso_resource_work(struct work_struct *wor= k) struct iso_resource *r =3D container_of(work, struct iso_resource, work.work); struct client *client =3D r->client; + unsigned long index =3D r->resource.handle; int generation, channel, bandwidth, todo; bool skip, free, success; =20 @@ -1351,7 +1355,7 @@ static void iso_resource_work(struct work_struct *wor= k) todo =3D=3D ISO_RES_ALLOC_ONCE); /* * Is this generation outdated already? As long as this resource sticks - * in the idr, it will be scheduled again for a newer generation or at + * in the xarray, it will be scheduled again for a newer generation or at * shutdown. */ if (channel =3D=3D -EAGAIN && @@ -1366,10 +1370,10 @@ static void iso_resource_work(struct work_struct *w= ork) 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. + // xarray 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)) { + xa_erase(&client->resource_xa, index)) { client_put(client); free =3D true; } @@ -1839,11 +1843,11 @@ static int fw_device_op_mmap(struct file *file, str= uct vm_area_struct *vma) static bool has_outbound_transactions(struct client *client) { struct client_resource *resource; - int id; + unsigned long index; =20 guard(spinlock_irq)(&client->lock); =20 - idr_for_each_entry(&client->resource_idr, resource, id) { + xa_for_each(&client->resource_xa, index, resource) { if (is_outbound_transaction_resource(resource)) return true; } @@ -1856,7 +1860,7 @@ static int fw_device_op_release(struct inode *inode, = struct file *file) struct client *client =3D file->private_data; struct event *event, *next_event; struct client_resource *resource; - int id; + unsigned long index; =20 scoped_guard(spinlock_irq, &client->device->card->lock) list_del(&client->phy_receiver_link); @@ -1870,17 +1874,17 @@ static int fw_device_op_release(struct inode *inode= , struct file *file) if (client->buffer.pages) fw_iso_buffer_destroy(&client->buffer, client->device->card); =20 - /* Freeze client->resource_idr and client->event_list */ + // Freeze client->resource_xa and client->event_list. scoped_guard(spinlock_irq, &client->lock) client->in_shutdown =3D true; =20 wait_event(client->tx_flush_wait, !has_outbound_transactions(client)); =20 - idr_for_each_entry(&client->resource_idr, resource, id) { + xa_for_each(&client->resource_xa, index, resource) { resource->release(client, resource); client_put(client); } - idr_destroy(&client->resource_idr); + xa_destroy(&client->resource_xa); =20 list_for_each_entry_safe(event, next_event, &client->event_list, link) kfree(event); diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index 8cace026090c..57d101c01e36 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include --=20 2.43.0