:::::: 
:::::: Manual check reason: "low confidence bisect report"
:::::: Manual check reason: "low confidence static check warning: 
drivers/misc/habanalabs/common/state_dump.c:79:9: warning: use of NULL 'buf' 
where non-null expected [CWE-476] [-Wanalyzer-null-argument]"
:::::: 

CC: kbuild-...@lists.01.org
BCC: l...@intel.com
CC: linux-ker...@vger.kernel.org
TO: Yuri Nudelman <ynudel...@habana.ai>
CC: Oded Gabbay <ogab...@kernel.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   3abc3ae553c7ed73365b385b9a4cffc5176aae45
commit: 938b793fdede518e10c67dc1dcfba1804faf98a6 habanalabs: expose state dump
date:   10 months ago
:::::: branch date: 7 hours ago
:::::: commit date: 10 months ago
config: arm-randconfig-c002-20220622 
(https://download.01.org/0day-ci/archive/20220623/202206230303.7cwoibwp-...@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
        chmod +x ~/bin/make.cross
        # 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=938b793fdede518e10c67dc1dcfba1804faf98a6
        git remote add linus 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout 938b793fdede518e10c67dc1dcfba1804faf98a6
        # save the config file
         ARCH=arm KBUILD_USERCFLAGS='-fanalyzer -Wno-error' 

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <l...@intel.com>


gcc-analyzer warnings: (new ones prefixed by >>)
   drivers/misc/habanalabs/common/state_dump.c: In function 'resize_to_fit':
>> drivers/misc/habanalabs/common/state_dump.c:79:9: warning: use of NULL 'buf' 
>> where non-null expected [CWE-476] [-Wanalyzer-null-argument]
      79 |         memcpy(resized_buf, *buf, *size);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     'hl_state_dump': event 1
       |
       |  428 | int hl_state_dump(struct hl_device *hdev)
       |      |     ^~~~~~~~~~~~~
       |      |     |
       |      |     (1) entry to 'hl_state_dump'
       |
     'hl_state_dump': event 2
       |
       |cc1:
       | (2): 'buf' is NULL
       |
     'hl_state_dump': event 3
       |
       |  434 |         rc = hl_snprintf_resize(&buf, &size, &offset,
       |      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       |      |              |
       |      |              (3) calling 'hl_snprintf_resize' from 
'hl_state_dump'
       |  435 |                                 "Timestamp taken on: %llu\n\n",
       |      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       |  436 |                                 ktime_to_ns(ktime_get()));
       |      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~
       |
       +--> 'hl_snprintf_resize': events 4-9
              |
              |  104 | int hl_snprintf_resize(char **buf, size_t *size, size_t 
*offset,
              |      |     ^~~~~~~~~~~~~~~~~~
              |      |     |
              |      |     (4) entry to 'hl_snprintf_resize'
              |......
              |  111 |         if (*buf == NULL && (*size != 0 || *offset != 0))
              |      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              |      |            ||            |   |
              |      |            ||            |   (8) ...to here
              |      |            ||            (9) following 'false' branch...
              |      |            |(5) 'buf' is NULL
              |      |            |(6) 'buf' is NULL
              |      |            (7) following 'true' branch...
              |
            'hl_snprintf_resize': event 10
              |
              |  114 |         va_start(args, format);
              |      |         ^~~~~~~~
              |      |         |
              |      |         (10) ...to here
              |
            'hl_snprintf_resize': events 11-13
              |
              |  115 |         length = vsnprintf(*buf + *offset, *size - 
*offset, format, args);
              |      |                  
~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              |      |                  |         |
              |      |                  |         (11) 'buf' is NULL
              |      |                  (12) 'buf' is NULL
              |......
              |  118 |         rc = resize_to_fit(buf, size, *offset + length + 
1);
              |      |              
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              |      |              |
              |      |              (13) calling 'resize_to_fit' from 
'hl_snprintf_resize'
              |
              +--> 'resize_to_fit': events 14-15
                     |
                     |   66 | static int resize_to_fit(char **buf, size_t 
*size, size_t desired_size)
                     |      |            ^~~~~~~~~~~~~
                     |      |            |
                     |      |            (14) entry to 'resize_to_fit'
                     |......
                     |   71 |         if (*size >= desired_size)
                     |      |            ~
                     |      |            |
                     |      |            (15) following 'false' branch...
                     |
                   'resize_to_fit': event 16
                     |
                     |include/linux/math.h:24:30:
                     |   24 | #define round_up(x, y) ((((x)-1) | 
__round_mask(x, y))+1)
                     |      |                          ~~~~^~~
                     |      |                              |
                     |      |                              (16) ...to here
   include/linux/minmax.h:32:39: note: in definition of macro '__cmp_once'
                     |   32 |                 typeof(y) unique_y = (y);         
      \
                     |      |                                       ^
   include/linux/minmax.h:112:33: note: in expansion of macro '__careful_cmp'
                     |  112 | #define max_t(type, x, y)       
