Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+12 -5
+1 -1
drivers/firewire/core-topology.c
··· 39 39 node->initiated_reset = phy_packet_self_id_zero_get_initiated_reset(sid); 40 40 node->port_count = port_count; 41 41 42 - refcount_set(&node->ref_count, 1); 42 + kref_init(&node->kref); 43 43 INIT_LIST_HEAD(&node->link); 44 44 45 45 return node;
+11 -4
drivers/firewire/core.h
··· 183 183 * local node to this node. */ 184 184 u8 max_depth:4; /* Maximum depth to any leaf node */ 185 185 u8 max_hops:4; /* Max hops in this sub tree */ 186 - refcount_t ref_count; 186 + 187 + struct kref kref; 187 188 188 189 /* For serializing node topology into a list. */ 189 190 struct list_head link; ··· 197 196 198 197 static inline struct fw_node *fw_node_get(struct fw_node *node) 199 198 { 200 - refcount_inc(&node->ref_count); 199 + kref_get(&node->kref); 201 200 202 201 return node; 203 202 } 204 203 204 + static void release_node(struct kref *kref) 205 + { 206 + struct fw_node *node = container_of(kref, struct fw_node, kref); 207 + 208 + kfree(node); 209 + } 210 + 205 211 static inline void fw_node_put(struct fw_node *node) 206 212 { 207 - if (refcount_dec_and_test(&node->ref_count)) 208 - kfree(node); 213 + kref_put(&node->kref, release_node); 209 214 } 210 215 211 216 void fw_core_handle_bus_reset(struct fw_card *card, int node_id,