public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure
@ 2026-01-02  4:10 kernel test robot
  2026-01-05 11:29 ` Filipe Manana
  0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2026-01-02  4:10 UTC (permalink / raw)
  To: Filipe Manana; +Cc: oe-kbuild-all, linux-kernel, David Sterba, Boris Burkov

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   b69053dd3ffbc0d2dedbbc86182cdef6f641fe1b
commit: 08c649a5637371cb6bf8f3e974323cf59a7f434b btrfs: check we grabbed inode reference when allocating an ordered extent
date:   8 months ago
config: arm-randconfig-r051-20251231 (https://download.01.org/0day-ci/archive/20260102/202601021217.PPsDsiqO-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 86b9f90b9574b3a7d15d28a91f6316459dcfa046)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202601021217.PPsDsiqO-lkp@intel.com/

cocci warnings: (new ones prefixed by >>)
>> fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure

vim +215 fs/btrfs/ordered-data.c

   147	
   148	static struct btrfs_ordered_extent *alloc_ordered_extent(
   149				struct btrfs_inode *inode, u64 file_offset, u64 num_bytes,
   150				u64 ram_bytes, u64 disk_bytenr, u64 disk_num_bytes,
   151				u64 offset, unsigned long flags, int compress_type)
   152	{
   153		struct btrfs_ordered_extent *entry;
   154		int ret;
   155		u64 qgroup_rsv = 0;
   156		const bool is_nocow = (flags &
   157		       ((1U << BTRFS_ORDERED_NOCOW) | (1U << BTRFS_ORDERED_PREALLOC)));
   158	
   159		if (is_nocow) {
   160			/* For nocow write, we can release the qgroup rsv right now */
   161			ret = btrfs_qgroup_free_data(inode, NULL, file_offset, num_bytes, &qgroup_rsv);
   162			if (ret < 0)
   163				return ERR_PTR(ret);
   164		} else {
   165			/*
   166			 * The ordered extent has reserved qgroup space, release now
   167			 * and pass the reserved number for qgroup_record to free.
   168			 */
   169			ret = btrfs_qgroup_release_data(inode, file_offset, num_bytes, &qgroup_rsv);
   170			if (ret < 0)
   171				return ERR_PTR(ret);
   172		}
 > 173		entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS);
   174		if (!entry) {
   175			entry = ERR_PTR(-ENOMEM);
   176			goto out;
   177		}
   178	
   179		entry->file_offset = file_offset;
   180		entry->num_bytes = num_bytes;
   181		entry->ram_bytes = ram_bytes;
   182		entry->disk_bytenr = disk_bytenr;
   183		entry->disk_num_bytes = disk_num_bytes;
   184		entry->offset = offset;
   185		entry->bytes_left = num_bytes;
   186		if (WARN_ON_ONCE(!igrab(&inode->vfs_inode))) {
   187			kmem_cache_free(btrfs_ordered_extent_cache, entry);
   188			entry = ERR_PTR(-ESTALE);
   189			goto out;
   190		}
   191		entry->inode = inode;
   192		entry->compress_type = compress_type;
   193		entry->truncated_len = (u64)-1;
   194		entry->qgroup_rsv = qgroup_rsv;
   195		entry->flags = flags;
   196		refcount_set(&entry->refs, 1);
   197		init_waitqueue_head(&entry->wait);
   198		INIT_LIST_HEAD(&entry->list);
   199		INIT_LIST_HEAD(&entry->log_list);
   200		INIT_LIST_HEAD(&entry->root_extent_list);
   201		INIT_LIST_HEAD(&entry->work_list);
   202		INIT_LIST_HEAD(&entry->bioc_list);
   203		init_completion(&entry->completion);
   204	
   205		/*
   206		 * We don't need the count_max_extents here, we can assume that all of
   207		 * that work has been done at higher layers, so this is truly the
   208		 * smallest the extent is going to get.
   209		 */
   210		spin_lock(&inode->lock);
   211		btrfs_mod_outstanding_extents(inode, 1);
   212		spin_unlock(&inode->lock);
   213	
   214	out:
 > 215		if (IS_ERR(entry) && !is_nocow)
   216			btrfs_qgroup_free_refroot(inode->root->fs_info,
   217						  btrfs_root_id(inode->root),
   218						  qgroup_rsv, BTRFS_QGROUP_RSV_DATA);
   219	
   220		return entry;
   221	}
   222	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure
  2026-01-02  4:10 fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure kernel test robot
@ 2026-01-05 11:29 ` Filipe Manana
  0 siblings, 0 replies; 4+ messages in thread
