From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: linux1394-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] firewire: core: utilize kref to maintain fw_node with reference counting
Date: Fri, 2 Aug 2024 08:29:38 +0900 [thread overview]
Message-ID: <20240801232938.GA58901@workstation.local> (raw)
In-Reply-To: <20240801022629.31857-1-o-takashi@sakamocchi.jp>
On Thu, Aug 01, 2024 at 11:26:29AM +0900, Takashi Sakamoto wrote:
> Current implementation directly uses refcount_t to maintain the life time
> of fw_node, while kref is available for the same purpose.
>
> This commit replaces the implementation with kref.
>
> Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> ---
> drivers/firewire/core-topology.c | 2 +-
> drivers/firewire/core.h | 15 +++++++++++----
> 2 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topology.c
> index b4e637aa6932..46e6eb287d24 100644
> --- a/drivers/firewire/core-topology.c
> +++ b/drivers/firewire/core-topology.c
> @@ -39,7 +39,7 @@ static struct fw_node *fw_node_create(u32 sid, int port_count, int color)
> node->initiated_reset = phy_packet_self_id_zero_get_initiated_reset(sid);
> node->port_count = port_count;
>
> - refcount_set(&node->ref_count, 1);
> + kref_init(&node->kref);
> INIT_LIST_HEAD(&node->link);
>
> return node;
> diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
> index 7c36d2628e37..189e15e6ba82 100644
> --- a/drivers/firewire/core.h
> +++ b/drivers/firewire/core.h
> @@ -183,7 +183,8 @@ struct fw_node {
> * local node to this node. */
> u8 max_depth:4; /* Maximum depth to any leaf node */
> u8 max_hops:4; /* Max hops in this sub tree */
> - refcount_t ref_count;
> +
> + struct kref kref;
>
> /* For serializing node topology into a list. */
> struct list_head link;
> @@ -196,15 +197,21 @@ struct fw_node {
>
> static inline struct fw_node *fw_node_get(struct fw_node *node)
> {
> - refcount_inc(&node->ref_count);
> + kref_get(&node->kref);
>
> return node;
> }
>
> +static void release_node(struct kref *kref)
> +{
> + struct fw_node *node = container_of(kref, struct fw_node, kref);
> +
> + kfree(node);
> +}
> +
> static inline void fw_node_put(struct fw_node *node)
> {
> - if (refcount_dec_and_test(&node->ref_count))
> - kfree(node);
> + kref_put(&node->kref, release_node);
> }
>
> void fw_core_handle_bus_reset(struct fw_card *card, int node_id,
Applied to for-next branch.
Regards
Takashi Sakamoto
prev parent reply other threads:[~2024-08-01 23:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-01 2:26 [PATCH] firewire: core: utilize kref to maintain fw_node with reference counting Takashi Sakamoto
2024-08-01 23:29 ` Takashi Sakamoto [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240801232938.GA58901@workstation.local \
--to=o-takashi@sakamocchi.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux1394-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox