Skip to content

Commit 392910c

Browse files
ereshetovagregkh
authored andcommitted
drivers, firewire: convert fw_node.ref_count from atomic_t to refcount_t
refcount_t type and corresponding API should be used instead of atomic_t when the variable is used as a reference counter. This allows to avoid accidental refcounter overflows that might lead to use-after-free situations. Signed-off-by: Elena Reshetova <elena.reshetova@intel.com> Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: David Windsor <dwindsor@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f7d88d2 commit 392910c

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎drivers/firewire/core-topology.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static struct fw_node *fw_node_create(u32 sid, int port_count, int color)
124124
node->initiated_reset = SELF_ID_PHY_INITIATOR(sid);
125125
node->port_count = port_count;
126126

127-
atomic_set(&node->ref_count, 1);
127+
refcount_set(&node->ref_count, 1);
128128
INIT_LIST_HEAD(&node->link);
129129

130130
return node;

‎drivers/firewire/core.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <linux/slab.h>
1313
#include <linux/types.h>
1414

15-
#include <linux/atomic.h>
15+
#include <linux/refcount.h>
1616

1717
struct device;
1818
struct fw_card;
@@ -184,7 +184,7 @@ struct fw_node {
184184
* local node to this node. */
185185
u8 max_depth:4; /* Maximum depth to any leaf node */
186186
u8 max_hops:4; /* Max hops in this sub tree */
187-
atomic_t ref_count;
187+
refcount_t ref_count;
188188

189189
/* For serializing node topology into a list. */
190190
struct list_head link;
@@ -197,14 +197,14 @@ struct fw_node {
197197

198198
static inline struct fw_node *fw_node_get(struct fw_node *node)
199199
{
200-
atomic_inc(&node->ref_count);
200+
refcount_inc(&node->ref_count);
201201

202202
return node;
203203
}
204204

205205
static inline void fw_node_put(struct fw_node *node)
206206
{
207-
if (atomic_dec_and_test(&node->ref_count))
207+
if (refcount_dec_and_test(&node->ref_count))
208208
kfree(node);
209209
}
210210

0 commit comments

Comments
 (0)