All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: oe-kbuild@lists.linux.dev
Cc: lkp@intel.com, Dan Carpenter <error27@gmail.com>
Subject: drivers/spi/spi-amd.c:253 amd_set_spi_freq() error: buffer overflow 'amd_spi_freq' 9 <= 9 (assuming for loop doesn't break)
Date: Mon, 30 Oct 2023 22:42:38 +0800	[thread overview]
Message-ID: <202310302226.EbVZndWM-lkp@intel.com> (raw)

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
CC: linux-kernel@vger.kernel.org
TO: Lucas Tanure <tanureal@opensource.cirrus.com>
CC: Mark Brown <broonie@kernel.org>
CC: Shreeya Patel <shreeya.patel@collabora.com>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   ffc253263a1375a65fa6c9f62a893e9767fbebfa
commit: 3fe26121dc3a9bf64e18fe0075cd9a92c9cd1b1a spi: amd: Configure device speed
date:   1 year, 2 months ago
:::::: branch date: 12 hours ago
:::::: commit date: 1 year, 2 months ago
config: x86_64-randconfig-x005-20230705 (https://download.01.org/0day-ci/archive/20231030/202310302226.EbVZndWM-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231030/202310302226.EbVZndWM-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202310302226.EbVZndWM-lkp@intel.com/

New smatch warnings:
drivers/spi/spi-amd.c:253 amd_set_spi_freq() error: buffer overflow 'amd_spi_freq' 9 <= 9 (assuming for loop doesn't break)

Old smatch warnings:
drivers/spi/spi-amd.c:256 amd_set_spi_freq() error: buffer overflow 'amd_spi_freq' 9 <= 9 (assuming for loop doesn't break)
drivers/spi/spi-amd.c:258 amd_set_spi_freq() error: buffer overflow 'amd_spi_freq' 9 <= 9 (assuming for loop doesn't break)
drivers/spi/spi-amd.c:267 amd_set_spi_freq() error: buffer overflow 'amd_spi_freq' 9 <= 9 (assuming for loop doesn't break)
drivers/spi/spi-amd.c:268 amd_set_spi_freq() error: buffer overflow 'amd_spi_freq' 9 <= 9 (assuming for loop doesn't break)

vim +253 drivers/spi/spi-amd.c

3fe26121dc3a9b Lucas Tanure 2022-08-25  238  
3fe26121dc3a9b Lucas Tanure 2022-08-25  239  static int amd_set_spi_freq(struct amd_spi *amd_spi, u32 speed_hz)
3fe26121dc3a9b Lucas Tanure 2022-08-25  240  {
3fe26121dc3a9b Lucas Tanure 2022-08-25  241  	unsigned int i, spd7_val, alt_spd;
3fe26121dc3a9b Lucas Tanure 2022-08-25  242  
3fe26121dc3a9b Lucas Tanure 2022-08-25  243  	if (speed_hz == amd_spi->speed_hz)
3fe26121dc3a9b Lucas Tanure 2022-08-25  244  		return 0;
3fe26121dc3a9b Lucas Tanure 2022-08-25  245  
3fe26121dc3a9b Lucas Tanure 2022-08-25  246  	if (speed_hz < AMD_SPI_MIN_HZ)
3fe26121dc3a9b Lucas Tanure 2022-08-25  247  		return -EINVAL;
3fe26121dc3a9b Lucas Tanure 2022-08-25  248  
3fe26121dc3a9b Lucas Tanure 2022-08-25  249  	for (i = 0; i < ARRAY_SIZE(amd_spi_freq); i++)
3fe26121dc3a9b Lucas Tanure 2022-08-25  250  		if (speed_hz >= amd_spi_freq[i].speed_hz)
3fe26121dc3a9b Lucas Tanure 2022-08-25  251  			break;
3fe26121dc3a9b Lucas Tanure 2022-08-25  252  
3fe26121dc3a9b Lucas Tanure 2022-08-25 @253  	if (speed_hz == amd_spi_freq[i].speed_hz)
3fe26121dc3a9b Lucas Tanure 2022-08-25  254  		return 0;
3fe26121dc3a9b Lucas Tanure 2022-08-25  255  
3fe26121dc3a9b Lucas Tanure 2022-08-25  256  	amd_spi->speed_hz = amd_spi_freq[i].speed_hz;
3fe26121dc3a9b Lucas Tanure 2022-08-25  257  
3fe26121dc3a9b Lucas Tanure 2022-08-25  258  	alt_spd = (amd_spi_freq[i].enable_val << AMD_SPI_ALT_SPD_SHIFT)
3fe26121dc3a9b Lucas Tanure 2022-08-25  259  		   & AMD_SPI_ALT_SPD_MASK;
3fe26121dc3a9b Lucas Tanure 2022-08-25  260  	amd_spi_setclear_reg32(amd_spi, AMD_SPI_ENA_REG, alt_spd,
3fe26121dc3a9b Lucas Tanure 2022-08-25  261  			       AMD_SPI_ALT_SPD_MASK);
3fe26121dc3a9b Lucas Tanure 2022-08-25  262  
3fe26121dc3a9b Lucas Tanure 2022-08-25  263  	if (amd_spi->speed_hz == AMD_SPI_MAX_HZ)
3fe26121dc3a9b Lucas Tanure 2022-08-25  264  		amd_spi_setclear_reg32(amd_spi, AMD_SPI_ENA_REG, 1,
3fe26121dc3a9b Lucas Tanure 2022-08-25  265  				       AMD_SPI_SPI100_MASK);
3fe26121dc3a9b Lucas Tanure 2022-08-25  266  
3fe26121dc3a9b Lucas Tanure 2022-08-25  267  	if (amd_spi_freq[i].spd7_val) {
3fe26121dc3a9b Lucas Tanure 2022-08-25  268  		spd7_val = (amd_spi_freq[i].spd7_val << AMD_SPI_SPD7_SHIFT)
3fe26121dc3a9b Lucas Tanure 2022-08-25  269  			    & AMD_SPI_SPD7_MASK;
3fe26121dc3a9b Lucas Tanure 2022-08-25  270  		amd_spi_setclear_reg32(amd_spi, AMD_SPI_SPEED_REG, spd7_val,
3fe26121dc3a9b Lucas Tanure 2022-08-25  271  				       AMD_SPI_SPD7_MASK);
3fe26121dc3a9b Lucas Tanure 2022-08-25  272  	}
3fe26121dc3a9b Lucas Tanure 2022-08-25  273  
3fe26121dc3a9b Lucas Tanure 2022-08-25  274  	return 0;
3fe26121dc3a9b Lucas Tanure 2022-08-25  275  }
3fe26121dc3a9b Lucas Tanure 2022-08-25  276  

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

             reply	other threads:[~2023-10-30 14:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-30 14:42 kernel test robot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-10-31 12:04 drivers/spi/spi-amd.c:253 amd_set_spi_freq() error: buffer overflow 'amd_spi_freq' 9 <= 9 (assuming for loop doesn't break) kernel test robot
2023-10-31 14:58 kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202310302226.EbVZndWM-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=error27@gmail.com \
    --cc=oe-kbuild@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.