From: Filipe Manana @ 2026-01-05 11:29 UTC (permalink / raw)
  To: kernel test robot; +Cc: oe-kbuild-all, linux-kernel, David Sterba, Boris Burkov

On Fri, Jan 2, 2026 at 4:10 AM kernel test robot <lkp@intel.com> wrote:
>
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head:   b69053dd3ffbc0d2dedbbc86182cdef6f641fe1b
> commit: 08c649a5637371cb6bf8f3e974323cf59a7f434b btrfs: check we grabbed inode reference when allocating an ordered extent
> date:   8 months ago
> config: arm-randconfig-r051-20251231 (https://download.01.org/0day-ci/archive/20260102/202601021217.PPsDsiqO-lkp@intel.com/config)
> compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 86b9f90b9574b3a7d15d28a91f6316459dcfa046)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202601021217.PPsDsiqO-lkp@intel.com/
>
> cocci warnings: (new ones prefixed by >>)
> >> fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure

False alarm.
The allocation function does indeed return NULL, but if that's the
case we set 'entry' to ERR_PTR(-ENOMEM) in line 175.
The only other error path sets entry to ERR_PTR(-ESTALE).

So it's perfectly fine to test for IS_ERR(entry) at line 215.

Thanks.

>
> vim +215 fs/btrfs/ordered-data.c
>
>    147
>    148  static struct btrfs_ordered_extent *alloc_ordered_extent(
>    149                          struct btrfs_inode *inode, u64 file_offset, u64 num_bytes,
>    150                          u64 ram_bytes, u64 disk_bytenr, u64 disk_num_bytes,
>    151                          u64 offset, unsigned long flags, int compress_type)
>    152  {
>    153          struct btrfs_ordered_extent *entry;
>    154          int ret;
>    155          u64 qgroup_rsv = 0;
>    156          const bool is_nocow = (flags &
>    157                 ((1U << BTRFS_ORDERED_NOCOW) | (1U << BTRFS_ORDERED_PREALLOC)));
>    158
>    159          if (is_nocow) {
>    160                  /* For nocow write, we can release the qgroup rsv right now */
>    161                  ret = btrfs_qgroup_free_data(inode, NULL, file_offset, num_bytes, &qgroup_rsv);
>    162                  if (ret < 0)
>    163                          return ERR_PTR(ret);
>    164          } else {
>    165                  /*
>    166                   * The ordered extent has reserved qgroup space, release now
>    167                   * and pass the reserved number for qgroup_record to free.
>    168                   */
>    169                  ret = btrfs_qgroup_release_data(inode, file_offset, num_bytes, &qgroup_rsv);
>    170                  if (ret < 0)
>    171                          return ERR_PTR(ret);
>    172          }
>  > 173          entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS);
>    174          if (!entry) {
>    175                  entry = ERR_PTR(-ENOMEM);
>    176                  goto out;
>    177          }
>    178
>    179          entry->file_offset = file_offset;
>    180          entry->num_bytes = num_bytes;
>    181          entry->ram_bytes = ram_bytes;
>    182          entry->disk_bytenr = disk_bytenr;
>    183          entry->disk_num_bytes = disk_num_bytes;
>    184          entry->offset = offset;
>    185          entry->bytes_left = num_bytes;
>    186          if (WARN_ON_ONCE(!igrab(&inode->vfs_inode))) {
>    187                  kmem_cache_free(btrfs_ordered_extent_cache, entry);
>    188                  entry = ERR_PTR(-ESTALE);
>    189                  goto out;
>    190          }
>    191          entry->inode = inode;
>    192          entry->compress_type = compress_type;
>    193          entry->truncated_len = (u64)-1;
>    194          entry->qgroup_rsv = qgroup_rsv;
>    195          entry->flags = flags;
>    196          refcount_set(&entry->refs, 1);
>    197          init_waitqueue_head(&entry->wait);
>    198          INIT_LIST_HEAD(&entry->list);
>    199          INIT_LIST_HEAD(&entry->log_list);
>    200          INIT_LIST_HEAD(&entry->root_extent_list);
>    201          INIT_LIST_HEAD(&entry->work_list);
>    202          INIT_LIST_HEAD(&entry->bioc_list);
>    203          init_completion(&entry->completion);
>    204
>    205          /*
>    206           * We don't need the count_max_extents here, we can assume that all of
>    207           * that work has been done at higher layers, so this is truly the
>    208           * smallest the extent is going to get.
>    209           */
>    210          spin_lock(&inode->lock);
>    211          btrfs_mod_outstanding_extents(inode, 1);
>    212          spin_unlock(&inode->lock);
>    213
>    214  out:
>  > 215          if (IS_ERR(entry) && !is_nocow)
>    216                  btrfs_qgroup_free_refroot(inode->root->fs_info,
>    217                                            btrfs_root_id(inode->root),
>    218                                            qgroup_rsv, BTRFS_QGROUP_RSV_DATA);
>    219
>    220          return entry;
>    221  }
>    222
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure
@ 2026-02-16 23:16 kernel test robot
  2026-02-17 12:21 ` Filipe Manana
  0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2026-02-16 23:16 UTC (permalink / raw)
  To: Filipe Manana; +Cc: oe-kbuild-all, linux-kernel, David Sterba, Boris Burkov

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   9702969978695d9a699a1f34771580cdbb153b33
commit: 08c649a5637371cb6bf8f3e974323cf59a7f434b btrfs: check we grabbed inode reference when allocating an ordered extent
date:   9 months ago
config: mips-randconfig-r064-20260215 (https://download.01.org/0day-ci/archive/20260217/202602170751.qIgCJbJI-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602170751.qIgCJbJI-lkp@intel.com/

cocci warnings: (new ones prefixed by >>)
>> fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure

vim +215 fs/btrfs/ordered-data.c

   147	
   148	static struct btrfs_ordered_extent *alloc_ordered_extent(
   149				struct btrfs_inode *inode, u64 file_offset, u64 num_bytes,
   150				u64 ram_bytes, u64 disk_bytenr, u64 disk_num_bytes,
   151				u64 offset, unsigned long flags, int compress_type)
   152	{
   153		struct btrfs_ordered_extent *entry;
   154		int ret;
   155		u64 qgroup_rsv = 0;
   156		const bool is_nocow = (flags &
   157		       ((1U << BTRFS_ORDERED_NOCOW) | (1U << BTRFS_ORDERED_PREALLOC)));
   158	
   159		if (is_nocow) {
   160			/* For nocow write, we can release the qgroup rsv right now */
   161			ret = btrfs_qgroup_free_data(inode, NULL, file_offset, num_bytes, &qgroup_rsv);
   162			if (ret < 0)
   163				return ERR_PTR(ret);
   164		} else {
   165			/*
   166			 * The ordered extent has reserved qgroup space, release now
   167			 * and pass the reserved number for qgroup_record to free.
   168			 */
   169			ret = btrfs_qgroup_release_data(inode, file_offset, num_bytes, &qgroup_rsv);
   170			if (ret < 0)
   171				return ERR_PTR(ret);
   172		}
 > 173		entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS);
   174		if (!entry) {
   175			entry = ERR_PTR(-ENOMEM);
   176			goto out;
   177		}
   178	
   179		entry->file_offset = file_offset;
   180		entry->num_bytes = num_bytes;
   181		entry->ram_bytes = ram_bytes;
   182		entry->disk_bytenr = disk_bytenr;
   183		entry->disk_num_bytes = disk_num_bytes;
   184		entry->offset = offset;
   185		entry->bytes_left = num_bytes;
   186		if (WARN_ON_ONCE(!igrab(&inode->vfs_inode))) {
   187			kmem_cache_free(btrfs_ordered_extent_cache, entry);
   188			entry = ERR_PTR(-ESTALE);
   189			goto out;
   190		}
   191		entry->inode = inode;
   192		entry->compress_type = compress_type;
   193		entry->truncated_len = (u64)-1;
   194		entry->qgroup_rsv = qgroup_rsv;
   195		entry->flags = flags;
   196		refcount_set(&entry->refs, 1);
   197		init_waitqueue_head(&entry->wait);
   198		INIT_LIST_HEAD(&entry->list);
   199		INIT_LIST_HEAD(&entry->log_list);
   200		INIT_LIST_HEAD(&entry->root_extent_list);
   201		INIT_LIST_HEAD(&entry->work_list);
   202		INIT_LIST_HEAD(&entry->bioc_list);
   203		init_completion(&entry->completion);
   204	
   205		/*
   206		 * We don't need the count_max_extents here, we can assume that all of
   207		 * that work has been done at higher layers, so this is truly the
   208		 * smallest the extent is going to get.
   209		 */
   210		spin_lock(&inode->lock);
   211		btrfs_mod_outstanding_extents(inode, 1);
   212		spin_unlock(&inode->lock);
   213	
   214	out:
 > 215		if (IS_ERR(entry) && !is_nocow)
   216			btrfs_qgroup_free_refroot(inode->root->fs_info,
   217						  btrfs_root_id(inode->root),
   218						  qgroup_rsv, BTRFS_QGROUP_RSV_DATA);
   219	
   220		return entry;
   221	}
   222	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure
  2026-02-16 23:16 kernel test robot
@ 2026-02-17 12:21 ` Filipe Manana
  0 siblings, 0 replies; 4+ messages in thread
