block: Fix double put in blk_integrity_unregister
[linux-3.10.git] / block / blk-integrity.c
index 4ffa381..e3817a0 100644 (file)
@@ -109,8 +109,8 @@ EXPORT_SYMBOL(blk_rq_map_integrity_sg);
 
 /**
  * blk_integrity_compare - Compare integrity profile of two block devices
- * @b1:                Device to compare
- * @b2:                Device to compare
+ * @bd1:       Device to compare
+ * @bd2:       Device to compare
  *
  * Description: Meta-devices like DM and MD need to verify that all
  * sub-devices use the same integrity format before advertising to
@@ -217,17 +217,16 @@ static ssize_t integrity_read_store(struct blk_integrity *bi,
        unsigned long val = simple_strtoul(p, &p, 10);
 
        if (val)
-               set_bit(INTEGRITY_FLAG_READ, &bi->flags);
+               bi->flags |= INTEGRITY_FLAG_READ;
        else
-               clear_bit(INTEGRITY_FLAG_READ, &bi->flags);
+               bi->flags &= ~INTEGRITY_FLAG_READ;
 
        return count;
 }
 
 static ssize_t integrity_read_show(struct blk_integrity *bi, char *page)
 {
-       return sprintf(page, "%d\n",
-                      test_bit(INTEGRITY_FLAG_READ, &bi->flags) ? 1 : 0);
+       return sprintf(page, "%d\n", (bi->flags & INTEGRITY_FLAG_READ) != 0);
 }
 
 static ssize_t integrity_write_store(struct blk_integrity *bi,
@@ -237,17 +236,16 @@ static ssize_t integrity_write_store(struct blk_integrity *bi,
        unsigned long val = simple_strtoul(p, &p, 10);
 
        if (val)
-               set_bit(INTEGRITY_FLAG_WRITE, &bi->flags);
+               bi->flags |= INTEGRITY_FLAG_WRITE;
        else
-               clear_bit(INTEGRITY_FLAG_WRITE, &bi->flags);
+               bi->flags &= ~INTEGRITY_FLAG_WRITE;
 
        return count;
 }
 
 static ssize_t integrity_write_show(struct blk_integrity *bi, char *page)
 {
-       return sprintf(page, "%d\n",
-                      test_bit(INTEGRITY_FLAG_WRITE, &bi->flags) ? 1 : 0);
+       return sprintf(page, "%d\n", (bi->flags & INTEGRITY_FLAG_WRITE) != 0);
 }
 
 static struct integrity_sysfs_entry integrity_format_entry = {
@@ -333,15 +331,15 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
                        return -1;
 
                if (kobject_init_and_add(&bi->kobj, &integrity_ktype,
-                                        &disk->dev.kobj, "%s", "integrity")) {
+                                        &disk_to_dev(disk)->kobj,
+                                        "%s", "integrity")) {
                        kmem_cache_free(integrity_cachep, bi);
                        return -1;
                }
 
                kobject_uevent(&bi->kobj, KOBJ_ADD);
 
-               set_bit(INTEGRITY_FLAG_READ, &bi->flags);
-               set_bit(INTEGRITY_FLAG_WRITE, &bi->flags);
+               bi->flags |= INTEGRITY_FLAG_READ | INTEGRITY_FLAG_WRITE;
                bi->sector_size = disk->queue->hardsect_size;
                disk->integrity = bi;
        } else
@@ -378,7 +376,7 @@ void blk_integrity_unregister(struct gendisk *disk)
 
        kobject_uevent(&bi->kobj, KOBJ_REMOVE);
        kobject_del(&bi->kobj);
-       kobject_put(&disk->dev.kobj);
        kmem_cache_free(integrity_cachep, bi);
+       disk->integrity = NULL;
 }
 EXPORT_SYMBOL(blk_integrity_unregister);