diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2024-08-01 11:26:29 +0900 |
---|---|---|
committer | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2024-08-01 11:26:29 +0900 |
commit | 3593b38a1367c3b57e986b0d2a9b6ceb84ec44ce (patch) | |
tree | c83a8344c6b6a116c8c22dfaedbd45dd4f9d60f4 /drivers/firewire/core.h | |
parent | 9b6ad6a0115e9a35da65abdc973b80539f983c26 (diff) |
firewire: core: utilize kref to maintain fw_node with reference counting
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.
Link: https://lore.kernel.org/r/20240801022629.31857-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Diffstat (limited to 'drivers/firewire/core.h')
-rw-r--r-- | drivers/firewire/core.h | 15 |
1 files changed, 11 insertions, 4 deletions
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, |