From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org
Subject: [freescale-fslc:5.4-2.3.x-imx 12739/16811] drivers/i2c/busses/i2c-imx-lpi2c.c:243 lpi2c_imx_config() warn: the 'I2C_CLK_RATIO' macro might need parens
Date: Fri, 29 Jan 2021 11:02:36 +0300 [thread overview]
Message-ID: <20210129080236.GM2696@kadam> (raw)
[-- Attachment #1: Type: text/plain, Size: 3882 bytes --]
tree: https://github.com/Freescale/linux-fslc 5.4-2.3.x-imx
head: 549889f65d65baa0e9efa8790dc81ce8c580d842
commit: 124d288c85caab0f868cec5387a1a32f39871392 [12739/16811] MLK-24495 i2c: lpi2c: fix i2c timing issue
config: x86_64-randconfig-m001-20210129 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
New smatch warnings:
drivers/i2c/busses/i2c-imx-lpi2c.c:243 lpi2c_imx_config() warn: the 'I2C_CLK_RATIO' macro might need parens
vim +/I2C_CLK_RATIO +243 drivers/i2c/busses/i2c-imx-lpi2c.c
a55fa9d0e42e31 Gao Pan 2016-11-30 220 static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)
a55fa9d0e42e31 Gao Pan 2016-11-30 221 {
a55fa9d0e42e31 Gao Pan 2016-11-30 222 u8 prescale, filt, sethold, clkhi, clklo, datavd;
a55fa9d0e42e31 Gao Pan 2016-11-30 223 unsigned int clk_rate, clk_cycle;
a55fa9d0e42e31 Gao Pan 2016-11-30 224 enum lpi2c_imx_pincfg pincfg;
a55fa9d0e42e31 Gao Pan 2016-11-30 225 unsigned int temp;
a55fa9d0e42e31 Gao Pan 2016-11-30 226
a55fa9d0e42e31 Gao Pan 2016-11-30 227 lpi2c_imx_set_mode(lpi2c_imx);
a55fa9d0e42e31 Gao Pan 2016-11-30 228
c846995d43e1d2 Gao Pan 2018-01-19 229 clk_rate = clk_get_rate(lpi2c_imx->clk_per);
c846995d43e1d2 Gao Pan 2018-01-19 230 if (!clk_rate) {
c846995d43e1d2 Gao Pan 2018-01-19 231 dev_dbg(&lpi2c_imx->adapter.dev, "clk_per rate is 0\n");
c846995d43e1d2 Gao Pan 2018-01-19 232 return -EINVAL;
c846995d43e1d2 Gao Pan 2018-01-19 233 }
c846995d43e1d2 Gao Pan 2018-01-19 234
a55fa9d0e42e31 Gao Pan 2016-11-30 235 if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
a55fa9d0e42e31 Gao Pan 2016-11-30 236 filt = 0;
a55fa9d0e42e31 Gao Pan 2016-11-30 237 else
a55fa9d0e42e31 Gao Pan 2016-11-30 238 filt = 2;
a55fa9d0e42e31 Gao Pan 2016-11-30 239
a55fa9d0e42e31 Gao Pan 2016-11-30 240 for (prescale = 0; prescale <= 7; prescale++) {
a55fa9d0e42e31 Gao Pan 2016-11-30 241 clk_cycle = clk_rate / ((1 << prescale) * lpi2c_imx->bitrate)
124d288c85caab Clark Wang 2020-08-19 242 - (2 + filt) / (1 << prescale);
124d288c85caab Clark Wang 2020-08-19 @243 clkhi = clk_cycle * I2C_CLK_RATIO;
This code is correct and adding parentheses would break it. The define
is:
#define I2C_CLK_RATIO 24 / 59
Obvioulsy 24 / 59 is zero. So the multiplication has to be done first:
(clk_cycle * 24) / 59 which is what happens now. But checkpatch
encourages people to add parentheses so they will then the code will be:
clkhi = clk_cycle * (24 / 59);
Which is the same as "clkhi = 0;". In other words, this code works for
now but soon it will be broken.
a55fa9d0e42e31 Gao Pan 2016-11-30 244 clklo = clk_cycle - clkhi;
a55fa9d0e42e31 Gao Pan 2016-11-30 245 if (clklo < 64)
a55fa9d0e42e31 Gao Pan 2016-11-30 246 break;
a55fa9d0e42e31 Gao Pan 2016-11-30 247 }
a55fa9d0e42e31 Gao Pan 2016-11-30 248
a55fa9d0e42e31 Gao Pan 2016-11-30 249 if (prescale > 7)
a55fa9d0e42e31 Gao Pan 2016-11-30 250 return -EINVAL;
a55fa9d0e42e31 Gao Pan 2016-11-30 251
a55fa9d0e42e31 Gao Pan 2016-11-30 252 /* set MCFGR1: PINCFG, PRESCALE, IGNACK */
a55fa9d0e42e31 Gao Pan 2016-11-30 253 if (lpi2c_imx->mode == ULTRA_FAST)
a55fa9d0e42e31 Gao Pan 2016-11-30 254 pincfg = TWO_PIN_OO;
a55fa9d0e42e31 Gao Pan 2016-11-30 255 else
a55fa9d0e42e31 Gao Pan 2016-11-30 256 pincfg = TWO_PIN_OD;
a55fa9d0e42e31 Gao Pan 2016-11-30 257 temp = prescale | pincfg << 24;
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 40633 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild-all@lists.01.org
Subject: [freescale-fslc:5.4-2.3.x-imx 12739/16811] drivers/i2c/busses/i2c-imx-lpi2c.c:243 lpi2c_imx_config() warn: the 'I2C_CLK_RATIO' macro might need parens
Date: Fri, 29 Jan 2021 11:02:36 +0300 [thread overview]
Message-ID: <20210129080236.GM2696@kadam> (raw)
[-- Attachment #1: Type: text/plain, Size: 3882 bytes --]
tree: https://github.com/Freescale/linux-fslc 5.4-2.3.x-imx
head: 549889f65d65baa0e9efa8790dc81ce8c580d842
commit: 124d288c85caab0f868cec5387a1a32f39871392 [12739/16811] MLK-24495 i2c: lpi2c: fix i2c timing issue
config: x86_64-randconfig-m001-20210129 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
New smatch warnings:
drivers/i2c/busses/i2c-imx-lpi2c.c:243 lpi2c_imx_config() warn: the 'I2C_CLK_RATIO' macro might need parens
vim +/I2C_CLK_RATIO +243 drivers/i2c/busses/i2c-imx-lpi2c.c
a55fa9d0e42e31 Gao Pan 2016-11-30 220 static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)
a55fa9d0e42e31 Gao Pan 2016-11-30 221 {
a55fa9d0e42e31 Gao Pan 2016-11-30 222 u8 prescale, filt, sethold, clkhi, clklo, datavd;
a55fa9d0e42e31 Gao Pan 2016-11-30 223 unsigned int clk_rate, clk_cycle;
a55fa9d0e42e31 Gao Pan 2016-11-30 224 enum lpi2c_imx_pincfg pincfg;
a55fa9d0e42e31 Gao Pan 2016-11-30 225 unsigned int temp;
a55fa9d0e42e31 Gao Pan 2016-11-30 226
a55fa9d0e42e31 Gao Pan 2016-11-30 227 lpi2c_imx_set_mode(lpi2c_imx);
a55fa9d0e42e31 Gao Pan 2016-11-30 228
c846995d43e1d2 Gao Pan 2018-01-19 229 clk_rate = clk_get_rate(lpi2c_imx->clk_per);
c846995d43e1d2 Gao Pan 2018-01-19 230 if (!clk_rate) {
c846995d43e1d2 Gao Pan 2018-01-19 231 dev_dbg(&lpi2c_imx->adapter.dev, "clk_per rate is 0\n");
c846995d43e1d2 Gao Pan 2018-01-19 232 return -EINVAL;
c846995d43e1d2 Gao Pan 2018-01-19 233 }
c846995d43e1d2 Gao Pan 2018-01-19 234
a55fa9d0e42e31 Gao Pan 2016-11-30 235 if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
a55fa9d0e42e31 Gao Pan 2016-11-30 236 filt = 0;
a55fa9d0e42e31 Gao Pan 2016-11-30 237 else
a55fa9d0e42e31 Gao Pan 2016-11-30 238 filt = 2;
a55fa9d0e42e31 Gao Pan 2016-11-30 239
a55fa9d0e42e31 Gao Pan 2016-11-30 240 for (prescale = 0; prescale <= 7; prescale++) {
a55fa9d0e42e31 Gao Pan 2016-11-30 241 clk_cycle = clk_rate / ((1 << prescale) * lpi2c_imx->bitrate)
124d288c85caab Clark Wang 2020-08-19 242 - (2 + filt) / (1 << prescale);
124d288c85caab Clark Wang 2020-08-19 @243 clkhi = clk_cycle * I2C_CLK_RATIO;
This code is correct and adding parentheses would break it. The define
is:
#define I2C_CLK_RATIO 24 / 59
Obvioulsy 24 / 59 is zero. So the multiplication has to be done first:
(clk_cycle * 24) / 59 which is what happens now. But checkpatch
encourages people to add parentheses so they will then the code will be:
clkhi = clk_cycle * (24 / 59);
Which is the same as "clkhi = 0;". In other words, this code works for
now but soon it will be broken.
a55fa9d0e42e31 Gao Pan 2016-11-30 244 clklo = clk_cycle - clkhi;
a55fa9d0e42e31 Gao Pan 2016-11-30 245 if (clklo < 64)
a55fa9d0e42e31 Gao Pan 2016-11-30 246 break;
a55fa9d0e42e31 Gao Pan 2016-11-30 247 }
a55fa9d0e42e31 Gao Pan 2016-11-30 248
a55fa9d0e42e31 Gao Pan 2016-11-30 249 if (prescale > 7)
a55fa9d0e42e31 Gao Pan 2016-11-30 250 return -EINVAL;
a55fa9d0e42e31 Gao Pan 2016-11-30 251
a55fa9d0e42e31 Gao Pan 2016-11-30 252 /* set MCFGR1: PINCFG, PRESCALE, IGNACK */
a55fa9d0e42e31 Gao Pan 2016-11-30 253 if (lpi2c_imx->mode == ULTRA_FAST)
a55fa9d0e42e31 Gao Pan 2016-11-30 254 pincfg = TWO_PIN_OO;
a55fa9d0e42e31 Gao Pan 2016-11-30 255 else
a55fa9d0e42e31 Gao Pan 2016-11-30 256 pincfg = TWO_PIN_OD;
a55fa9d0e42e31 Gao Pan 2016-11-30 257 temp = prescale | pincfg << 24;
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 40633 bytes --]
next reply other threads:[~2021-01-29 8:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 8:02 Dan Carpenter [this message]
2021-01-29 8:02 ` [freescale-fslc:5.4-2.3.x-imx 12739/16811] drivers/i2c/busses/i2c-imx-lpi2c.c:243 lpi2c_imx_config() warn: the 'I2C_CLK_RATIO' macro might need parens Dan Carpenter
-- strict thread matches above, loose matches on Subject: below --
2021-01-29 6:39 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=20210129080236.GM2696@kadam \
--to=dan.carpenter@oracle.com \
--cc=kbuild@lists.01.org \
/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.