diff mbox series

[1/3] fs/ntfs3: Fix memory leak if fill_super failed

Message ID f34b8f25-96c7-16d6-1e1c-6bb6c5342edd@paragon-software.com (mailing list archive)
State New, archived
Headers show
Series fs/ntfs3: Refactoring of super.c | expand

Commit Message

Konstantin Komarov Sept. 27, 2021, 3:47 p.m. UTC
Restore fc->s_fs_info to free memory allocated in ntfs_init_fs_context.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
 fs/ntfs3/super.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Kari Argillander Sept. 27, 2021, 6:40 p.m. UTC | #1
On Mon, Sep 27, 2021 at 06:47:14PM +0300, Konstantin Komarov wrote:
> Restore fc->s_fs_info to free memory allocated in ntfs_init_fs_context.
> 
> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
> ---
>  fs/ntfs3/super.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
> index 800897777eb0..7099d9b1f3aa 100644
> --- a/fs/ntfs3/super.c
> +++ b/fs/ntfs3/super.c
> @@ -1308,6 +1308,9 @@ int ntfs_discard(struct ntfs_sb_info *sbi, CLST lcn, CLST len)
>  	if (err == -EOPNOTSUPP)
>  		sbi->flags |= NTFS_FLAGS_NODISCARD;
>  
> +	/* Restore fc->s_fs_info to free memory allocated in ntfs_init_fs_context. */
> +	fc->s_fs_info = sbi;

Won't build and I do not understand what this does in ntfs_discard.

> +
>  	return err;
>  }
>  
> -- 
> 2.33.0
> 
>
kernel test robot Oct. 1, 2021, 3:56 a.m. UTC | #2
Hi Konstantin,

I love your patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.15-rc3 next-20210921]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Konstantin-Komarov/fs-ntfs3-Refactoring-of-super-c/20210929-210855
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5816b3e6577eaa676ceb00a848f0fd65fe2adc29
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/82c276fadc515e07a29db5855fd04a0c5e5f2358
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Konstantin-Komarov/fs-ntfs3-Refactoring-of-super-c/20210929-210855
        git checkout 82c276fadc515e07a29db5855fd04a0c5e5f2358
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=xtensa SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   fs/ntfs3/super.c: In function 'ntfs_discard':
>> fs/ntfs3/super.c:1429:9: error: 'fc' undeclared (first use in this function); did you mean 'fd'?
    1429 |         fc->s_fs_info = sbi;
         |         ^~
         |         fd
   fs/ntfs3/super.c:1429:9: note: each undeclared identifier is reported only once for each function it appears in


vim +1429 fs/ntfs3/super.c

  1390	
  1391	/*
  1392	 * ntfs_discard - Issue a discard request (trim for SSD).
  1393	 */
  1394	int ntfs_discard(struct ntfs_sb_info *sbi, CLST lcn, CLST len)
  1395	{
  1396		int err;
  1397		u64 lbo, bytes, start, end;
  1398		struct super_block *sb;
  1399	
  1400		if (sbi->used.next_free_lcn == lcn + len)
  1401			sbi->used.next_free_lcn = lcn;
  1402	
  1403		if (sbi->flags & NTFS_FLAGS_NODISCARD)
  1404			return -EOPNOTSUPP;
  1405	
  1406		if (!sbi->options.discard)
  1407			return -EOPNOTSUPP;
  1408	
  1409		lbo = (u64)lcn << sbi->cluster_bits;
  1410		bytes = (u64)len << sbi->cluster_bits;
  1411	
  1412		/* Align up 'start' on discard_granularity. */
  1413		start = (lbo + sbi->discard_granularity - 1) &
  1414			sbi->discard_granularity_mask_inv;
  1415		/* Align down 'end' on discard_granularity. */
  1416		end = (lbo + bytes) & sbi->discard_granularity_mask_inv;
  1417	
  1418		sb = sbi->sb;
  1419		if (start >= end)
  1420			return 0;
  1421	
  1422		err = blkdev_issue_discard(sb->s_bdev, start >> 9, (end - start) >> 9,
  1423					   GFP_NOFS, 0);
  1424	
  1425		if (err == -EOPNOTSUPP)
  1426			sbi->flags |= NTFS_FLAGS_NODISCARD;
  1427	
  1428		/* Restore fc->s_fs_info to free memory allocated in ntfs_init_fs_context. */
> 1429		fc->s_fs_info = sbi;
  1430	
  1431		return err;
  1432	}
  1433	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 800897777eb0..7099d9b1f3aa 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -1308,6 +1308,9 @@  int ntfs_discard(struct ntfs_sb_info *sbi, CLST lcn, CLST len)
 	if (err == -EOPNOTSUPP)
 		sbi->flags |= NTFS_FLAGS_NODISCARD;
 
+	/* Restore fc->s_fs_info to free memory allocated in ntfs_init_fs_context. */
+	fc->s_fs_info = sbi;
+
 	return err;
 }