diff options
author | Elena Reshetova <elena.reshetova@intel.com> | 2017-03-06 09:20:49 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-03-23 08:57:19 -0400 |
commit | 392910cf3f8a0161d3da45d02ea17f2910d9193b (patch) | |
tree | 1b8000c1e13654b51ed58e19df0ac897a190849d | |
parent | f7d88d24c5a2b66b02770e2776fce72b5fd70193 (diff) |
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>
-rw-r--r-- | drivers/firewire/core-topology.c | 2 | ||||
-rw-r--r-- | drivers/firewire/core.h | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topology.c index 0de83508f321..939d259ddf19 100644 --- a/drivers/firewire/core-topology.c +++ b/drivers/firewire/core-topology.c | |||
@@ -124,7 +124,7 @@ static struct fw_node *fw_node_create(u32 sid, int port_count, int color) | |||
124 | node->initiated_reset = SELF_ID_PHY_INITIATOR(sid); | 124 | node->initiated_reset = SELF_ID_PHY_INITIATOR(sid); |
125 | node->port_count = port_count; | 125 | node->port_count = port_count; |
126 | 126 | ||
127 | atomic_set(&node->ref_count, 1); | 127 | refcount_set(&node->ref_count, 1); |
128 | INIT_LIST_HEAD(&node->link); | 128 | INIT_LIST_HEAD(&node->link); |
129 | 129 | ||
130 | return node; | 130 | return node; |
diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index e1480ff683d2..c07962ead5e4 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h | |||
@@ -12,7 +12,7 @@ | |||
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
14 | 14 | ||
15 | #include <linux/atomic.h> | 15 | #include <linux/refcount.h> |
16 | 16 | ||
17 | struct device; | 17 | struct device; |
18 | struct fw_card; | 18 | struct fw_card; |
@@ -184,7 +184,7 @@ struct fw_node { | |||
184 | * local node to this node. */ | 184 | * local node to this node. */ |
185 | u8 max_depth:4; /* Maximum depth to any leaf node */ | 185 | u8 max_depth:4; /* Maximum depth to any leaf node */ |
186 | u8 max_hops:4; /* Max hops in this sub tree */ | 186 | u8 max_hops:4; /* Max hops in this sub tree */ |
187 | atomic_t ref_count; | 187 | refcount_t ref_count; |
188 | 188 | ||
189 | /* For serializing node topology into a list. */ | 189 | /* For serializing node topology into a list. */ |
190 | struct list_head link; | 190 | struct list_head link; |
@@ -197,14 +197,14 @@ struct fw_node { | |||
197 | 197 | ||
198 | static inline struct fw_node *fw_node_get(struct fw_node *node) | 198 | static inline struct fw_node *fw_node_get(struct fw_node *node) |
199 | { | 199 | { |
200 | atomic_inc(&node->ref_count); | 200 | refcount_inc(&node->ref_count); |
201 | 201 | ||
202 | return node; | 202 | return node; |
203 | } | 203 | } |
204 | 204 | ||
205 | static inline void fw_node_put(struct fw_node *node) | 205 | static inline void fw_node_put(struct fw_node *node) |
206 | { | 206 | { |
207 | if (atomic_dec_and_test(&node->ref_count)) | 207 | if (refcount_dec_and_test(&node->ref_count)) |
208 | kfree(node); | 208 | kfree(node); |
209 | } | 209 | } |
210 | 210 | ||