Skip to contentSkip to conversation

drivers/md/bcache/nvm-pages.c:156:34: warning: Unsigned variable 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]

PATCH In review Dan Carpenter 3 participants 4 messages Apr 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 46/61 drivers/md/bcache/nvm-pages.c:156:34: warning: Unsigned variable 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git  for-5.13/drivers
head:   b09729cbbbf28ecdc61f00335684f7566eb740ec
commit: 97c62b647fcabd86fe703f9869be7dd91e685f50 [46/61] bcache: initialization of the buddy
compiler: microblaze-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate

cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

Quoted 1 line
Quoted 1 line

drivers/md/bcache/nvm-pages.c:156:34: warning: Unsigned variable 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]

      for (i = BCH_MAX_ORDER - 1; i >= 0 ; i--) {
                                    ^

vim +156 drivers/md/bcache/nvm-pages.c

97c62b647fcabd Jianpeng Ma 2021-04-14  144  static void init_nvm_free_space(struct bch_nvm_namespace *ns)
97c62b647fcabd Jianpeng Ma 2021-04-14  145  {
97c62b647fcabd Jianpeng Ma 2021-04-14  146  	unsigned int start, end, i;
                                                ^^^^^^^^^^^^             ^
97c62b647fcabd Jianpeng Ma 2021-04-14  147  	struct page *page;
97c62b647fcabd Jianpeng Ma 2021-04-14  148  	long long pages;
97c62b647fcabd Jianpeng Ma 2021-04-14  149  	pgoff_t pgoff_start;
97c62b647fcabd Jianpeng Ma 2021-04-14  150  
97c62b647fcabd Jianpeng Ma 2021-04-14  151  	bitmap_for_each_clear_region(ns->pages_bitmap, start, end, 0, ns->pages_total) {
97c62b647fcabd Jianpeng Ma 2021-04-14  152  		pgoff_start = start;
97c62b647fcabd Jianpeng Ma 2021-04-14  153  		pages = end - start;
97c62b647fcabd Jianpeng Ma 2021-04-14  154  
97c62b647fcabd Jianpeng Ma 2021-04-14  155  		while (pages) {
97c62b647fcabd Jianpeng Ma 2021-04-14 @156  			for (i = BCH_MAX_ORDER - 1; i >= 0 ; i--) {
                                                                                            ^^^^^^

This needs to be "int i;" for the loop to work correctly.

97c62b647fcabd Jianpeng Ma 2021-04-14  157  				if ((pgoff_start % (1 << i) == 0) && (pages >= (1 << i)))
97c62b647fcabd Jianpeng Ma 2021-04-14  158  					break;
97c62b647fcabd Jianpeng Ma 2021-04-14  159  			}
97c62b647fcabd Jianpeng Ma 2021-04-14  160  
97c62b647fcabd Jianpeng Ma 2021-04-14  161  			page = nvm_vaddr_to_page(ns, nvm_pgoff_to_vaddr(ns, pgoff_start));
97c62b647fcabd Jianpeng Ma 2021-04-14  162  			page->index = pgoff_start;
97c62b647fcabd Jianpeng Ma 2021-04-14  163  			set_page_private(page, i);
97c62b647fcabd Jianpeng Ma 2021-04-14  164  			__SetPageBuddy(page);
97c62b647fcabd Jianpeng Ma 2021-04-14  165  			list_add((struct list_head *)&page->zone_device_data, &ns->free_area[i]);
97c62b647fcabd Jianpeng Ma 2021-04-14  166  
97c62b647fcabd Jianpeng Ma 2021-04-14  167  			pgoff_start += 1 << i;
97c62b647fcabd Jianpeng Ma 2021-04-14  168  			pages -= 1 << i;
97c62b647fcabd Jianpeng Ma 2021-04-14  169  		}
97c62b647fcabd Jianpeng Ma 2021-04-14  170  	}
688330711e9ae3 Jianpeng Ma 2021-04-14  171  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
_______________________________________________
kbuild mailing list -- kbuild(a)lists.01.org
To unsubscribe send an email to [email protected]

#1 lore raw
Quoted 5 lines · Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git  for-5.13/drivers
head:   b09729cbbbf28ecdc61f00335684f7566eb740ec
commit: 97c62b647fcabd86fe703f9869be7dd91e685f50 [46/61] bcache: initialization of the buddy
compiler: microblaze-linux-gcc (GCC) 9.3.0
Quoted 7 lines

If you fix the issue, kindly add following tag as appropriate

cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

Quoted 1 line
Quoted 1 line

drivers/md/bcache/nvm-pages.c:156:34: warning: Unsigned variable 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]

      for (i = BCH_MAX_ORDER - 1; i >= 0 ; i--) {

Coly, how could this ever have worked?

I'm staring to get less and less impressed with this nvm changeset, it seems broken in various ways. Might not be a bad idea to pull it from the next queue and give it some more time to turn into something that is acceptable.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 12 lines · Jens Axboe
Quoted 11 lines · Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git  for-5.13/drivers
head:   b09729cbbbf28ecdc61f00335684f7566eb740ec
commit: 97c62b647fcabd86fe703f9869be7dd91e685f50 [46/61] bcache: initialization of the buddy
compiler: microblaze-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate

cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

Quoted 1 line
Quoted 1 line

drivers/md/bcache/nvm-pages.c:156:34: warning: Unsigned variable 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]

Quoted 9 lines
Quoted 1 line
      for (i = BCH_MAX_ORDER - 1; i >= 0 ; i--) {

Coly, how could this ever have worked?

I'm staring to get less and less impressed with this nvm changeset, it seems broken in various ways. Might not be a bad idea to pull it from the next queue and give it some more time to turn into something that is acceptable.

Hi Jens,

Copied, please do.

We will prepare a more stable code base for 5.14 merge window.

Thanks.

Coly Li

#3 lore raw
Quoted 23 lines · Coly Li
Quoted 12 lines · Jens Axboe
Quoted 11 lines · Dan Carpenter
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git  for-5.13/drivers
head:   b09729cbbbf28ecdc61f00335684f7566eb740ec
commit: 97c62b647fcabd86fe703f9869be7dd91e685f50 [46/61] bcache: initialization of the buddy
compiler: microblaze-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate

cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

Quoted 1 line
Quoted 1 line

drivers/md/bcache/nvm-pages.c:156:34: warning: Unsigned variable 'i' can't be negative so it is unnecessary to test it. [unsignedPositive]

Quoted 9 lines
Quoted 1 line
      for (i = BCH_MAX_ORDER - 1; i >= 0 ; i--) {

Coly, how could this ever have worked?

I'm staring to get less and less impressed with this nvm changeset, it seems broken in various ways. Might not be a bad idea to pull it from the next queue and give it some more time to turn into something that is acceptable.

Quoted 5 lines

Hi Jens,

Copied, please do.

We will prepare a more stable code base for 5.14 merge window.

Done.

Signature · 1 line
Jens Axboe