diff options
author | Bart Van Assche <bart.vanassche@wdc.com> | 2017-08-17 19:23:06 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2017-08-18 10:36:58 -0400 |
commit | 6d2cf6f2b446c4ace6f57402713ddbc09b11b0a9 (patch) | |
tree | 00de4770e862d2d130a8c1260400dbbd3a56230e /block/genhd.c | |
parent | f846593391d86289bed6b4834a9717820561d571 (diff) |
genhd: Annotate all part and part_tbl pointer dereferences
Annotate gendisk.part_tbl and disk_part_tbl.part dereferences with
rcu_dereference_protected(). This patch does not change the behavior
of the modified code but ensures that sparse does not complain about
disk->part_tbl manipulations nor about part_tbl->part accesses.
Additionally, improve documentation of the locking requirements of
the modified functions.
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/genhd.c')
-rw-r--r-- | block/genhd.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/block/genhd.c b/block/genhd.c index 3dc4d115480f..2367087cdb7c 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -1127,12 +1127,13 @@ static const struct attribute_group *disk_attr_groups[] = { | |||
1127 | * original ptbl is freed using RCU callback. | 1127 | * original ptbl is freed using RCU callback. |
1128 | * | 1128 | * |
1129 | * LOCKING: | 1129 | * LOCKING: |
1130 | * Matching bd_mutx locked. | 1130 | * Matching bd_mutex locked or the caller is the only user of @disk. |
1131 | */ | 1131 | */ |
1132 | static void disk_replace_part_tbl(struct gendisk *disk, | 1132 | static void disk_replace_part_tbl(struct gendisk *disk, |
1133 | struct disk_part_tbl *new_ptbl) | 1133 | struct disk_part_tbl *new_ptbl) |
1134 | { | 1134 | { |
1135 | struct disk_part_tbl *old_ptbl = disk->part_tbl; | 1135 | struct disk_part_tbl *old_ptbl = |
1136 | rcu_dereference_protected(disk->part_tbl, 1); | ||
1136 | 1137 | ||
1137 | rcu_assign_pointer(disk->part_tbl, new_ptbl); | 1138 | rcu_assign_pointer(disk->part_tbl, new_ptbl); |
1138 | 1139 | ||
@@ -1151,14 +1152,16 @@ static void disk_replace_part_tbl(struct gendisk *disk, | |||
1151 | * uses RCU to allow unlocked dereferencing for stats and other stuff. | 1152 | * uses RCU to allow unlocked dereferencing for stats and other stuff. |
1152 | * | 1153 | * |
1153 | * LOCKING: | 1154 | * LOCKING: |
1154 | * Matching bd_mutex locked, might sleep. | 1155 | * Matching bd_mutex locked or the caller is the only user of @disk. |
1156 | * Might sleep. | ||
1155 | * | 1157 | * |
1156 | * RETURNS: | 1158 | * RETURNS: |
1157 | * 0 on success, -errno on failure. | 1159 | * 0 on success, -errno on failure. |
1158 | */ | 1160 | */ |
1159 | int disk_expand_part_tbl(struct gendisk *disk, int partno) | 1161 | int disk_expand_part_tbl(struct gendisk *disk, int partno) |
1160 | { | 1162 | { |
1161 | struct disk_part_tbl *old_ptbl = disk->part_tbl; | 1163 | struct disk_part_tbl *old_ptbl = |
1164 | rcu_dereference_protected(disk->part_tbl, 1); | ||
1162 | struct disk_part_tbl *new_ptbl; | 1165 | struct disk_part_tbl *new_ptbl; |
1163 | int len = old_ptbl ? old_ptbl->len : 0; | 1166 | int len = old_ptbl ? old_ptbl->len : 0; |
1164 | int i, target; | 1167 | int i, target; |
@@ -1352,6 +1355,7 @@ EXPORT_SYMBOL(alloc_disk); | |||
1352 | struct gendisk *alloc_disk_node(int minors, int node_id) | 1355 | struct gendisk *alloc_disk_node(int minors, int node_id) |
1353 | { | 1356 | { |
1354 | struct gendisk *disk; | 1357 | struct gendisk *disk; |
1358 | struct disk_part_tbl *ptbl; | ||
1355 | 1359 | ||
1356 | disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id); | 1360 | disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id); |
1357 | if (disk) { | 1361 | if (disk) { |
@@ -1365,7 +1369,8 @@ struct gendisk *alloc_disk_node(int minors, int node_id) | |||
1365 | kfree(disk); | 1369 | kfree(disk); |
1366 | return NULL; | 1370 | return NULL; |
1367 | } | 1371 | } |
1368 | disk->part_tbl->part[0] = &disk->part0; | 1372 | ptbl = rcu_dereference_protected(disk->part_tbl, 1); |
1373 | rcu_assign_pointer(ptbl->part[0], &disk->part0); | ||
1369 | 1374 | ||
1370 | /* | 1375 | /* |
1371 | * set_capacity() and get_capacity() currently don't use | 1376 | * set_capacity() and get_capacity() currently don't use |