diff options
| author | John Pittman <jpittman@redhat.com> | 2018-08-27 14:33:05 -0400 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2018-08-27 21:17:02 -0400 |
| commit | db193954ed9e35701b6e489fa4cc97b08589341b (patch) | |
| tree | 5ebcc8fb74104392763ba3a03eae0196f19ea6cd | |
| parent | 62d2a1940709198a522a43ff8be8b8f6b3654dec (diff) | |
block: bsg: move atomic_t ref_count variable to refcount API
Currently, variable ref_count within the bsg_device struct is of
type atomic_t. For variables being used as reference counters,
the refcount API should be used instead of atomic. The newer
refcount API works to prevent counter overflows and use-after-free
bugs. So, move this varable from the atomic API to refcount,
potentially avoiding the issues mentioned.
Signed-off-by: John Pittman <jpittman@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
| -rw-r--r-- | block/bsg.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/block/bsg.c b/block/bsg.c index db588add6ba6..9a442c23a715 100644 --- a/block/bsg.c +++ b/block/bsg.c | |||
| @@ -37,7 +37,7 @@ struct bsg_device { | |||
| 37 | struct request_queue *queue; | 37 | struct request_queue *queue; |
| 38 | spinlock_t lock; | 38 | spinlock_t lock; |
| 39 | struct hlist_node dev_list; | 39 | struct hlist_node dev_list; |
| 40 | atomic_t ref_count; | 40 | refcount_t ref_count; |
| 41 | char name[20]; | 41 | char name[20]; |
| 42 | int max_queue; | 42 | int max_queue; |
| 43 | }; | 43 | }; |
| @@ -252,7 +252,7 @@ static int bsg_put_device(struct bsg_device *bd) | |||
| 252 | 252 | ||
| 253 | mutex_lock(&bsg_mutex); | 253 | mutex_lock(&bsg_mutex); |
| 254 | 254 | ||
| 255 | if (!atomic_dec_and_test(&bd->ref_count)) { | 255 | if (!refcount_dec_and_test(&bd->ref_count)) { |
| 256 | mutex_unlock(&bsg_mutex); | 256 | mutex_unlock(&bsg_mutex); |
| 257 | return 0; | 257 | return 0; |
| 258 | } | 258 | } |
| @@ -290,7 +290,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode, | |||
| 290 | 290 | ||
| 291 | bd->queue = rq; | 291 | bd->queue = rq; |
| 292 | 292 | ||
| 293 | atomic_set(&bd->ref_count, 1); | 293 | refcount_set(&bd->ref_count, 1); |
| 294 | hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode))); | 294 | hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode))); |
| 295 | 295 | ||
| 296 | strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1); | 296 | strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1); |
| @@ -308,7 +308,7 @@ static struct bsg_device *__bsg_get_device(int minor, struct request_queue *q) | |||
| 308 | 308 | ||
| 309 | hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) { | 309 | hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) { |
| 310 | if (bd->queue == q) { | 310 | if (bd->queue == q) { |
| 311 | atomic_inc(&bd->ref_count); | 311 | refcount_inc(&bd->ref_count); |
| 312 | goto found; | 312 | goto found; |
| 313 | } | 313 | } |
| 314 | } | 314 | } |