From: Filipe Manana @ 2026-02-17 12:21 UTC (permalink / raw)
  To: kernel test robot; +Cc: oe-kbuild-all, linux-kernel, David Sterba, Boris Burkov

On Mon, Feb 16, 2026 at 11:16 PM kernel test robot <lkp@intel.com> wrote:
>
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head:   9702969978695d9a699a1f34771580cdbb153b33
> commit: 08c649a5637371cb6bf8f3e974323cf59a7f434b btrfs: check we grabbed inode reference when allocating an ordered extent
> date:   9 months ago
> config: mips-randconfig-r064-20260215 (https://download.01.org/0day-ci/archive/20260217/202602170751.qIgCJbJI-lkp@intel.com/config)
> compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202602170751.qIgCJbJI-lkp@intel.com/
>
> cocci warnings: (new ones prefixed by >>)
> >> fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure


False alarm.
The allocation function does indeed return NULL, but if that's the
case we set 'entry' to ERR_PTR(-ENOMEM) in line 175.
The only other error path sets entry to ERR_PTR(-ESTALE).

So it's perfectly fine to test for IS_ERR(entry) at line 215.

Please fix the bot, as this is the second time this warning/false
alarm is reported.

Thanks.


>
>
> vim +215 fs/btrfs/ordered-data.c
>
>    147
>    148  static struct btrfs_ordered_extent *alloc_ordered_extent(
>    149                          struct btrfs_inode *inode, u64 file_offset, u64 num_bytes,
>    150                          u64 ram_bytes, u64 disk_bytenr, u64 disk_num_bytes,
>    151                          u64 offset, unsigned long flags, int compress_type)
>    152  {
>    153          struct btrfs_ordered_extent *entry;
>    154          int ret;
>    155          u64 qgroup_rsv = 0;
>    156          const bool is_nocow = (flags &
>    157                 ((1U << BTRFS_ORDERED_NOCOW) | (1U << BTRFS_ORDERED_PREALLOC)));
>    158
>    159          if (is_nocow) {
>    160                  /* For nocow write, we can release the qgroup rsv right now */
>    161                  ret = btrfs_qgroup_free_data(inode, NULL, file_offset, num_bytes, &qgroup_rsv);
>    162                  if (ret < 0)
>    163                          return ERR_PTR(ret);
>    164          } else {
>    165                  /*
>    166                   * The ordered extent has reserved qgroup space, release now
>    167                   * and pass the reserved number for qgroup_record to free.
>    168                   */
>    169                  ret = btrfs_qgroup_release_data(inode, file_offset, num_bytes, &qgroup_rsv);
>    170                  if (ret < 0)
>    171                          return ERR_PTR(ret);
>    172          }
>  > 173          entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS);
>    174          if (!entry) {
>    175                  entry = ERR_PTR(-ENOMEM);
>    176                  goto out;
>    177          }
>    178
>    179          entry->file_offset = file_offset;
>    180          entry->num_bytes = num_bytes;
>    181          entry->ram_bytes = ram_bytes;
>    182          entry->disk_bytenr = disk_bytenr;
>    183          entry->disk_num_bytes = disk_num_bytes;
>    184          entry->offset = offset;
>    185          entry->bytes_left = num_bytes;
>    186          if (WARN_ON_ONCE(!igrab(&inode->vfs_inode))) {
>    187                  kmem_cache_free(btrfs_ordered_extent_cache, entry);
>    188                  entry = ERR_PTR(-ESTALE);
>    189                  goto out;
>    190          }
>    191          entry->inode = inode;
>    192          entry->compress_type = compress_type;
>    193          entry->truncated_len = (u64)-1;
>    194          entry->qgroup_rsv = qgroup_rsv;
>    195          entry->flags = flags;
>    196          refcount_set(&entry->refs, 1);
>    197          init_waitqueue_head(&entry->wait);
>    198          INIT_LIST_HEAD(&entry->list);
>    199          INIT_LIST_HEAD(&entry->log_list);
>    200          INIT_LIST_HEAD(&entry->root_extent_list);
>    201          INIT_LIST_HEAD(&entry->work_list);
>    202          INIT_LIST_HEAD(&entry->bioc_list);
>    203          init_completion(&entry->completion);
>    204
>    205          /*
>    206           * We don't need the count_max_extents here, we can assume that all of
>    207           * that work has been done at higher layers, so this is truly the
>    208           * smallest the extent is going to get.
>    209           */
>    210          spin_lock(&inode->lock);
>    211          btrfs_mod_outstanding_extents(inode, 1);
>    212          spin_unlock(&inode->lock);
>    213
>    214  out:
>  > 215          if (IS_ERR(entry) && !is_nocow)
>    216                  btrfs_qgroup_free_refroot(inode->root->fs_info,
>    217                                            btrfs_root_id(inode->root),
>    218                                            qgroup_rsv, BTRFS_QGROUP_RSV_DATA);
>    219
>    220          return entry;
>    221  }
>    222
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-17 12:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-02  4:10 fs/btrfs/ordered-data.c:215:5-11: ERROR: allocation function on line 173 returns NULL not ERR_PTR on failure kernel test robot
2026-01-05 11:29 ` Filipe Manana
  -- strict thread matches above, loose matches on Subject: below --
2026-02-16 23:16 kernel test robot
2026-02-17 12:21 ` Filipe Manana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox