diff mbox series

[28/44] block: initialize struct block_device in bdev_alloc

Message ID 20201126130422.92945-29-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/44] blk-cgroup: fix a hd_struct leak in blkcg_fill_root_iostats | expand

Commit Message

Christoph Hellwig Nov. 26, 2020, 1:04 p.m. UTC
Don't play tricks with slab constructors as bdev structures tends to not
get reused very much, and this makes the code a lot less error prone.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Tejun Heo <tj@kernel.org>
---
 fs/block_dev.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

Comments

Jan Kara Nov. 26, 2020, 4:37 p.m. UTC | #1
On Thu 26-11-20 14:04:06, Christoph Hellwig wrote:
> Don't play tricks with slab constructors as bdev structures tends to not
> get reused very much, and this makes the code a lot less error prone.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Acked-by: Tejun Heo <tj@kernel.org>

Looks good. You can add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/block_dev.c | 22 +++++++++-------------
>  1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index f180ac0e87844f..58e8532d8580a1 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -784,20 +784,11 @@ static void bdev_free_inode(struct inode *inode)
>  	kmem_cache_free(bdev_cachep, BDEV_I(inode));
>  }
>  
> -static void init_once(void *foo)
> +static void init_once(void *data)
>  {
> -	struct bdev_inode *ei = (struct bdev_inode *) foo;
> -	struct block_device *bdev = &ei->bdev;
> +	struct bdev_inode *ei = data;
>  
> -	memset(bdev, 0, sizeof(*bdev));
> -	mutex_init(&bdev->bd_mutex);
> -#ifdef CONFIG_SYSFS
> -	INIT_LIST_HEAD(&bdev->bd_holder_disks);
> -#endif
> -	bdev->bd_bdi = &noop_backing_dev_info;
>  	inode_init_once(&ei->vfs_inode);
> -	/* Initialize mutex for freeze. */
> -	mutex_init(&bdev->bd_fsfreeze_mutex);
>  }
>  
>  static void bdev_evict_inode(struct inode *inode)
> @@ -873,12 +864,17 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
>  	mapping_set_gfp_mask(&inode->i_data, GFP_USER);
>  
>  	bdev = I_BDEV(inode);
> +	memset(bdev, 0, sizeof(*bdev));
> +	mutex_init(&bdev->bd_mutex);
> +	mutex_init(&bdev->bd_fsfreeze_mutex);
>  	spin_lock_init(&bdev->bd_size_lock);
>  	bdev->bd_disk = disk;
>  	bdev->bd_partno = partno;
> -	bdev->bd_super = NULL;
>  	bdev->bd_inode = inode;
> -	bdev->bd_part_count = 0;
> +	bdev->bd_bdi = &noop_backing_dev_info;
> +#ifdef CONFIG_SYSFS
> +	INIT_LIST_HEAD(&bdev->bd_holder_disks);
> +#endif
>  	return bdev;
>  }
>  
> -- 
> 2.29.2
>
diff mbox series

Patch

diff --git a/fs/block_dev.c b/fs/block_dev.c
index f180ac0e87844f..58e8532d8580a1 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -784,20 +784,11 @@  static void bdev_free_inode(struct inode *inode)
 	kmem_cache_free(bdev_cachep, BDEV_I(inode));
 }
 
-static void init_once(void *foo)
+static void init_once(void *data)
 {
-	struct bdev_inode *ei = (struct bdev_inode *) foo;
-	struct block_device *bdev = &ei->bdev;
+	struct bdev_inode *ei = data;
 
-	memset(bdev, 0, sizeof(*bdev));
-	mutex_init(&bdev->bd_mutex);
-#ifdef CONFIG_SYSFS
-	INIT_LIST_HEAD(&bdev->bd_holder_disks);
-#endif
-	bdev->bd_bdi = &noop_backing_dev_info;
 	inode_init_once(&ei->vfs_inode);
-	/* Initialize mutex for freeze. */
-	mutex_init(&bdev->bd_fsfreeze_mutex);
 }
 
 static void bdev_evict_inode(struct inode *inode)
@@ -873,12 +864,17 @@  struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
 	mapping_set_gfp_mask(&inode->i_data, GFP_USER);
 
 	bdev = I_BDEV(inode);
+	memset(bdev, 0, sizeof(*bdev));
+	mutex_init(&bdev->bd_mutex);
+	mutex_init(&bdev->bd_fsfreeze_mutex);
 	spin_lock_init(&bdev->bd_size_lock);
 	bdev->bd_disk = disk;
 	bdev->bd_partno = partno;
-	bdev->bd_super = NULL;
 	bdev->bd_inode = inode;
-	bdev->bd_part_count = 0;
+	bdev->bd_bdi = &noop_backing_dev_info;
+#ifdef CONFIG_SYSFS
+	INIT_LIST_HEAD(&bdev->bd_holder_disks);
+#endif
 	return bdev;
 }