Skip to contentSkip to conversation

nilfs2: fix backing_dev_info reference leak

PATCH Applied Shuangpeng Bai 3 participants 4 messages May 7 – May 8 NILFS2 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nilfs2: fix backing_dev_info reference leak

setup_bdev_super() already initializes sb->s_bdev and takes a reference on the block device backing_dev_info when assigning sb->s_bdi.

nilfs_fill_super() takes another reference to the same backing_dev_info and stores it in sb->s_bdi again. The extra reference is not paired with a matching bdi_put(), since generic_shutdown_super() releases sb->s_bdi only once.

Drop the redundant bdi_get() in nilfs_fill_super(). The single reference taken by setup_bdev_super() is enough and is released during superblock shutdown.

Fixes c1e012ea9e83 ("nilfs2: use setup_bdev_super to de-duplicate the mount code")
---
 fs/nilfs2/super.c | 2 --
 1 file changed, 2 deletions(-)
fs/nilfs2/super.c +0 -2
index 7aa5ef8606cd..893a504cb80c 100644
@@ -1070,8 +1070,6 @@ nilfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	sb->s_time_gran = 1;
 	sb->s_max_links = NILFS_LINK_MAX;
 
-	sb->s_bdi = bdi_get(sb->s_bdev->bd_disk->bdi);
-
 	err = load_nilfs(nilfs, sb);
 	if (err)
 		goto failed_nilfs;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Shuangpeng Bai

setup_bdev_super() already initializes sb->s_bdev and takes a reference on the block device backing_dev_info when assigning sb->s_bdi.

nilfs_fill_super() takes another reference to the same backing_dev_info and stores it in sb->s_bdi again. The extra reference is not paired with a matching bdi_put(), since generic_shutdown_super() releases sb->s_bdi only once.

Drop the redundant bdi_get() in nilfs_fill_super(). The single reference taken by setup_bdev_super() is enough and is released during superblock shutdown.

Fixes c1e012ea9e83 ("nilfs2: use setup_bdev_super to de-duplicate the mount code")
---
 fs/nilfs2/super.c | 2 --
 1 file changed, 2 deletions(-)
fs/nilfs2/super.c +0 -0
index 7aa5ef8606cd..893a504cb80c 100644

fs/nilfs2/super.c nilfs_fill_super(struct super_block *sb, struct fs_context *fc) · line 1075

Quoted 8 lines
fs/nilfs2/super.c +0 -2
@@ -1070,8 +1070,6 @@ nilfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	sb->s_time_gran = 1;
 	sb->s_max_links = NILFS_LINK_MAX;
 
-	sb->s_bdi = bdi_get(sb->s_bdev->bd_disk->bdi);
-
 	err = load_nilfs(nilfs, sb);
 	if (err)
 		goto failed_nilfs;

Makes sense to me.

Thanks,
Slava.

maintainer Acked-by
#2 lore raw
Quoted 14 lines · Viacheslav Dubeyko
Quoted 12 lines · Shuangpeng Bai

setup_bdev_super() already initializes sb->s_bdev and takes a reference on the block device backing_dev_info when assigning sb->s_bdi.

nilfs_fill_super() takes another reference to the same backing_dev_info and stores it in sb->s_bdi again. The extra reference is not paired with a matching bdi_put(), since generic_shutdown_super() releases sb->s_bdi only once.

Drop the redundant bdi_get() in nilfs_fill_super(). The single reference taken by setup_bdev_super() is enough and is released during superblock shutdown.

Quoted 5 lines
Quoted 5 lines
Fixes c1e012ea9e83 ("nilfs2: use setup_bdev_super to de-duplicate the mount code")
---
 fs/nilfs2/super.c | 2 --
 1 file changed, 2 deletions(-)

Viacheslav,

Could you please apply this directly?
I have also verified the fix and confirmed that the Fixes tag correctly identifies the origin of the leak for backporting.

Thanks,
Ryusuke Konishi

Quoted 22 lines
Quoted 6 lines
fs/nilfs2/super.c +0 -0
index 7aa5ef8606cd..893a504cb80c 100644

fs/nilfs2/super.c nilfs_fill_super(struct super_block *sb, struct fs_context *fc) · line 1075

Quoted 8 lines
fs/nilfs2/super.c +0 -2
@@ -1070,8 +1070,6 @@ nilfs_fill_super(struct super_block *sb, struct fs_context *fc)
      sb->s_time_gran = 1;
      sb->s_max_links = NILFS_LINK_MAX;
 
-     sb->s_bdi = bdi_get(sb->s_bdev->bd_disk->bdi);
-
      err = load_nilfs(nilfs, sb);
      if (err)
              goto failed_nilfs;

Makes sense to me.

Thanks,
Slava.

#3 lore raw
Quoted 21 lines · Ryusuke Konishi
Quoted 14 lines · Viacheslav Dubeyko
Quoted 12 lines · Shuangpeng Bai

setup_bdev_super() already initializes sb->s_bdev and takes a reference on the block device backing_dev_info when assigning sb->s_bdi.

nilfs_fill_super() takes another reference to the same backing_dev_info and stores it in sb->s_bdi again. The extra reference is not paired with a matching bdi_put(), since generic_shutdown_super() releases sb->s_bdi only once.

Drop the redundant bdi_get() in nilfs_fill_super(). The single reference taken by setup_bdev_super() is enough and is released during superblock shutdown.

Quoted 5 lines
Quoted 5 lines
Fixes c1e012ea9e83 ("nilfs2: use setup_bdev_super to de-duplicate the mount code")
---
 fs/nilfs2/super.c | 2 --
 1 file changed, 2 deletions(-)
Quoted 8 lines

Viacheslav,

Could you please apply this directly?
I have also verified the fix and confirmed that the Fixes tag correctly identifies the origin of the leak for backporting.

Applied.

Thanks,
Slava.