[PATCH] genhd: Handle part_tbl and part pointers correctly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch ensures that sparse does not complain about disk->part_tbl
manipulations nor about part_tbl->part accesses.

Signed-off-by: Bart Van Assche <bart.vanassche@xxxxxxxxxxx>
---
 block/genhd.c             | 7 ++++---
 block/partition-generic.c | 6 +++---
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index fcd6d4f..a54c8ce 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1072,7 +1072,7 @@ static const struct attribute_group *disk_attr_groups[] = {
 static void disk_replace_part_tbl(struct gendisk *disk,
 				  struct disk_part_tbl *new_ptbl)
 {
-	struct disk_part_tbl *old_ptbl = disk->part_tbl;
+	struct disk_part_tbl *old_ptbl = rcu_dereference(disk->part_tbl);
 
 	rcu_assign_pointer(disk->part_tbl, new_ptbl);
 
@@ -1098,7 +1098,7 @@ static void disk_replace_part_tbl(struct gendisk *disk,
  */
 int disk_expand_part_tbl(struct gendisk *disk, int partno)
 {
-	struct disk_part_tbl *old_ptbl = disk->part_tbl;
+	struct disk_part_tbl *old_ptbl = rcu_dereference(disk->part_tbl);
 	struct disk_part_tbl *new_ptbl;
 	int len = old_ptbl ? old_ptbl->len : 0;
 	int i, target;
@@ -1303,7 +1303,8 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
 			kfree(disk);
 			return NULL;
 		}
-		disk->part_tbl->part[0] = &disk->part0;
+		rcu_assign_pointer(rcu_dereference(disk->part_tbl)->part[0],
+				   &disk->part0);
 
 		/*
 		 * set_capacity() and get_capacity() currently don't use
diff --git a/block/partition-generic.c b/block/partition-generic.c
index 71d9ed9..df38027 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -252,13 +252,13 @@ void __delete_partition(struct percpu_ref *ref)
 
 void delete_partition(struct gendisk *disk, int partno)
 {
-	struct disk_part_tbl *ptbl = disk->part_tbl;
+	struct disk_part_tbl *ptbl = rcu_dereference(disk->part_tbl);
 	struct hd_struct *part;
 
 	if (partno >= ptbl->len)
 		return;
 
-	part = ptbl->part[partno];
+	part = rcu_dereference(ptbl->part[partno]);
 	if (!part)
 		return;
 
@@ -293,7 +293,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
 	err = disk_expand_part_tbl(disk, partno);
 	if (err)
 		return ERR_PTR(err);
-	ptbl = disk->part_tbl;
+	ptbl = rcu_dereference(disk->part_tbl);
 
 	if (ptbl->part[partno])
 		return ERR_PTR(-EBUSY);
-- 
2.10.0

--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux