Commit 3593b38a authored by Takashi Sakamoto's avatar Takashi Sakamoto

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.jpSigned-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
parent 9b6ad6a0
...@@ -39,7 +39,7 @@ static struct fw_node *fw_node_create(u32 sid, int port_count, int color) ...@@ -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->initiated_reset = phy_packet_self_id_zero_get_initiated_reset(sid);
node->port_count = port_count; node->port_count = port_count;
refcount_set(&node->ref_count, 1); kref_init(&node->kref);
INIT_LIST_HEAD(&node->link); INIT_LIST_HEAD(&node->link);
return node; return node;
......
...@@ -183,7 +183,8 @@ struct fw_node { ...@@ -183,7 +183,8 @@ struct fw_node {
* local node to this node. */ * local node to this node. */
u8 max_depth:4; /* Maximum depth to any leaf node */ u8 max_depth:4; /* Maximum depth to any leaf node */
u8 max_hops:4; /* Max hops in this sub tree */ u8 max_hops:4; /* Max hops in this sub tree */
refcount_t ref_count;
struct kref kref;
/* For serializing node topology into a list. */ /* For serializing node topology into a list. */
struct list_head link; struct list_head link;
...@@ -196,17 +197,23 @@ struct fw_node { ...@@ -196,17 +197,23 @@ struct fw_node {
static inline struct fw_node *fw_node_get(struct fw_node *node) static inline struct fw_node *fw_node_get(struct fw_node *node)
{ {
refcount_inc(&node->ref_count); kref_get(&node->kref);
return node; return node;
} }
static inline void fw_node_put(struct fw_node *node) static void release_node(struct kref *kref)
{ {
if (refcount_dec_and_test(&node->ref_count)) struct fw_node *node = container_of(kref, struct fw_node, kref);
kfree(node); kfree(node);
} }
static inline void fw_node_put(struct fw_node *node)
{
kref_put(&node->kref, release_node);
}
void fw_core_handle_bus_reset(struct fw_card *card, int node_id, void fw_core_handle_bus_reset(struct fw_card *card, int node_id,
int generation, int self_id_count, u32 *self_ids, bool bm_abdicate); int generation, int self_id_count, u32 *self_ids, bool bm_abdicate);
void fw_destroy_nodes(struct fw_card *card); void fw_destroy_nodes(struct fw_card *card);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment