All of lore.kernel.org
 help / color / mirror / Atom feed
* drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
@ 2021-11-21 11:07 kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-11-21 11:07 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 24686 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Kees Cook <keescook@chromium.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   923dcc5eb0c111eccd51cc7ce1658537e3c38b25
commit: a52f8a59aef46b59753e583bf4b28fccb069ce64 fortify: Explicitly disable Clang support
date:   8 weeks ago
:::::: branch date: 14 hours ago
:::::: commit date: 8 weeks ago
config: i386-randconfig-c001-20211115 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)
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://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a52f8a59aef46b59753e583bf4b28fccb069ce64
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout a52f8a59aef46b59753e583bf4b28fccb069ce64
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer 

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


clang-analyzer warnings: (new ones prefixed by >>)
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
>> drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
                           do_div(sum, n);
                           ^
   arch/x86/include/asm/div64.h:33:21: note: expanded from macro 'do_div'
                           __upper = __high % (__base);            \
                                     ~~~~~~~^~~~~~~~~~
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: '?' condition is true
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: Taking false branch
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:23: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                         ^
   drivers/md/bcache/sysfs.c:1035:21: note: Loop condition is false.  Exiting loop
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:295:2: note: expanded from macro '__compiletime_assert'
           do {                                                            \
           ^
   drivers/md/bcache/sysfs.c:1037:2: note: '?' condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1037:2: note: Assuming the condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:56:44: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var'

vim +1102 drivers/md/bcache/sysfs.c

58f913dce2814a Peter Foley     2017-10-13  1032  
cafe563591446c Kent Overstreet 2013-03-23  1033  SHOW(__bch_cache)
cafe563591446c Kent Overstreet 2013-03-23  1034  {
cafe563591446c Kent Overstreet 2013-03-23  1035  	struct cache *ca = container_of(kobj, struct cache, kobj);
cafe563591446c Kent Overstreet 2013-03-23  1036  
cafe563591446c Kent Overstreet 2013-03-23  1037  	sysfs_hprint(bucket_size,	bucket_bytes(ca));
cafe563591446c Kent Overstreet 2013-03-23  1038  	sysfs_hprint(block_size,	block_bytes(ca));
cafe563591446c Kent Overstreet 2013-03-23  1039  	sysfs_print(nbuckets,		ca->sb.nbuckets);
cafe563591446c Kent Overstreet 2013-03-23  1040  	sysfs_print(discard,		ca->discard);
cafe563591446c Kent Overstreet 2013-03-23  1041  	sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1042  	sysfs_hprint(btree_written,
cafe563591446c Kent Overstreet 2013-03-23  1043  		     atomic_long_read(&ca->btree_sectors_written) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1044  	sysfs_hprint(metadata_written,
cafe563591446c Kent Overstreet 2013-03-23  1045  		     (atomic_long_read(&ca->meta_sectors_written) +
cafe563591446c Kent Overstreet 2013-03-23  1046  		      atomic_long_read(&ca->btree_sectors_written)) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1047  
cafe563591446c Kent Overstreet 2013-03-23  1048  	sysfs_print(io_errors,
cafe563591446c Kent Overstreet 2013-03-23  1049  		    atomic_read(&ca->io_errors) >> IO_ERROR_SHIFT);
cafe563591446c Kent Overstreet 2013-03-23  1050  
cafe563591446c Kent Overstreet 2013-03-23  1051  	if (attr == &sysfs_cache_replacement_policy)
169ef1cf6171d3 Kent Overstreet 2013-03-28  1052  		return bch_snprint_string_list(buf, PAGE_SIZE,
cafe563591446c Kent Overstreet 2013-03-23  1053  					       cache_replacement_policies,
cafe563591446c Kent Overstreet 2013-03-23  1054  					       CACHE_REPLACEMENT(&ca->sb));
cafe563591446c Kent Overstreet 2013-03-23  1055  
cafe563591446c Kent Overstreet 2013-03-23  1056  	if (attr == &sysfs_priority_stats) {
15754020524a56 Kent Overstreet 2014-02-25  1057  		struct bucket *b;
15754020524a56 Kent Overstreet 2014-02-25  1058  		size_t n = ca->sb.nbuckets, i;
15754020524a56 Kent Overstreet 2014-02-25  1059  		size_t unused = 0, available = 0, dirty = 0, meta = 0;
cafe563591446c Kent Overstreet 2013-03-23  1060  		uint64_t sum = 0;
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1061  		/* Compute 31 quantiles */
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1062  		uint16_t q[31], *p, *cached;
cafe563591446c Kent Overstreet 2013-03-23  1063  		ssize_t ret;
cafe563591446c Kent Overstreet 2013-03-23  1064  
42bc47b35320e0 Kees Cook       2018-06-12  1065  		cached = p = vmalloc(array_size(sizeof(uint16_t),
42bc47b35320e0 Kees Cook       2018-06-12  1066  						ca->sb.nbuckets));
cafe563591446c Kent Overstreet 2013-03-23  1067  		if (!p)
cafe563591446c Kent Overstreet 2013-03-23  1068  			return -ENOMEM;
cafe563591446c Kent Overstreet 2013-03-23  1069  
cafe563591446c Kent Overstreet 2013-03-23  1070  		mutex_lock(&ca->set->bucket_lock);
15754020524a56 Kent Overstreet 2014-02-25  1071  		for_each_bucket(b, ca) {
15754020524a56 Kent Overstreet 2014-02-25  1072  			if (!GC_SECTORS_USED(b))
15754020524a56 Kent Overstreet 2014-02-25  1073  				unused++;
15754020524a56 Kent Overstreet 2014-02-25  1074  			if (GC_MARK(b) == GC_MARK_RECLAIMABLE)
15754020524a56 Kent Overstreet 2014-02-25  1075  				available++;
15754020524a56 Kent Overstreet 2014-02-25  1076  			if (GC_MARK(b) == GC_MARK_DIRTY)
15754020524a56 Kent Overstreet 2014-02-25  1077  				dirty++;
15754020524a56 Kent Overstreet 2014-02-25  1078  			if (GC_MARK(b) == GC_MARK_METADATA)
15754020524a56 Kent Overstreet 2014-02-25  1079  				meta++;
15754020524a56 Kent Overstreet 2014-02-25  1080  		}
15754020524a56 Kent Overstreet 2014-02-25  1081  
cafe563591446c Kent Overstreet 2013-03-23  1082  		for (i = ca->sb.first_bucket; i < n; i++)
cafe563591446c Kent Overstreet 2013-03-23  1083  			p[i] = ca->buckets[i].prio;
cafe563591446c Kent Overstreet 2013-03-23  1084  		mutex_unlock(&ca->set->bucket_lock);
cafe563591446c Kent Overstreet 2013-03-23  1085  
58f913dce2814a Peter Foley     2017-10-13  1086  		sort(p, n, sizeof(uint16_t), __bch_cache_cmp, NULL);
cafe563591446c Kent Overstreet 2013-03-23  1087  
cafe563591446c Kent Overstreet 2013-03-23  1088  		while (n &&
cafe563591446c Kent Overstreet 2013-03-23  1089  		       !cached[n - 1])
cafe563591446c Kent Overstreet 2013-03-23  1090  			--n;
cafe563591446c Kent Overstreet 2013-03-23  1091  
cafe563591446c Kent Overstreet 2013-03-23  1092  		while (cached < p + n &&
6751c1e3cff3aa Joe Perches     2021-02-10  1093  		       *cached == BTREE_PRIO) {
6751c1e3cff3aa Joe Perches     2021-02-10  1094  			cached++;
6751c1e3cff3aa Joe Perches     2021-02-10  1095  			n--;
6751c1e3cff3aa Joe Perches     2021-02-10  1096  		}
cafe563591446c Kent Overstreet 2013-03-23  1097  
cafe563591446c Kent Overstreet 2013-03-23  1098  		for (i = 0; i < n; i++)
cafe563591446c Kent Overstreet 2013-03-23  1099  			sum += INITIAL_PRIO - cached[i];
cafe563591446c Kent Overstreet 2013-03-23  1100  
cafe563591446c Kent Overstreet 2013-03-23  1101  		if (n)
cafe563591446c Kent Overstreet 2013-03-23 @1102  			do_div(sum, n);
cafe563591446c Kent Overstreet 2013-03-23  1103  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1104  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1105  			q[i] = INITIAL_PRIO - cached[n * (i + 1) /
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1106  				(ARRAY_SIZE(q) + 1)];
cafe563591446c Kent Overstreet 2013-03-23  1107  
cafe563591446c Kent Overstreet 2013-03-23  1108  		vfree(p);
cafe563591446c Kent Overstreet 2013-03-23  1109  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1110  		ret = scnprintf(buf, PAGE_SIZE,
cafe563591446c Kent Overstreet 2013-03-23  1111  				"Unused:		%zu%%\n"
15754020524a56 Kent Overstreet 2014-02-25  1112  				"Clean:		%zu%%\n"
15754020524a56 Kent Overstreet 2014-02-25  1113  				"Dirty:		%zu%%\n"
cafe563591446c Kent Overstreet 2013-03-23  1114  				"Metadata:	%zu%%\n"
cafe563591446c Kent Overstreet 2013-03-23  1115  				"Average:	%llu\n"
cafe563591446c Kent Overstreet 2013-03-23  1116  				"Sectors per Q:	%zu\n"
cafe563591446c Kent Overstreet 2013-03-23  1117  				"Quantiles:	[",
cafe563591446c Kent Overstreet 2013-03-23  1118  				unused * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1119  				available * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1120  				dirty * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1121  				meta * 100 / (size_t) ca->sb.nbuckets, sum,
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1122  				n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1));
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1123  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1124  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1125  			ret += scnprintf(buf + ret, PAGE_SIZE - ret,
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1126  					 "%u ", q[i]);
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1127  		ret--;
cafe563591446c Kent Overstreet 2013-03-23  1128  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1129  		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "]\n");
cafe563591446c Kent Overstreet 2013-03-23  1130  
cafe563591446c Kent Overstreet 2013-03-23  1131  		return ret;
cafe563591446c Kent Overstreet 2013-03-23  1132  	}
cafe563591446c Kent Overstreet 2013-03-23  1133  
cafe563591446c Kent Overstreet 2013-03-23  1134  	return 0;
cafe563591446c Kent Overstreet 2013-03-23  1135  }
cafe563591446c Kent Overstreet 2013-03-23  1136  SHOW_LOCKED(bch_cache)
cafe563591446c Kent Overstreet 2013-03-23  1137  

:::::: The code@line 1102 was first introduced by commit
:::::: cafe563591446cf80bfbc2fe3bc72a2e36cf1060 bcache: A block layer cache

:::::: TO: Kent Overstreet <koverstreet@google.com>
:::::: CC: Kent Overstreet <koverstreet@google.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 33400 bytes --]

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

* drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
@ 2022-01-01  8:22 kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-01-01  8:22 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 24755 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Kees Cook <keescook@chromium.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   8008293888188c3923f5bd8a69370dae25ed14e5
commit: a52f8a59aef46b59753e583bf4b28fccb069ce64 fortify: Explicitly disable Clang support
date:   3 months ago
:::::: branch date: 11 hours ago
:::::: commit date: 3 months ago
config: i386-randconfig-c001-20211115 (https://download.01.org/0day-ci/archive/20220101/202201011649.USOVbPWp-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)
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://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a52f8a59aef46b59753e583bf4b28fccb069ce64
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout a52f8a59aef46b59753e583bf4b28fccb069ce64
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer 

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


clang-analyzer warnings: (new ones prefixed by >>)
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
>> drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
                           do_div(sum, n);
                           ^
   arch/x86/include/asm/div64.h:33:21: note: expanded from macro 'do_div'
                           __upper = __high % (__base);            \
                                     ~~~~~~~^~~~~~~~~~
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: '?' condition is true
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: Taking false branch
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:23: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                         ^
   drivers/md/bcache/sysfs.c:1035:21: note: Loop condition is false.  Exiting loop
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:295:2: note: expanded from macro '__compiletime_assert'
           do {                                                            \
           ^
   drivers/md/bcache/sysfs.c:1037:2: note: '?' condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1037:2: note: Assuming the condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:56:44: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var'

vim +1102 drivers/md/bcache/sysfs.c

58f913dce2814a Peter Foley     2017-10-13  1032  
cafe563591446c Kent Overstreet 2013-03-23  1033  SHOW(__bch_cache)
cafe563591446c Kent Overstreet 2013-03-23  1034  {
cafe563591446c Kent Overstreet 2013-03-23  1035  	struct cache *ca = container_of(kobj, struct cache, kobj);
cafe563591446c Kent Overstreet 2013-03-23  1036  
cafe563591446c Kent Overstreet 2013-03-23  1037  	sysfs_hprint(bucket_size,	bucket_bytes(ca));
cafe563591446c Kent Overstreet 2013-03-23  1038  	sysfs_hprint(block_size,	block_bytes(ca));
cafe563591446c Kent Overstreet 2013-03-23  1039  	sysfs_print(nbuckets,		ca->sb.nbuckets);
cafe563591446c Kent Overstreet 2013-03-23  1040  	sysfs_print(discard,		ca->discard);
cafe563591446c Kent Overstreet 2013-03-23  1041  	sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1042  	sysfs_hprint(btree_written,
cafe563591446c Kent Overstreet 2013-03-23  1043  		     atomic_long_read(&ca->btree_sectors_written) << 9);
cafe563591446c Kent Overstreet 2013-03-23 @1044  	sysfs_hprint(metadata_written,
cafe563591446c Kent Overstreet 2013-03-23  1045  		     (atomic_long_read(&ca->meta_sectors_written) +
cafe563591446c Kent Overstreet 2013-03-23  1046  		      atomic_long_read(&ca->btree_sectors_written)) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1047  
cafe563591446c Kent Overstreet 2013-03-23  1048  	sysfs_print(io_errors,
cafe563591446c Kent Overstreet 2013-03-23  1049  		    atomic_read(&ca->io_errors) >> IO_ERROR_SHIFT);
cafe563591446c Kent Overstreet 2013-03-23  1050  
cafe563591446c Kent Overstreet 2013-03-23  1051  	if (attr == &sysfs_cache_replacement_policy)
169ef1cf6171d3 Kent Overstreet 2013-03-28  1052  		return bch_snprint_string_list(buf, PAGE_SIZE,
cafe563591446c Kent Overstreet 2013-03-23  1053  					       cache_replacement_policies,
cafe563591446c Kent Overstreet 2013-03-23  1054  					       CACHE_REPLACEMENT(&ca->sb));
cafe563591446c Kent Overstreet 2013-03-23  1055  
cafe563591446c Kent Overstreet 2013-03-23  1056  	if (attr == &sysfs_priority_stats) {
15754020524a56 Kent Overstreet 2014-02-25  1057  		struct bucket *b;
15754020524a56 Kent Overstreet 2014-02-25  1058  		size_t n = ca->sb.nbuckets, i;
15754020524a56 Kent Overstreet 2014-02-25  1059  		size_t unused = 0, available = 0, dirty = 0, meta = 0;
cafe563591446c Kent Overstreet 2013-03-23  1060  		uint64_t sum = 0;
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1061  		/* Compute 31 quantiles */
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1062  		uint16_t q[31], *p, *cached;
cafe563591446c Kent Overstreet 2013-03-23  1063  		ssize_t ret;
cafe563591446c Kent Overstreet 2013-03-23  1064  
42bc47b35320e0 Kees Cook       2018-06-12  1065  		cached = p = vmalloc(array_size(sizeof(uint16_t),
42bc47b35320e0 Kees Cook       2018-06-12  1066  						ca->sb.nbuckets));
cafe563591446c Kent Overstreet 2013-03-23  1067  		if (!p)
cafe563591446c Kent Overstreet 2013-03-23  1068  			return -ENOMEM;
cafe563591446c Kent Overstreet 2013-03-23  1069  
cafe563591446c Kent Overstreet 2013-03-23  1070  		mutex_lock(&ca->set->bucket_lock);
15754020524a56 Kent Overstreet 2014-02-25  1071  		for_each_bucket(b, ca) {
15754020524a56 Kent Overstreet 2014-02-25  1072  			if (!GC_SECTORS_USED(b))
15754020524a56 Kent Overstreet 2014-02-25  1073  				unused++;
15754020524a56 Kent Overstreet 2014-02-25  1074  			if (GC_MARK(b) == GC_MARK_RECLAIMABLE)
15754020524a56 Kent Overstreet 2014-02-25  1075  				available++;
15754020524a56 Kent Overstreet 2014-02-25  1076  			if (GC_MARK(b) == GC_MARK_DIRTY)
15754020524a56 Kent Overstreet 2014-02-25  1077  				dirty++;
15754020524a56 Kent Overstreet 2014-02-25  1078  			if (GC_MARK(b) == GC_MARK_METADATA)
15754020524a56 Kent Overstreet 2014-02-25  1079  				meta++;
15754020524a56 Kent Overstreet 2014-02-25  1080  		}
15754020524a56 Kent Overstreet 2014-02-25  1081  
cafe563591446c Kent Overstreet 2013-03-23  1082  		for (i = ca->sb.first_bucket; i < n; i++)
cafe563591446c Kent Overstreet 2013-03-23  1083  			p[i] = ca->buckets[i].prio;
cafe563591446c Kent Overstreet 2013-03-23  1084  		mutex_unlock(&ca->set->bucket_lock);
cafe563591446c Kent Overstreet 2013-03-23  1085  
58f913dce2814a Peter Foley     2017-10-13  1086  		sort(p, n, sizeof(uint16_t), __bch_cache_cmp, NULL);
cafe563591446c Kent Overstreet 2013-03-23  1087  
cafe563591446c Kent Overstreet 2013-03-23  1088  		while (n &&
cafe563591446c Kent Overstreet 2013-03-23  1089  		       !cached[n - 1])
cafe563591446c Kent Overstreet 2013-03-23  1090  			--n;
cafe563591446c Kent Overstreet 2013-03-23  1091  
cafe563591446c Kent Overstreet 2013-03-23  1092  		while (cached < p + n &&
6751c1e3cff3aa Joe Perches     2021-02-10  1093  		       *cached == BTREE_PRIO) {
6751c1e3cff3aa Joe Perches     2021-02-10  1094  			cached++;
6751c1e3cff3aa Joe Perches     2021-02-10  1095  			n--;
6751c1e3cff3aa Joe Perches     2021-02-10  1096  		}
cafe563591446c Kent Overstreet 2013-03-23  1097  
cafe563591446c Kent Overstreet 2013-03-23  1098  		for (i = 0; i < n; i++)
cafe563591446c Kent Overstreet 2013-03-23  1099  			sum += INITIAL_PRIO - cached[i];
cafe563591446c Kent Overstreet 2013-03-23  1100  
cafe563591446c Kent Overstreet 2013-03-23  1101  		if (n)
cafe563591446c Kent Overstreet 2013-03-23 @1102  			do_div(sum, n);
cafe563591446c Kent Overstreet 2013-03-23  1103  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1104  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1105  			q[i] = INITIAL_PRIO - cached[n * (i + 1) /
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1106  				(ARRAY_SIZE(q) + 1)];
cafe563591446c Kent Overstreet 2013-03-23  1107  
cafe563591446c Kent Overstreet 2013-03-23  1108  		vfree(p);
cafe563591446c Kent Overstreet 2013-03-23  1109  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1110  		ret = scnprintf(buf, PAGE_SIZE,
cafe563591446c Kent Overstreet 2013-03-23  1111  				"Unused:		%zu%%\n"
15754020524a56 Kent Overstreet 2014-02-25  1112  				"Clean:		%zu%%\n"
15754020524a56 Kent Overstreet 2014-02-25  1113  				"Dirty:		%zu%%\n"
cafe563591446c Kent Overstreet 2013-03-23  1114  				"Metadata:	%zu%%\n"
cafe563591446c Kent Overstreet 2013-03-23  1115  				"Average:	%llu\n"
cafe563591446c Kent Overstreet 2013-03-23  1116  				"Sectors per Q:	%zu\n"
cafe563591446c Kent Overstreet 2013-03-23  1117  				"Quantiles:	[",
cafe563591446c Kent Overstreet 2013-03-23  1118  				unused * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1119  				available * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1120  				dirty * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1121  				meta * 100 / (size_t) ca->sb.nbuckets, sum,
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1122  				n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1));
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1123  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1124  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1125  			ret += scnprintf(buf + ret, PAGE_SIZE - ret,
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1126  					 "%u ", q[i]);
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1127  		ret--;
cafe563591446c Kent Overstreet 2013-03-23  1128  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1129  		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "]\n");
cafe563591446c Kent Overstreet 2013-03-23  1130  
cafe563591446c Kent Overstreet 2013-03-23  1131  		return ret;
cafe563591446c Kent Overstreet 2013-03-23  1132  	}
cafe563591446c Kent Overstreet 2013-03-23  1133  
cafe563591446c Kent Overstreet 2013-03-23  1134  	return 0;
cafe563591446c Kent Overstreet 2013-03-23  1135  }
cafe563591446c Kent Overstreet 2013-03-23  1136  SHOW_LOCKED(bch_cache)
cafe563591446c Kent Overstreet 2013-03-23  1137  

:::::: The code@line 1102 was first introduced by commit
:::::: cafe563591446cf80bfbc2fe3bc72a2e36cf1060 bcache: A block layer cache

:::::: TO: Kent Overstreet <koverstreet@google.com>
:::::: CC: Kent Overstreet <koverstreet@google.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

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

* drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
@ 2021-11-30  9:36 kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-11-30  9:36 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 24753 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Kees Cook <keescook@chromium.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   d58071a8a76d779eedab38033ae4c821c30295a5
commit: a52f8a59aef46b59753e583bf4b28fccb069ce64 fortify: Explicitly disable Clang support
date:   9 weeks ago
:::::: branch date: 35 hours ago
:::::: commit date: 9 weeks ago
config: i386-randconfig-c001-20211115 (https://download.01.org/0day-ci/archive/20211130/202111301728.11UuSEgW-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)
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://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a52f8a59aef46b59753e583bf4b28fccb069ce64
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout a52f8a59aef46b59753e583bf4b28fccb069ce64
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer 

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


clang-analyzer warnings: (new ones prefixed by >>)
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
>> drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
                           do_div(sum, n);
                           ^
   arch/x86/include/asm/div64.h:33:21: note: expanded from macro 'do_div'
                           __upper = __high % (__base);            \
                                     ~~~~~~~^~~~~~~~~~
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: '?' condition is true
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: Taking false branch
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:23: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                         ^
   drivers/md/bcache/sysfs.c:1035:21: note: Loop condition is false.  Exiting loop
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:295:2: note: expanded from macro '__compiletime_assert'
           do {                                                            \
           ^
   drivers/md/bcache/sysfs.c:1037:2: note: '?' condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1037:2: note: Assuming the condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:56:44: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var'

vim +1102 drivers/md/bcache/sysfs.c

58f913dce2814a Peter Foley     2017-10-13  1032  
cafe563591446c Kent Overstreet 2013-03-23  1033  SHOW(__bch_cache)
cafe563591446c Kent Overstreet 2013-03-23  1034  {
cafe563591446c Kent Overstreet 2013-03-23  1035  	struct cache *ca = container_of(kobj, struct cache, kobj);
cafe563591446c Kent Overstreet 2013-03-23  1036  
cafe563591446c Kent Overstreet 2013-03-23  1037  	sysfs_hprint(bucket_size,	bucket_bytes(ca));
cafe563591446c Kent Overstreet 2013-03-23  1038  	sysfs_hprint(block_size,	block_bytes(ca));
cafe563591446c Kent Overstreet 2013-03-23  1039  	sysfs_print(nbuckets,		ca->sb.nbuckets);
cafe563591446c Kent Overstreet 2013-03-23  1040  	sysfs_print(discard,		ca->discard);
cafe563591446c Kent Overstreet 2013-03-23  1041  	sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1042  	sysfs_hprint(btree_written,
cafe563591446c Kent Overstreet 2013-03-23  1043  		     atomic_long_read(&ca->btree_sectors_written) << 9);
cafe563591446c Kent Overstreet 2013-03-23 @1044  	sysfs_hprint(metadata_written,
cafe563591446c Kent Overstreet 2013-03-23  1045  		     (atomic_long_read(&ca->meta_sectors_written) +
cafe563591446c Kent Overstreet 2013-03-23  1046  		      atomic_long_read(&ca->btree_sectors_written)) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1047  
cafe563591446c Kent Overstreet 2013-03-23  1048  	sysfs_print(io_errors,
cafe563591446c Kent Overstreet 2013-03-23  1049  		    atomic_read(&ca->io_errors) >> IO_ERROR_SHIFT);
cafe563591446c Kent Overstreet 2013-03-23  1050  
cafe563591446c Kent Overstreet 2013-03-23  1051  	if (attr == &sysfs_cache_replacement_policy)
169ef1cf6171d3 Kent Overstreet 2013-03-28  1052  		return bch_snprint_string_list(buf, PAGE_SIZE,
cafe563591446c Kent Overstreet 2013-03-23  1053  					       cache_replacement_policies,
cafe563591446c Kent Overstreet 2013-03-23  1054  					       CACHE_REPLACEMENT(&ca->sb));
cafe563591446c Kent Overstreet 2013-03-23  1055  
cafe563591446c Kent Overstreet 2013-03-23  1056  	if (attr == &sysfs_priority_stats) {
15754020524a56 Kent Overstreet 2014-02-25  1057  		struct bucket *b;
15754020524a56 Kent Overstreet 2014-02-25  1058  		size_t n = ca->sb.nbuckets, i;
15754020524a56 Kent Overstreet 2014-02-25  1059  		size_t unused = 0, available = 0, dirty = 0, meta = 0;
cafe563591446c Kent Overstreet 2013-03-23  1060  		uint64_t sum = 0;
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1061  		/* Compute 31 quantiles */
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1062  		uint16_t q[31], *p, *cached;
cafe563591446c Kent Overstreet 2013-03-23  1063  		ssize_t ret;
cafe563591446c Kent Overstreet 2013-03-23  1064  
42bc47b35320e0 Kees Cook       2018-06-12  1065  		cached = p = vmalloc(array_size(sizeof(uint16_t),
42bc47b35320e0 Kees Cook       2018-06-12  1066  						ca->sb.nbuckets));
cafe563591446c Kent Overstreet 2013-03-23  1067  		if (!p)
cafe563591446c Kent Overstreet 2013-03-23  1068  			return -ENOMEM;
cafe563591446c Kent Overstreet 2013-03-23  1069  
cafe563591446c Kent Overstreet 2013-03-23  1070  		mutex_lock(&ca->set->bucket_lock);
15754020524a56 Kent Overstreet 2014-02-25  1071  		for_each_bucket(b, ca) {
15754020524a56 Kent Overstreet 2014-02-25  1072  			if (!GC_SECTORS_USED(b))
15754020524a56 Kent Overstreet 2014-02-25  1073  				unused++;
15754020524a56 Kent Overstreet 2014-02-25  1074  			if (GC_MARK(b) == GC_MARK_RECLAIMABLE)
15754020524a56 Kent Overstreet 2014-02-25  1075  				available++;
15754020524a56 Kent Overstreet 2014-02-25  1076  			if (GC_MARK(b) == GC_MARK_DIRTY)
15754020524a56 Kent Overstreet 2014-02-25  1077  				dirty++;
15754020524a56 Kent Overstreet 2014-02-25  1078  			if (GC_MARK(b) == GC_MARK_METADATA)
15754020524a56 Kent Overstreet 2014-02-25  1079  				meta++;
15754020524a56 Kent Overstreet 2014-02-25  1080  		}
15754020524a56 Kent Overstreet 2014-02-25  1081  
cafe563591446c Kent Overstreet 2013-03-23  1082  		for (i = ca->sb.first_bucket; i < n; i++)
cafe563591446c Kent Overstreet 2013-03-23  1083  			p[i] = ca->buckets[i].prio;
cafe563591446c Kent Overstreet 2013-03-23  1084  		mutex_unlock(&ca->set->bucket_lock);
cafe563591446c Kent Overstreet 2013-03-23  1085  
58f913dce2814a Peter Foley     2017-10-13  1086  		sort(p, n, sizeof(uint16_t), __bch_cache_cmp, NULL);
cafe563591446c Kent Overstreet 2013-03-23  1087  
cafe563591446c Kent Overstreet 2013-03-23  1088  		while (n &&
cafe563591446c Kent Overstreet 2013-03-23  1089  		       !cached[n - 1])
cafe563591446c Kent Overstreet 2013-03-23  1090  			--n;
cafe563591446c Kent Overstreet 2013-03-23  1091  
cafe563591446c Kent Overstreet 2013-03-23  1092  		while (cached < p + n &&
6751c1e3cff3aa Joe Perches     2021-02-10  1093  		       *cached == BTREE_PRIO) {
6751c1e3cff3aa Joe Perches     2021-02-10  1094  			cached++;
6751c1e3cff3aa Joe Perches     2021-02-10  1095  			n--;
6751c1e3cff3aa Joe Perches     2021-02-10  1096  		}
cafe563591446c Kent Overstreet 2013-03-23  1097  
cafe563591446c Kent Overstreet 2013-03-23  1098  		for (i = 0; i < n; i++)
cafe563591446c Kent Overstreet 2013-03-23  1099  			sum += INITIAL_PRIO - cached[i];
cafe563591446c Kent Overstreet 2013-03-23  1100  
cafe563591446c Kent Overstreet 2013-03-23  1101  		if (n)
cafe563591446c Kent Overstreet 2013-03-23 @1102  			do_div(sum, n);
cafe563591446c Kent Overstreet 2013-03-23  1103  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1104  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1105  			q[i] = INITIAL_PRIO - cached[n * (i + 1) /
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1106  				(ARRAY_SIZE(q) + 1)];
cafe563591446c Kent Overstreet 2013-03-23  1107  
cafe563591446c Kent Overstreet 2013-03-23  1108  		vfree(p);
cafe563591446c Kent Overstreet 2013-03-23  1109  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1110  		ret = scnprintf(buf, PAGE_SIZE,
cafe563591446c Kent Overstreet 2013-03-23  1111  				"Unused:		%zu%%\n"
15754020524a56 Kent Overstreet 2014-02-25  1112  				"Clean:		%zu%%\n"
15754020524a56 Kent Overstreet 2014-02-25  1113  				"Dirty:		%zu%%\n"
cafe563591446c Kent Overstreet 2013-03-23  1114  				"Metadata:	%zu%%\n"
cafe563591446c Kent Overstreet 2013-03-23  1115  				"Average:	%llu\n"
cafe563591446c Kent Overstreet 2013-03-23  1116  				"Sectors per Q:	%zu\n"
cafe563591446c Kent Overstreet 2013-03-23  1117  				"Quantiles:	[",
cafe563591446c Kent Overstreet 2013-03-23  1118  				unused * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1119  				available * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1120  				dirty * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1121  				meta * 100 / (size_t) ca->sb.nbuckets, sum,
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1122  				n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1));
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1123  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1124  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1125  			ret += scnprintf(buf + ret, PAGE_SIZE - ret,
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1126  					 "%u ", q[i]);
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1127  		ret--;
cafe563591446c Kent Overstreet 2013-03-23  1128  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1129  		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "]\n");
cafe563591446c Kent Overstreet 2013-03-23  1130  
cafe563591446c Kent Overstreet 2013-03-23  1131  		return ret;
cafe563591446c Kent Overstreet 2013-03-23  1132  	}
cafe563591446c Kent Overstreet 2013-03-23  1133  
cafe563591446c Kent Overstreet 2013-03-23  1134  	return 0;
cafe563591446c Kent Overstreet 2013-03-23  1135  }
cafe563591446c Kent Overstreet 2013-03-23  1136  SHOW_LOCKED(bch_cache)
cafe563591446c Kent Overstreet 2013-03-23  1137  

:::::: The code@line 1102 was first introduced by commit
:::::: cafe563591446cf80bfbc2fe3bc72a2e36cf1060 bcache: A block layer cache

:::::: TO: Kent Overstreet <koverstreet@google.com>
:::::: CC: Kent Overstreet <koverstreet@google.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

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

* drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
@ 2021-11-27 21:50 kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-11-27 21:50 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 24753 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Kees Cook <keescook@chromium.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   c5c17547b778975b3d83a73c8d84e8fb5ecf3ba5
commit: a52f8a59aef46b59753e583bf4b28fccb069ce64 fortify: Explicitly disable Clang support
date:   9 weeks ago
:::::: branch date: 25 hours ago
:::::: commit date: 9 weeks ago
config: i386-randconfig-c001-20211115 (https://download.01.org/0day-ci/archive/20211128/202111280556.6EQ23zfa-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)
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://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a52f8a59aef46b59753e583bf4b28fccb069ce64
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout a52f8a59aef46b59753e583bf4b28fccb069ce64
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer 

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


clang-analyzer warnings: (new ones prefixed by >>)
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
>> drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
                           do_div(sum, n);
                           ^
   arch/x86/include/asm/div64.h:33:21: note: expanded from macro 'do_div'
                           __upper = __high % (__base);            \
                                     ~~~~~~~^~~~~~~~~~
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: '?' condition is true
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: Taking false branch
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:23: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                         ^
   drivers/md/bcache/sysfs.c:1035:21: note: Loop condition is false.  Exiting loop
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:295:2: note: expanded from macro '__compiletime_assert'
           do {                                                            \
           ^
   drivers/md/bcache/sysfs.c:1037:2: note: '?' condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1037:2: note: Assuming the condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:56:44: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var'

vim +1102 drivers/md/bcache/sysfs.c

58f913dce2814a Peter Foley     2017-10-13  1032  
cafe563591446c Kent Overstreet 2013-03-23  1033  SHOW(__bch_cache)
cafe563591446c Kent Overstreet 2013-03-23  1034  {
cafe563591446c Kent Overstreet 2013-03-23  1035  	struct cache *ca = container_of(kobj, struct cache, kobj);
cafe563591446c Kent Overstreet 2013-03-23  1036  
cafe563591446c Kent Overstreet 2013-03-23  1037  	sysfs_hprint(bucket_size,	bucket_bytes(ca));
cafe563591446c Kent Overstreet 2013-03-23  1038  	sysfs_hprint(block_size,	block_bytes(ca));
cafe563591446c Kent Overstreet 2013-03-23  1039  	sysfs_print(nbuckets,		ca->sb.nbuckets);
cafe563591446c Kent Overstreet 2013-03-23  1040  	sysfs_print(discard,		ca->discard);
cafe563591446c Kent Overstreet 2013-03-23  1041  	sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1042  	sysfs_hprint(btree_written,
cafe563591446c Kent Overstreet 2013-03-23  1043  		     atomic_long_read(&ca->btree_sectors_written) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1044  	sysfs_hprint(metadata_written,
cafe563591446c Kent Overstreet 2013-03-23  1045  		     (atomic_long_read(&ca->meta_sectors_written) +
cafe563591446c Kent Overstreet 2013-03-23  1046  		      atomic_long_read(&ca->btree_sectors_written)) << 9);
cafe563591446c Kent Overstreet 2013-03-23  1047  
cafe563591446c Kent Overstreet 2013-03-23  1048  	sysfs_print(io_errors,
cafe563591446c Kent Overstreet 2013-03-23  1049  		    atomic_read(&ca->io_errors) >> IO_ERROR_SHIFT);
cafe563591446c Kent Overstreet 2013-03-23  1050  
cafe563591446c Kent Overstreet 2013-03-23  1051  	if (attr == &sysfs_cache_replacement_policy)
169ef1cf6171d3 Kent Overstreet 2013-03-28  1052  		return bch_snprint_string_list(buf, PAGE_SIZE,
cafe563591446c Kent Overstreet 2013-03-23  1053  					       cache_replacement_policies,
cafe563591446c Kent Overstreet 2013-03-23  1054  					       CACHE_REPLACEMENT(&ca->sb));
cafe563591446c Kent Overstreet 2013-03-23  1055  
cafe563591446c Kent Overstreet 2013-03-23  1056  	if (attr == &sysfs_priority_stats) {
15754020524a56 Kent Overstreet 2014-02-25  1057  		struct bucket *b;
15754020524a56 Kent Overstreet 2014-02-25  1058  		size_t n = ca->sb.nbuckets, i;
15754020524a56 Kent Overstreet 2014-02-25  1059  		size_t unused = 0, available = 0, dirty = 0, meta = 0;
cafe563591446c Kent Overstreet 2013-03-23  1060  		uint64_t sum = 0;
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1061  		/* Compute 31 quantiles */
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1062  		uint16_t q[31], *p, *cached;
cafe563591446c Kent Overstreet 2013-03-23  1063  		ssize_t ret;
cafe563591446c Kent Overstreet 2013-03-23  1064  
42bc47b35320e0 Kees Cook       2018-06-12  1065  		cached = p = vmalloc(array_size(sizeof(uint16_t),
42bc47b35320e0 Kees Cook       2018-06-12  1066  						ca->sb.nbuckets));
cafe563591446c Kent Overstreet 2013-03-23  1067  		if (!p)
cafe563591446c Kent Overstreet 2013-03-23  1068  			return -ENOMEM;
cafe563591446c Kent Overstreet 2013-03-23  1069  
cafe563591446c Kent Overstreet 2013-03-23  1070  		mutex_lock(&ca->set->bucket_lock);
15754020524a56 Kent Overstreet 2014-02-25  1071  		for_each_bucket(b, ca) {
15754020524a56 Kent Overstreet 2014-02-25  1072  			if (!GC_SECTORS_USED(b))
15754020524a56 Kent Overstreet 2014-02-25  1073  				unused++;
15754020524a56 Kent Overstreet 2014-02-25  1074  			if (GC_MARK(b) == GC_MARK_RECLAIMABLE)
15754020524a56 Kent Overstreet 2014-02-25  1075  				available++;
15754020524a56 Kent Overstreet 2014-02-25  1076  			if (GC_MARK(b) == GC_MARK_DIRTY)
15754020524a56 Kent Overstreet 2014-02-25  1077  				dirty++;
15754020524a56 Kent Overstreet 2014-02-25  1078  			if (GC_MARK(b) == GC_MARK_METADATA)
15754020524a56 Kent Overstreet 2014-02-25  1079  				meta++;
15754020524a56 Kent Overstreet 2014-02-25  1080  		}
15754020524a56 Kent Overstreet 2014-02-25  1081  
cafe563591446c Kent Overstreet 2013-03-23  1082  		for (i = ca->sb.first_bucket; i < n; i++)
cafe563591446c Kent Overstreet 2013-03-23  1083  			p[i] = ca->buckets[i].prio;
cafe563591446c Kent Overstreet 2013-03-23  1084  		mutex_unlock(&ca->set->bucket_lock);
cafe563591446c Kent Overstreet 2013-03-23  1085  
58f913dce2814a Peter Foley     2017-10-13  1086  		sort(p, n, sizeof(uint16_t), __bch_cache_cmp, NULL);
cafe563591446c Kent Overstreet 2013-03-23  1087  
cafe563591446c Kent Overstreet 2013-03-23  1088  		while (n &&
cafe563591446c Kent Overstreet 2013-03-23  1089  		       !cached[n - 1])
cafe563591446c Kent Overstreet 2013-03-23  1090  			--n;
cafe563591446c Kent Overstreet 2013-03-23  1091  
cafe563591446c Kent Overstreet 2013-03-23  1092  		while (cached < p + n &&
6751c1e3cff3aa Joe Perches     2021-02-10  1093  		       *cached == BTREE_PRIO) {
6751c1e3cff3aa Joe Perches     2021-02-10  1094  			cached++;
6751c1e3cff3aa Joe Perches     2021-02-10  1095  			n--;
6751c1e3cff3aa Joe Perches     2021-02-10  1096  		}
cafe563591446c Kent Overstreet 2013-03-23  1097  
cafe563591446c Kent Overstreet 2013-03-23  1098  		for (i = 0; i < n; i++)
cafe563591446c Kent Overstreet 2013-03-23  1099  			sum += INITIAL_PRIO - cached[i];
cafe563591446c Kent Overstreet 2013-03-23  1100  
cafe563591446c Kent Overstreet 2013-03-23  1101  		if (n)
cafe563591446c Kent Overstreet 2013-03-23 @1102  			do_div(sum, n);
cafe563591446c Kent Overstreet 2013-03-23  1103  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1104  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1105  			q[i] = INITIAL_PRIO - cached[n * (i + 1) /
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1106  				(ARRAY_SIZE(q) + 1)];
cafe563591446c Kent Overstreet 2013-03-23  1107  
cafe563591446c Kent Overstreet 2013-03-23  1108  		vfree(p);
cafe563591446c Kent Overstreet 2013-03-23  1109  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1110  		ret = scnprintf(buf, PAGE_SIZE,
cafe563591446c Kent Overstreet 2013-03-23  1111  				"Unused:		%zu%%\n"
15754020524a56 Kent Overstreet 2014-02-25  1112  				"Clean:		%zu%%\n"
15754020524a56 Kent Overstreet 2014-02-25  1113  				"Dirty:		%zu%%\n"
cafe563591446c Kent Overstreet 2013-03-23  1114  				"Metadata:	%zu%%\n"
cafe563591446c Kent Overstreet 2013-03-23  1115  				"Average:	%llu\n"
cafe563591446c Kent Overstreet 2013-03-23  1116  				"Sectors per Q:	%zu\n"
cafe563591446c Kent Overstreet 2013-03-23  1117  				"Quantiles:	[",
cafe563591446c Kent Overstreet 2013-03-23  1118  				unused * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1119  				available * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1120  				dirty * 100 / (size_t) ca->sb.nbuckets,
15754020524a56 Kent Overstreet 2014-02-25  1121  				meta * 100 / (size_t) ca->sb.nbuckets, sum,
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1122  				n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1));
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1123  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1124  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1125  			ret += scnprintf(buf + ret, PAGE_SIZE - ret,
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1126  					 "%u ", q[i]);
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1127  		ret--;
cafe563591446c Kent Overstreet 2013-03-23  1128  
bbc77aa7fb72e6 Kent Overstreet 2013-05-28  1129  		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "]\n");
cafe563591446c Kent Overstreet 2013-03-23  1130  
cafe563591446c Kent Overstreet 2013-03-23  1131  		return ret;
cafe563591446c Kent Overstreet 2013-03-23  1132  	}
cafe563591446c Kent Overstreet 2013-03-23  1133  
cafe563591446c Kent Overstreet 2013-03-23  1134  	return 0;
cafe563591446c Kent Overstreet 2013-03-23  1135  }
cafe563591446c Kent Overstreet 2013-03-23  1136  SHOW_LOCKED(bch_cache)
cafe563591446c Kent Overstreet 2013-03-23  1137  

:::::: The code@line 1102 was first introduced by commit
:::::: cafe563591446cf80bfbc2fe3bc72a2e36cf1060 bcache: A block layer cache

:::::: TO: Kent Overstreet <koverstreet@google.com>
:::::: CC: Kent Overstreet <koverstreet@google.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

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

* drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
@ 2021-11-26  6:13 kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-11-26  6:13 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 24859 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Kees Cook <keescook@chromium.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   8ced7ca3570333998ad2088d5a6275701970e28e
commit: a52f8a59aef46b59753e583bf4b28fccb069ce64 fortify: Explicitly disable Clang support
date:   9 weeks ago
:::::: branch date: 11 hours ago
:::::: commit date: 9 weeks ago
config: i386-randconfig-c001-20211115 (https://download.01.org/0day-ci/archive/20211126/202111261418.1JpEdsM1-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project fbe72e41b99dc7994daac300d208a955be3e4a0a)
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://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a52f8a59aef46b59753e583bf4b28fccb069ce64
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout a52f8a59aef46b59753e583bf4b28fccb069ce64
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer 

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


clang-analyzer warnings: (new ones prefixed by >>)
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:740:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_cache_size,          bch_cache_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:751:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(average_key_size,  bch_average_key_size(c));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:778:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(congested,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1037:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1038:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(block_size,        block_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1041:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1042:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(btree_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
   drivers/md/bcache/sysfs.c:1044:2: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
           sysfs_hprint(metadata_written,
           ^
   drivers/md/bcache/sysfs.h:67:3: note: expanded from macro 'sysfs_hprint'
                   strcat(buf, "\n");                                      \
                   ^~~~~~
>> drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero]
                           do_div(sum, n);
                           ^
   arch/x86/include/asm/div64.h:33:21: note: expanded from macro 'do_div'
                           __upper = __high % (__base);            \
                                     ~~~~~~~^~~~~~~~~~
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: '?' condition is true
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1035:21: note: Left side of '&&' is false
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/md/bcache/sysfs.c:1035:21: note: Taking false branch
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:297:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/compiler.h:56:23: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                         ^
   drivers/md/bcache/sysfs.c:1035:21: note: Loop condition is false.  Exiting loop
           struct cache *ca = container_of(kobj, struct cache, kobj);
                              ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:317:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:295:2: note: expanded from macro '__compiletime_assert'
           do {                                                            \
           ^
   drivers/md/bcache/sysfs.c:1037:2: note: '?' condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^
   include/linux/compiler.h:56:28: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ^
   include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                 ^
   drivers/md/bcache/sysfs.c:1037:2: note: Assuming the condition is false
           sysfs_hprint(bucket_size,       bucket_bytes(ca));
           ^
   drivers/md/bcache/sysfs.h:65:2: note: expanded from macro 'sysfs_hprint'
           if (attr == &sysfs_ ## file) {                                  \
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:56:44: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var'

vim +1102 drivers/md/bcache/sysfs.c

58f913dce2814a9 Peter Foley     2017-10-13  1032  
cafe563591446cf Kent Overstreet 2013-03-23  1033  SHOW(__bch_cache)
cafe563591446cf Kent Overstreet 2013-03-23  1034  {
cafe563591446cf Kent Overstreet 2013-03-23  1035  	struct cache *ca = container_of(kobj, struct cache, kobj);
cafe563591446cf Kent Overstreet 2013-03-23  1036  
cafe563591446cf Kent Overstreet 2013-03-23  1037  	sysfs_hprint(bucket_size,	bucket_bytes(ca));
cafe563591446cf Kent Overstreet 2013-03-23  1038  	sysfs_hprint(block_size,	block_bytes(ca));
cafe563591446cf Kent Overstreet 2013-03-23  1039  	sysfs_print(nbuckets,		ca->sb.nbuckets);
cafe563591446cf Kent Overstreet 2013-03-23  1040  	sysfs_print(discard,		ca->discard);
cafe563591446cf Kent Overstreet 2013-03-23  1041  	sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
cafe563591446cf Kent Overstreet 2013-03-23  1042  	sysfs_hprint(btree_written,
cafe563591446cf Kent Overstreet 2013-03-23  1043  		     atomic_long_read(&ca->btree_sectors_written) << 9);
cafe563591446cf Kent Overstreet 2013-03-23 @1044  	sysfs_hprint(metadata_written,
cafe563591446cf Kent Overstreet 2013-03-23  1045  		     (atomic_long_read(&ca->meta_sectors_written) +
cafe563591446cf Kent Overstreet 2013-03-23  1046  		      atomic_long_read(&ca->btree_sectors_written)) << 9);
cafe563591446cf Kent Overstreet 2013-03-23  1047  
cafe563591446cf Kent Overstreet 2013-03-23  1048  	sysfs_print(io_errors,
cafe563591446cf Kent Overstreet 2013-03-23  1049  		    atomic_read(&ca->io_errors) >> IO_ERROR_SHIFT);
cafe563591446cf Kent Overstreet 2013-03-23  1050  
cafe563591446cf Kent Overstreet 2013-03-23  1051  	if (attr == &sysfs_cache_replacement_policy)
169ef1cf6171d35 Kent Overstreet 2013-03-28  1052  		return bch_snprint_string_list(buf, PAGE_SIZE,
cafe563591446cf Kent Overstreet 2013-03-23  1053  					       cache_replacement_policies,
cafe563591446cf Kent Overstreet 2013-03-23  1054  					       CACHE_REPLACEMENT(&ca->sb));
cafe563591446cf Kent Overstreet 2013-03-23  1055  
cafe563591446cf Kent Overstreet 2013-03-23  1056  	if (attr == &sysfs_priority_stats) {
15754020524a565 Kent Overstreet 2014-02-25  1057  		struct bucket *b;
15754020524a565 Kent Overstreet 2014-02-25  1058  		size_t n = ca->sb.nbuckets, i;
15754020524a565 Kent Overstreet 2014-02-25  1059  		size_t unused = 0, available = 0, dirty = 0, meta = 0;
cafe563591446cf Kent Overstreet 2013-03-23  1060  		uint64_t sum = 0;
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1061  		/* Compute 31 quantiles */
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1062  		uint16_t q[31], *p, *cached;
cafe563591446cf Kent Overstreet 2013-03-23  1063  		ssize_t ret;
cafe563591446cf Kent Overstreet 2013-03-23  1064  
42bc47b35320e0e Kees Cook       2018-06-12  1065  		cached = p = vmalloc(array_size(sizeof(uint16_t),
42bc47b35320e0e Kees Cook       2018-06-12  1066  						ca->sb.nbuckets));
cafe563591446cf Kent Overstreet 2013-03-23  1067  		if (!p)
cafe563591446cf Kent Overstreet 2013-03-23  1068  			return -ENOMEM;
cafe563591446cf Kent Overstreet 2013-03-23  1069  
cafe563591446cf Kent Overstreet 2013-03-23  1070  		mutex_lock(&ca->set->bucket_lock);
15754020524a565 Kent Overstreet 2014-02-25  1071  		for_each_bucket(b, ca) {
15754020524a565 Kent Overstreet 2014-02-25  1072  			if (!GC_SECTORS_USED(b))
15754020524a565 Kent Overstreet 2014-02-25  1073  				unused++;
15754020524a565 Kent Overstreet 2014-02-25  1074  			if (GC_MARK(b) == GC_MARK_RECLAIMABLE)
15754020524a565 Kent Overstreet 2014-02-25  1075  				available++;
15754020524a565 Kent Overstreet 2014-02-25  1076  			if (GC_MARK(b) == GC_MARK_DIRTY)
15754020524a565 Kent Overstreet 2014-02-25  1077  				dirty++;
15754020524a565 Kent Overstreet 2014-02-25  1078  			if (GC_MARK(b) == GC_MARK_METADATA)
15754020524a565 Kent Overstreet 2014-02-25  1079  				meta++;
15754020524a565 Kent Overstreet 2014-02-25  1080  		}
15754020524a565 Kent Overstreet 2014-02-25  1081  
cafe563591446cf Kent Overstreet 2013-03-23  1082  		for (i = ca->sb.first_bucket; i < n; i++)
cafe563591446cf Kent Overstreet 2013-03-23  1083  			p[i] = ca->buckets[i].prio;
cafe563591446cf Kent Overstreet 2013-03-23  1084  		mutex_unlock(&ca->set->bucket_lock);
cafe563591446cf Kent Overstreet 2013-03-23  1085  
58f913dce2814a9 Peter Foley     2017-10-13  1086  		sort(p, n, sizeof(uint16_t), __bch_cache_cmp, NULL);
cafe563591446cf Kent Overstreet 2013-03-23  1087  
cafe563591446cf Kent Overstreet 2013-03-23  1088  		while (n &&
cafe563591446cf Kent Overstreet 2013-03-23  1089  		       !cached[n - 1])
cafe563591446cf Kent Overstreet 2013-03-23  1090  			--n;
cafe563591446cf Kent Overstreet 2013-03-23  1091  
cafe563591446cf Kent Overstreet 2013-03-23  1092  		while (cached < p + n &&
6751c1e3cff3aa7 Joe Perches     2021-02-10  1093  		       *cached == BTREE_PRIO) {
6751c1e3cff3aa7 Joe Perches     2021-02-10  1094  			cached++;
6751c1e3cff3aa7 Joe Perches     2021-02-10  1095  			n--;
6751c1e3cff3aa7 Joe Perches     2021-02-10  1096  		}
cafe563591446cf Kent Overstreet 2013-03-23  1097  
cafe563591446cf Kent Overstreet 2013-03-23  1098  		for (i = 0; i < n; i++)
cafe563591446cf Kent Overstreet 2013-03-23  1099  			sum += INITIAL_PRIO - cached[i];
cafe563591446cf Kent Overstreet 2013-03-23  1100  
cafe563591446cf Kent Overstreet 2013-03-23  1101  		if (n)
cafe563591446cf Kent Overstreet 2013-03-23 @1102  			do_div(sum, n);
cafe563591446cf Kent Overstreet 2013-03-23  1103  
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1104  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1105  			q[i] = INITIAL_PRIO - cached[n * (i + 1) /
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1106  				(ARRAY_SIZE(q) + 1)];
cafe563591446cf Kent Overstreet 2013-03-23  1107  
cafe563591446cf Kent Overstreet 2013-03-23  1108  		vfree(p);
cafe563591446cf Kent Overstreet 2013-03-23  1109  
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1110  		ret = scnprintf(buf, PAGE_SIZE,
cafe563591446cf Kent Overstreet 2013-03-23  1111  				"Unused:		%zu%%\n"
15754020524a565 Kent Overstreet 2014-02-25  1112  				"Clean:		%zu%%\n"
15754020524a565 Kent Overstreet 2014-02-25  1113  				"Dirty:		%zu%%\n"
cafe563591446cf Kent Overstreet 2013-03-23  1114  				"Metadata:	%zu%%\n"
cafe563591446cf Kent Overstreet 2013-03-23  1115  				"Average:	%llu\n"
cafe563591446cf Kent Overstreet 2013-03-23  1116  				"Sectors per Q:	%zu\n"
cafe563591446cf Kent Overstreet 2013-03-23  1117  				"Quantiles:	[",
cafe563591446cf Kent Overstreet 2013-03-23  1118  				unused * 100 / (size_t) ca->sb.nbuckets,
15754020524a565 Kent Overstreet 2014-02-25  1119  				available * 100 / (size_t) ca->sb.nbuckets,
15754020524a565 Kent Overstreet 2014-02-25  1120  				dirty * 100 / (size_t) ca->sb.nbuckets,
15754020524a565 Kent Overstreet 2014-02-25  1121  				meta * 100 / (size_t) ca->sb.nbuckets, sum,
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1122  				n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1));
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1123  
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1124  		for (i = 0; i < ARRAY_SIZE(q); i++)
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1125  			ret += scnprintf(buf + ret, PAGE_SIZE - ret,
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1126  					 "%u ", q[i]);
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1127  		ret--;
cafe563591446cf Kent Overstreet 2013-03-23  1128  
bbc77aa7fb72e61 Kent Overstreet 2013-05-28  1129  		ret += scnprintf(buf + ret, PAGE_SIZE - ret, "]\n");
cafe563591446cf Kent Overstreet 2013-03-23  1130  
cafe563591446cf Kent Overstreet 2013-03-23  1131  		return ret;
cafe563591446cf Kent Overstreet 2013-03-23  1132  	}
cafe563591446cf Kent Overstreet 2013-03-23  1133  
cafe563591446cf Kent Overstreet 2013-03-23  1134  	return 0;
cafe563591446cf Kent Overstreet 2013-03-23  1135  }
cafe563591446cf Kent Overstreet 2013-03-23  1136  SHOW_LOCKED(bch_cache)
cafe563591446cf Kent Overstreet 2013-03-23  1137  

:::::: The code@line 1102 was first introduced by commit
:::::: cafe563591446cf80bfbc2fe3bc72a2e36cf1060 bcache: A block layer cache

:::::: TO: Kent Overstreet <koverstreet@google.com>
:::::: CC: Kent Overstreet <koverstreet@google.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

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

end of thread, other threads:[~2022-01-01  8:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-21 11:07 drivers/md/bcache/sysfs.c:1102:4: warning: Division by zero [clang-analyzer-core.DivideZero] kernel test robot
2021-11-26  6:13 kernel test robot
2021-11-27 21:50 kernel test robot
2021-11-30  9:36 kernel test robot
2022-01-01  8:22 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.