__careful_cmp((type)(x), (type)(y), >)
                     |      |                                 ^~~~~~~~~~~~~
   drivers/misc/habanalabs/common/state_dump.c:75:20: note: in expansion of 
macro 'max_t'
                     |   75 |         new_size = max_t(size_t, PAGE_SIZE, 
round_up(desired_size, PAGE_SIZE));
                     |      |                    ^~~~~
   drivers/misc/habanalabs/common/state_dump.c:75:45: note: in expansion of 
macro 'round_up'
                     |   75 |         new_size = max_t(size_t, PAGE_SIZE, 
round_up(desired_size, PAGE_SIZE));
                     |      |                                             
^~~~~~~~
                     |
                   'resize_to_fit': events 17-21
                     |
                     |   77 |         if (!resized_buf)
                     |      |            ^
                     |      |            |
                     |      |            (17) following 'false' branch (when 
'resized_buf' is non-NULL)...
                     |   78 |                 return -ENOMEM;

vim +/buf +79 drivers/misc/habanalabs/common/state_dump.c

938b793fdede51 Yuri Nudelman 2021-06-06  55  
938b793fdede51 Yuri Nudelman 2021-06-06  56  /**
938b793fdede51 Yuri Nudelman 2021-06-06  57   * resize_to_fit - helper 
function, resize buffer to fit given amount of data
938b793fdede51 Yuri Nudelman 2021-06-06  58   * @buf: destination buffer double 
pointer
938b793fdede51 Yuri Nudelman 2021-06-06  59   * @size: pointer to the size 
container
938b793fdede51 Yuri Nudelman 2021-06-06  60   * @desired_size: size the buffer 
must contain
938b793fdede51 Yuri Nudelman 2021-06-06  61   *
938b793fdede51 Yuri Nudelman 2021-06-06  62   * Returns 0 on success or error 
code on failure.
938b793fdede51 Yuri Nudelman 2021-06-06  63   * On success, the size of buffer 
is at least desired_size. Buffer is allocated
938b793fdede51 Yuri Nudelman 2021-06-06  64   * via vmalloc and must be freed 
with vfree.
938b793fdede51 Yuri Nudelman 2021-06-06  65   */
938b793fdede51 Yuri Nudelman 2021-06-06  66  static int resize_to_fit(char 
**buf, size_t *size, size_t desired_size)
938b793fdede51 Yuri Nudelman 2021-06-06  67  {
938b793fdede51 Yuri Nudelman 2021-06-06  68     char *resized_buf;
938b793fdede51 Yuri Nudelman 2021-06-06  69     size_t new_size;
938b793fdede51 Yuri Nudelman 2021-06-06  70  
938b793fdede51 Yuri Nudelman 2021-06-06  71     if (*size >= desired_size)
938b793fdede51 Yuri Nudelman 2021-06-06  72             return 0;
938b793fdede51 Yuri Nudelman 2021-06-06  73  
938b793fdede51 Yuri Nudelman 2021-06-06  74     /* Not enough space to print 
all, have to resize */
938b793fdede51 Yuri Nudelman 2021-06-06  75     new_size = max_t(size_t, 
PAGE_SIZE, round_up(desired_size, PAGE_SIZE));
938b793fdede51 Yuri Nudelman 2021-06-06  76     resized_buf = vmalloc(new_size);
938b793fdede51 Yuri Nudelman 2021-06-06  77     if (!resized_buf)
938b793fdede51 Yuri Nudelman 2021-06-06  78             return -ENOMEM;
938b793fdede51 Yuri Nudelman 2021-06-06 @79     memcpy(resized_buf, *buf, 
*size);
938b793fdede51 Yuri Nudelman 2021-06-06  80     vfree(*buf);
938b793fdede51 Yuri Nudelman 2021-06-06  81     *buf = resized_buf;
938b793fdede51 Yuri Nudelman 2021-06-06  82     *size = new_size;
938b793fdede51 Yuri Nudelman 2021-06-06  83  
938b793fdede51 Yuri Nudelman 2021-06-06  84     return 1;
938b793fdede51 Yuri Nudelman 2021-06-06  85  }
938b793fdede51 Yuri Nudelman 2021-06-06  86  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp
_______________________________________________
kbuild mailing list -- kbuild@lists.01.org
To unsubscribe send an email to kbuild-le...@lists.01.org

Reply via email to