Skip to contentSkip to conversation

fs/bcachefs/clock.c:150:18-21: Unneeded variable: "ret". Return "NULL" on line 164

PATCH New kernel test robot 2 participants 3 messages Jun 2, 2024 Memory management

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable
head:   54524b845fbe070c5401141bc4ff2ec3f01f1e72
commit: cf66e6c3b24c5aaf365c54bb7dc8b9cb01f47f4d [38/65] bcachefs: remove heap-related macros and switch to generic min_heap
config: x86_64-randconfig-102-20240602 (https://download.01.org/0day-ci/archive/20240603/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)

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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

cocci warnings: (new ones prefixed by >>)

>> fs/bcachefs/clock.c:150:18-21: Unneeded variable: "ret". Return "NULL" on line 164

vim +150 fs/bcachefs/clock.c

1c6fdbd8f2465dd Kent Overstreet 2017-03-16  146  
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  147  static struct io_timer *get_expired_timer(struct io_clock *clock,
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  148  					  unsigned long now)
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  149  {
1c6fdbd8f2465dd Kent Overstreet 2017-03-16 @150  	struct io_timer *ret = NULL;
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  151  	const struct min_heap_callbacks callbacks = {
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  152  		.less = io_timer_cmp,
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  153  		.swp = io_timer_swp,
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  154  	};
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  155  
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  156  	spin_lock(&clock->timer_lock);
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  157  
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  158  	if (clock->timers.nr &&
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  159  	    time_after_eq(now, clock->timers.data[0]->expire))
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  160  		min_heap_pop(&clock->timers, &callbacks, NULL);
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  161  
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  162  	spin_unlock(&clock->timer_lock);
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  163  

1c6fdbd8f2465dd Kent Overstreet 2017-03-16 @164 return ret;
1c6fdbd8f2465dd Kent Overstreet 2017-03-16 165 } 1c6fdbd8f2465dd Kent Overstreet 2017-03-16 166

:::::: The code at line 150 was first introduced by commit :::::: 1c6fdbd8f2465ddfb73a01ec620cbf3d14044e1a bcachefs: Initial commit

:::::: TO: Kent Overstreet <[email protected]> :::::: CC: Kent Overstreet <[email protected]>

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw
Quoted 6 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable
head:   54524b845fbe070c5401141bc4ff2ec3f01f1e72
commit: cf66e6c3b24c5aaf365c54bb7dc8b9cb01f47f4d [38/65] bcachefs: remove heap-related macros and switch to generic min_heap
config: x86_64-randconfig-102-20240602 (https://download.01.org/0day-ci/archive/20240603/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
Quoted 8 lines

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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

fs/bcachefs/clock.c:150:18-21: Unneeded variable: "ret". Return "NULL" on line 164

Hi Andrew,

This error occurred because I forgot to store the minimum value into 'ret' before calling min_heap_pop(). Should I submit a new version of the patch series or send a separate patch to fix this error?

Regards,
Kuan-Wei

Quoted 33 lines

vim +150 fs/bcachefs/clock.c

1c6fdbd8f2465dd Kent Overstreet 2017-03-16  146  
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  147  static struct io_timer *get_expired_timer(struct io_clock *clock,
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  148  					  unsigned long now)
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  149  {
1c6fdbd8f2465dd Kent Overstreet 2017-03-16 @150  	struct io_timer *ret = NULL;
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  151  	const struct min_heap_callbacks callbacks = {
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  152  		.less = io_timer_cmp,
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  153  		.swp = io_timer_swp,
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  154  	};
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  155  
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  156  	spin_lock(&clock->timer_lock);
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  157  
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  158  	if (clock->timers.nr &&
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  159  	    time_after_eq(now, clock->timers.data[0]->expire))
cf66e6c3b24c5aa Kuan-Wei Chiu   2024-05-24  160  		min_heap_pop(&clock->timers, &callbacks, NULL);
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  161  
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  162  	spin_unlock(&clock->timer_lock);
1c6fdbd8f2465dd Kent Overstreet 2017-03-16  163  

1c6fdbd8f2465dd Kent Overstreet 2017-03-16 @164 return ret;
1c6fdbd8f2465dd Kent Overstreet 2017-03-16 165 } 1c6fdbd8f2465dd Kent Overstreet 2017-03-16 166

:::::: The code at line 150 was first introduced by commit :::::: 1c6fdbd8f2465ddfb73a01ec620cbf3d14044e1a bcachefs: Initial commit

:::::: TO: Kent Overstreet <[email protected]> :::::: CC: Kent Overstreet <[email protected]>

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw

PATCH 1/1 bcachefs: Fix missing assignment of minimum element before min_heap_pop()

In reply to kernel test robot

When replacing the heap_pop() macro with min_heap_pop(), the original heap_pop() macro would store the minimum element into 'ret'. However, after replacing it with min_heap_pop(), the code incorrectly failed to store the minimum element into 'ret' before deleting it.

Fix the issue by using min_heap_peek() to assign the minimum element to 'ret' before calling min_heap_pop() to remove the minimum element.

---
 fs/bcachefs/clock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/bcachefs/clock.c +3 -1
index 3ec64fe6a064..18fab9c44b1b 100644
@@ -156,8 +156,10 @@ static struct io_timer *get_expired_timer(struct io_clock *clock,
 	spin_lock(&clock->timer_lock);
 
 	if (clock->timers.nr &&
-	    time_after_eq(now, clock->timers.data[0]->expire))
+	    time_after_eq(now, clock->timers.data[0]->expire)) {
+		ret = *min_heap_peek(&clock->timers);
 		min_heap_pop(&clock->timers, &callbacks, NULL);
+	}
 
 	spin_unlock(&clock->timer_lock);
 
Signature · 1 line
2.34.1