All of lore.kernel.org
 help / color / mirror / Atom feed
* [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
@ 2021-01-29  6:39 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-01-29  6:39 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
TO: Otavio Salvador <otavio@ossystems.com.br>

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
:::::: branch date: 6 hours ago
:::::: commit date: 5 months ago
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

Old smatch warnings:
drivers/i2c/busses/i2c-imx-lpi2c.c:583 lpi2c_imx_init_recovery_info() warn: passing zero to 'PTR_ERR'

vim +/I2C_CLK_RATIO +243 drivers/i2c/busses/i2c-imx-lpi2c.c

a55fa9d0e42e31 Gao Pan    2016-11-30  217  
124d288c85caab Clark Wang 2020-08-19  218  /* CLKLO = (1 - I2C_CLK_RATIO) * clk_cycle, SETHOLD = CLKHI, DATAVD = CLKHI/2
124d288c85caab Clark Wang 2020-08-19  219     CLKHI = I2C_CLK_RATIO * clk_cycle */
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;
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;
a55fa9d0e42e31 Gao Pan    2016-11-30  258  
a55fa9d0e42e31 Gao Pan    2016-11-30  259  	if (lpi2c_imx->mode == ULTRA_FAST)
a55fa9d0e42e31 Gao Pan    2016-11-30  260  		temp |= MCFGR1_IGNACK;
a55fa9d0e42e31 Gao Pan    2016-11-30  261  
a55fa9d0e42e31 Gao Pan    2016-11-30  262  	writel(temp, lpi2c_imx->base + LPI2C_MCFGR1);
a55fa9d0e42e31 Gao Pan    2016-11-30  263  
a55fa9d0e42e31 Gao Pan    2016-11-30  264  	/* set MCFGR2: FILTSDA, FILTSCL */
a55fa9d0e42e31 Gao Pan    2016-11-30  265  	temp = (filt << 16) | (filt << 24);
a55fa9d0e42e31 Gao Pan    2016-11-30  266  	writel(temp, lpi2c_imx->base + LPI2C_MCFGR2);
a55fa9d0e42e31 Gao Pan    2016-11-30  267  
a55fa9d0e42e31 Gao Pan    2016-11-30  268  	/* set MCCR: DATAVD, SETHOLD, CLKHI, CLKLO */
a55fa9d0e42e31 Gao Pan    2016-11-30  269  	sethold = clkhi;
a55fa9d0e42e31 Gao Pan    2016-11-30  270  	datavd = clkhi >> 1;
a55fa9d0e42e31 Gao Pan    2016-11-30  271  	temp = datavd << 24 | sethold << 16 | clkhi << 8 | clklo;
a55fa9d0e42e31 Gao Pan    2016-11-30  272  
a55fa9d0e42e31 Gao Pan    2016-11-30  273  	if (lpi2c_imx->mode == HS)
a55fa9d0e42e31 Gao Pan    2016-11-30  274  		writel(temp, lpi2c_imx->base + LPI2C_MCCR1);
a55fa9d0e42e31 Gao Pan    2016-11-30  275  	else
a55fa9d0e42e31 Gao Pan    2016-11-30  276  		writel(temp, lpi2c_imx->base + LPI2C_MCCR0);
a55fa9d0e42e31 Gao Pan    2016-11-30  277  
a55fa9d0e42e31 Gao Pan    2016-11-30  278  	return 0;
a55fa9d0e42e31 Gao Pan    2016-11-30  279  }
a55fa9d0e42e31 Gao Pan    2016-11-30  280  

---
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: 40633 bytes --]

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

* [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
@ 2021-01-29  8:02 ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2021-01-29  8:02 UTC (permalink / raw)
  To: kbuild

[-- 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 --]

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

* [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
@ 2021-01-29  8:02 ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2021-01-29  8:02 UTC (permalink / raw)
  To: kbuild-all

[-- 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 --]

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

end of thread, other threads:[~2021-01-29  8:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2021-01-29  8:02 ` Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2021-01-29  6:39 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.