linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Correctly handle plaform_get_irq()'s result in the i2C drivers
@ 2021-06-23 20:48 Sergey Shtylyov
  2021-06-23 20:53 ` [PATCH 1/5] i2c: hix5hd2: fix IRQ check Sergey Shtylyov
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Sergey Shtylyov @ 2021-06-23 20:48 UTC (permalink / raw)
  To: linux-i2c
  Cc: Qii Wang, Matthias Brugger, linux-arm-kernel, linux-mediatek,
	linux-samsung-soc

Here are 5 patches against the 'i2c/for-current' branch of the Jens Axboe's 'linux-block.git' repo.
The affected drivers call platform_get_irq() but mis-interprete its result -- they consider
IRQ0 as error and (sometimes) the real error codes as valid IRQs... :-/

[1/5] i2c: hix5hd2: fix IRQ check
[2/5] i2c: mt65xx: fix IRQ check
[3/5] i2c: pmcmsp: fix-IRQ-check
[4/5] i2c: s3c2410: fix IRQ check
[5/5] i2c: xlp9xx: fix main IRQ check

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

* [PATCH 1/5] i2c: hix5hd2: fix IRQ check
  2021-06-23 20:48 [PATCH 0/5] Correctly handle plaform_get_irq()'s result in the i2C drivers Sergey Shtylyov
@ 2021-06-23 20:53 ` Sergey Shtylyov
  2021-06-23 20:56 ` [PATCH 2/5] i2c: mt65xx: " Sergey Shtylyov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sergey Shtylyov @ 2021-06-23 20:53 UTC (permalink / raw)
  To: linux-i2c

Iff platform_get_irq() returns 0, the driver's probe() method will return 0
early (as if the method's call was successful).  Let's consider IRQ0 valid
for simplicity -- devm_request_irq() can always override that decision...

Fixes: 15ef27756b23 ("i2c: hix5hd2: add i2c controller driver")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
 drivers/i2c/busses/i2c-hix5hd2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/drivers/i2c/busses/i2c-hix5hd2.c
===================================================================
--- linux.orig/drivers/i2c/busses/i2c-hix5hd2.c
+++ linux/drivers/i2c/busses/i2c-hix5hd2.c
@@ -413,7 +413,7 @@ static int hix5hd2_i2c_probe(struct plat
 		return PTR_ERR(priv->regs);
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq <= 0)
+	if (irq < 0)
 		return irq;
 
 	priv->clk = devm_clk_get(&pdev->dev, NULL);

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

* [PATCH 2/5] i2c: mt65xx: fix IRQ check
  2021-06-23 20:48 [PATCH 0/5] Correctly handle plaform_get_irq()'s result in the i2C drivers Sergey Shtylyov
  2021-06-23 20:53 ` [PATCH 1/5] i2c: hix5hd2: fix IRQ check Sergey Shtylyov
@ 2021-06-23 20:56 ` Sergey Shtylyov
  2021-06-23 20:58 ` [PATCH 3/5] i2c: pmcmsp: fix-IRQ-check Sergey Shtylyov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sergey Shtylyov @ 2021-06-23 20:56 UTC (permalink / raw)
  To: linux-i2c; +Cc: Qii Wang, Matthias Brugger, linux-arm-kernel, linux-mediatek

Iff platform_get_irq() returns 0, the driver's probe() method will return 0
early (as if the method's call was successful).  Let's consider IRQ0 valid
for simplicity -- devm_request_irq() can always override that decision...

Fixes: ce38815d39ea ("I2C: mediatek: Add driver for MediaTek I2C controller")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omprussia.ru>

---
 drivers/i2c/busses/i2c-mt65xx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/drivers/i2c/busses/i2c-mt65xx.c
===================================================================
--- linux.orig/drivers/i2c/busses/i2c-mt65xx.c
+++ linux/drivers/i2c/busses/i2c-mt65xx.c
@@ -1211,7 +1211,7 @@ static int mtk_i2c_probe(struct platform
 		return PTR_ERR(i2c->pdmabase);
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq <= 0)
+	if (irq < 0)
 		return irq;
 
 	init_completion(&i2c->msg_complete);

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

* [PATCH 3/5] i2c: pmcmsp: fix-IRQ-check
  2021-06-23 20:48 [PATCH 0/5] Correctly handle plaform_get_irq()'s result in the i2C drivers Sergey Shtylyov
  2021-06-23 20:53 ` [PATCH 1/5] i2c: hix5hd2: fix IRQ check Sergey Shtylyov
  2021-06-23 20:56 ` [PATCH 2/5] i2c: mt65xx: " Sergey Shtylyov
@ 2021-06-23 20:58 ` Sergey Shtylyov
  2021-06-29  7:19   ` [kbuild] " Dan Carpenter
  2021-06-23 21:01 ` [PATCH 4/5] i2c: s3c2410: fix IRQ check Sergey Shtylyov
  2021-06-23 21:06 ` [PATCH 5/5] i2c: xlp9xx: fix main " Sergey Shtylyov
  4 siblings, 1 reply; 7+ messages in thread
From: Sergey Shtylyov @ 2021-06-23 20:58 UTC (permalink / raw)
  To: linux-i2c

The driver's probe() method is written as if platform_get_irq() returns 0
on error, while actually it returns a negative error code (with all the
other values considered valid IRQs).  Rewrite the driver's IRQ checking
code to pass the positive IRQ #s to request_irq(), propagate -EPROBE_DEFER
upstream, and use the polling mode when platform_get_irq() returns negative
error code or 0...

Fixes: 1b144df1d7d6 ("i2c: New PMC MSP71xx TWI bus driver")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
 drivers/i2c/busses/i2c-pmcmsp.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Index: linux/drivers/i2c/busses/i2c-pmcmsp.c
===================================================================
--- linux.orig/drivers/i2c/busses/i2c-pmcmsp.c
+++ linux/drivers/i2c/busses/i2c-pmcmsp.c
@@ -291,8 +291,13 @@ static int pmcmsptwi_probe(struct platfo
 	}
 
 	/* request the irq */
-	pmcmsptwi_data.irq = platform_get_irq(pldev, 0);
-	if (pmcmsptwi_data.irq) {
+	rc = platform_get_irq(pldev, 0);
+	if (rc == -EPROBE_DEFER)
+		return rc;
+	if (rc <= 0) {
+		pmcmsptwi_data.irq = 0;
+	} else {
+		pmcmsptwi_data.irq = rc;
 		rc = request_irq(pmcmsptwi_data.irq, &pmcmsptwi_interrupt,
 				 IRQF_SHARED, pldev->name, &pmcmsptwi_data);
 		if (rc == 0) {



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

* [PATCH 4/5] i2c: s3c2410: fix IRQ check
  2021-06-23 20:48 [PATCH 0/5] Correctly handle plaform_get_irq()'s result in the i2C drivers Sergey Shtylyov
                   ` (2 preceding siblings ...)
  2021-06-23 20:58 ` [PATCH 3/5] i2c: pmcmsp: fix-IRQ-check Sergey Shtylyov
@ 2021-06-23 21:01 ` Sergey Shtylyov
  2021-06-23 21:06 ` [PATCH 5/5] i2c: xlp9xx: fix main " Sergey Shtylyov
  4 siblings, 0 replies; 7+ messages in thread
From: Sergey Shtylyov @ 2021-06-23 21:01 UTC (permalink / raw)
  To: linux-i2c; +Cc: linux-samsung-soc

Iff platform_get_irq() returns 0, the driver's probe() method will return 0
early (as if the method's call was successful).  Let's consider IRQ0 valid
for simplicity -- devm_request_irq() can always override that decision...

Fixes: 2bbd681ba2b ("i2c-s3c2410: Change IRQ to be plain integer.")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
 drivers/i2c/busses/i2c-s3c2410.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/drivers/i2c/busses/i2c-s3c2410.c
===================================================================
--- linux.orig/drivers/i2c/busses/i2c-s3c2410.c
+++ linux/drivers/i2c/busses/i2c-s3c2410.c
@@ -1137,7 +1137,7 @@ static int s3c24xx_i2c_probe(struct plat
 	 */
 	if (!(i2c->quirks & QUIRK_POLL)) {
 		i2c->irq = ret = platform_get_irq(pdev, 0);
-		if (ret <= 0) {
+		if (ret < 0) {
 			dev_err(&pdev->dev, "cannot find IRQ\n");
 			clk_unprepare(i2c->clk);
 			return ret;

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

* [PATCH 5/5] i2c: xlp9xx: fix main IRQ check
  2021-06-23 20:48 [PATCH 0/5] Correctly handle plaform_get_irq()'s result in the i2C drivers Sergey Shtylyov
                   ` (3 preceding siblings ...)
  2021-06-23 21:01 ` [PATCH 4/5] i2c: s3c2410: fix IRQ check Sergey Shtylyov
@ 2021-06-23 21:06 ` Sergey Shtylyov
  4 siblings, 0 replies; 7+ messages in thread
From: Sergey Shtylyov @ 2021-06-23 21:06 UTC (permalink / raw)
  To: linux-i2c, George Cherian

Iff platform_get_irq() returns 0 for the main IRQ, the driver's probe()
method will return 0 early (as if the method's call was successful).
Let's consider IRQ0 valid for simplicity -- devm_request_irq() can always
override that decision...

Fixes: 2bbd681ba2b ("i2c: xlp9xx: Driver for Netlogic XLP9XX/5XX I2C controller")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
 drivers/i2c/busses/i2c-xlp9xx.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux/drivers/i2c/busses/i2c-xlp9xx.c
===================================================================
--- linux.orig/drivers/i2c/busses/i2c-xlp9xx.c
+++ linux/drivers/i2c/busses/i2c-xlp9xx.c
@@ -517,7 +517,7 @@ static int xlp9xx_i2c_probe(struct platf
 		return PTR_ERR(priv->base);
 
 	priv->irq = platform_get_irq(pdev, 0);
-	if (priv->irq <= 0)
+	if (priv->irq < 0)
 		return priv->irq;
 	/* SMBAlert irq */
 	priv->alert_data.irq = platform_get_irq(pdev, 1);

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

* [kbuild] Re: [PATCH 3/5] i2c: pmcmsp: fix-IRQ-check
  2021-06-23 20:58 ` [PATCH 3/5] i2c: pmcmsp: fix-IRQ-check Sergey Shtylyov
@ 2021-06-29  7:19   ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2021-06-29  7:19 UTC (permalink / raw)
  To: kbuild, Sergey Shtylyov, linux-i2c; +Cc: lkp, kbuild-all

Hi Sergey,

url:    https://github.com/0day-ci/linux/commits/Sergey-Shtylyov/Correctly-handle-plaform_get_irq-s-result-in-the-i2C-drivers/20210624-050805 
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git  i2c/for-next
config: microblaze-randconfig-m031-20210628 (attached as .config)
compiler: microblaze-linux-gcc (GCC) 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>

smatch warnings:
drivers/i2c/busses/i2c-pmcmsp.c:355 pmcmsptwi_probe() warn: 'pmcmsptwi_data.iobase' not released on lines: 296.
drivers/i2c/busses/i2c-pmcmsp.c:355 pmcmsptwi_probe() warn: 'res->start' not released on lines: 296.

vim +355 drivers/i2c/busses/i2c-pmcmsp.c

0b255e927d47b5 Bill Pemberton      2012-11-27  261  static int pmcmsptwi_probe(struct platform_device *pldev)
1b144df1d7d69d Marc St-Jean        2007-07-12  262  {
1b144df1d7d69d Marc St-Jean        2007-07-12  263  	struct resource *res;
1b144df1d7d69d Marc St-Jean        2007-07-12  264  	int rc = -ENODEV;
1b144df1d7d69d Marc St-Jean        2007-07-12  265  
1b144df1d7d69d Marc St-Jean        2007-07-12  266  	/* get the static platform resources */
1b144df1d7d69d Marc St-Jean        2007-07-12  267  	res = platform_get_resource(pldev, IORESOURCE_MEM, 0);
1b144df1d7d69d Marc St-Jean        2007-07-12  268  	if (!res) {
1b144df1d7d69d Marc St-Jean        2007-07-12  269  		dev_err(&pldev->dev, "IOMEM resource not found\n");
1b144df1d7d69d Marc St-Jean        2007-07-12  270  		goto ret_err;
1b144df1d7d69d Marc St-Jean        2007-07-12  271  	}
1b144df1d7d69d Marc St-Jean        2007-07-12  272  
1b144df1d7d69d Marc St-Jean        2007-07-12  273  	/* reserve the memory region */
c6ffddea36dd57 Linus Walleij       2009-06-14  274  	if (!request_mem_region(res->start, resource_size(res),
1b144df1d7d69d Marc St-Jean        2007-07-12  275  				pldev->name)) {
1b144df1d7d69d Marc St-Jean        2007-07-12  276  		dev_err(&pldev->dev,
066e6e805d4af2 Krzysztof Kozlowski 2020-01-15  277  			"Unable to get memory/io address region %pap\n",
066e6e805d4af2 Krzysztof Kozlowski 2020-01-15  278  			&res->start);
1b144df1d7d69d Marc St-Jean        2007-07-12  279  		rc = -EBUSY;
1b144df1d7d69d Marc St-Jean        2007-07-12  280  		goto ret_err;
1b144df1d7d69d Marc St-Jean        2007-07-12  281  	}
1b144df1d7d69d Marc St-Jean        2007-07-12  282  
1b144df1d7d69d Marc St-Jean        2007-07-12  283  	/* remap the memory */
4bdc0d676a6431 Christoph Hellwig   2020-01-06  284  	pmcmsptwi_data.iobase = ioremap(res->start,
c6ffddea36dd57 Linus Walleij       2009-06-14  285  						resource_size(res));
1b144df1d7d69d Marc St-Jean        2007-07-12  286  	if (!pmcmsptwi_data.iobase) {
1b144df1d7d69d Marc St-Jean        2007-07-12  287  		dev_err(&pldev->dev,
066e6e805d4af2 Krzysztof Kozlowski 2020-01-15  288  			"Unable to ioremap address %pap\n", &res->start);
1b144df1d7d69d Marc St-Jean        2007-07-12  289  		rc = -EIO;
1b144df1d7d69d Marc St-Jean        2007-07-12  290  		goto ret_unreserve;
1b144df1d7d69d Marc St-Jean        2007-07-12  291  	}
1b144df1d7d69d Marc St-Jean        2007-07-12  292  
1b144df1d7d69d Marc St-Jean        2007-07-12  293  	/* request the irq */
fa227704e6a1e0 Sergey Shtylyov     2021-06-23  294  	rc = platform_get_irq(pldev, 0);
fa227704e6a1e0 Sergey Shtylyov     2021-06-23  295  	if (rc == -EPROBE_DEFER)
fa227704e6a1e0 Sergey Shtylyov     2021-06-23  296  		return rc;

Need to clean up the ioremap() and the request_mem_region().

fa227704e6a1e0 Sergey Shtylyov     2021-06-23  297  	if (rc <= 0) {
fa227704e6a1e0 Sergey Shtylyov     2021-06-23  298  		pmcmsptwi_data.irq = 0;
fa227704e6a1e0 Sergey Shtylyov     2021-06-23  299  	} else {
fa227704e6a1e0 Sergey Shtylyov     2021-06-23  300  		pmcmsptwi_data.irq = rc;
1b144df1d7d69d Marc St-Jean        2007-07-12  301  		rc = request_irq(pmcmsptwi_data.irq, &pmcmsptwi_interrupt,
d38a0149e8a11c Theodore Ts'o       2012-07-17  302  				 IRQF_SHARED, pldev->name, &pmcmsptwi_data);
1b144df1d7d69d Marc St-Jean        2007-07-12  303  		if (rc == 0) {
1b144df1d7d69d Marc St-Jean        2007-07-12  304  			/*
1b144df1d7d69d Marc St-Jean        2007-07-12  305  			 * Enable 'DONE' interrupt only.
1b144df1d7d69d Marc St-Jean        2007-07-12  306  			 *
1b144df1d7d69d Marc St-Jean        2007-07-12  307  			 * If you enable all interrupts, you will get one on
1b144df1d7d69d Marc St-Jean        2007-07-12  308  			 * error and another when the operation completes.
1b144df1d7d69d Marc St-Jean        2007-07-12  309  			 * This way you only have to handle one interrupt,
1b144df1d7d69d Marc St-Jean        2007-07-12  310  			 * but you can still check all result flags.
1b144df1d7d69d Marc St-Jean        2007-07-12  311  			 */
1b144df1d7d69d Marc St-Jean        2007-07-12  312  			pmcmsptwi_writel(MSP_TWI_INT_STS_DONE,
1b144df1d7d69d Marc St-Jean        2007-07-12  313  					pmcmsptwi_data.iobase +
1b144df1d7d69d Marc St-Jean        2007-07-12  314  					MSP_TWI_INT_MSK_REG_OFFSET);
1b144df1d7d69d Marc St-Jean        2007-07-12  315  		} else {
1b144df1d7d69d Marc St-Jean        2007-07-12  316  			dev_warn(&pldev->dev,
1b144df1d7d69d Marc St-Jean        2007-07-12  317  				"Could not assign TWI IRQ handler "
1b144df1d7d69d Marc St-Jean        2007-07-12  318  				"to irq %d (continuing with poll)\n",
1b144df1d7d69d Marc St-Jean        2007-07-12  319  				pmcmsptwi_data.irq);
1b144df1d7d69d Marc St-Jean        2007-07-12  320  			pmcmsptwi_data.irq = 0;
1b144df1d7d69d Marc St-Jean        2007-07-12  321  		}
1b144df1d7d69d Marc St-Jean        2007-07-12  322  	}
1b144df1d7d69d Marc St-Jean        2007-07-12  323  
1b144df1d7d69d Marc St-Jean        2007-07-12  324  	init_completion(&pmcmsptwi_data.wait);
1b144df1d7d69d Marc St-Jean        2007-07-12  325  	mutex_init(&pmcmsptwi_data.lock);
1b144df1d7d69d Marc St-Jean        2007-07-12  326  
1b144df1d7d69d Marc St-Jean        2007-07-12  327  	pmcmsptwi_set_clock_config(&pmcmsptwi_defclockcfg, &pmcmsptwi_data);
1b144df1d7d69d Marc St-Jean        2007-07-12  328  	pmcmsptwi_set_twi_config(&pmcmsptwi_defcfg, &pmcmsptwi_data);
1b144df1d7d69d Marc St-Jean        2007-07-12  329  
1b144df1d7d69d Marc St-Jean        2007-07-12  330  	printk(KERN_INFO DRV_NAME ": Registering MSP71xx I2C adapter\n");
1b144df1d7d69d Marc St-Jean        2007-07-12  331  
1b144df1d7d69d Marc St-Jean        2007-07-12  332  	pmcmsptwi_adapter.dev.parent = &pldev->dev;
1b144df1d7d69d Marc St-Jean        2007-07-12  333  	platform_set_drvdata(pldev, &pmcmsptwi_adapter);
1b144df1d7d69d Marc St-Jean        2007-07-12  334  	i2c_set_adapdata(&pmcmsptwi_adapter, &pmcmsptwi_data);
1b144df1d7d69d Marc St-Jean        2007-07-12  335  
1b144df1d7d69d Marc St-Jean        2007-07-12  336  	rc = i2c_add_adapter(&pmcmsptwi_adapter);
ea734404f3daf1 Wolfram Sang        2016-08-09  337  	if (rc)
1b144df1d7d69d Marc St-Jean        2007-07-12  338  		goto ret_unmap;
1b144df1d7d69d Marc St-Jean        2007-07-12  339  
1b144df1d7d69d Marc St-Jean        2007-07-12  340  	return 0;
1b144df1d7d69d Marc St-Jean        2007-07-12  341  
1b144df1d7d69d Marc St-Jean        2007-07-12  342  ret_unmap:
1b144df1d7d69d Marc St-Jean        2007-07-12  343  	if (pmcmsptwi_data.irq) {
1b144df1d7d69d Marc St-Jean        2007-07-12  344  		pmcmsptwi_writel(0,
1b144df1d7d69d Marc St-Jean        2007-07-12  345  			pmcmsptwi_data.iobase + MSP_TWI_INT_MSK_REG_OFFSET);
1b144df1d7d69d Marc St-Jean        2007-07-12  346  		free_irq(pmcmsptwi_data.irq, &pmcmsptwi_data);
1b144df1d7d69d Marc St-Jean        2007-07-12  347  	}
1b144df1d7d69d Marc St-Jean        2007-07-12  348  
1b144df1d7d69d Marc St-Jean        2007-07-12  349  	iounmap(pmcmsptwi_data.iobase);
1b144df1d7d69d Marc St-Jean        2007-07-12  350  
1b144df1d7d69d Marc St-Jean        2007-07-12  351  ret_unreserve:
c6ffddea36dd57 Linus Walleij       2009-06-14  352  	release_mem_region(res->start, resource_size(res));
1b144df1d7d69d Marc St-Jean        2007-07-12  353  
1b144df1d7d69d Marc St-Jean        2007-07-12  354  ret_err:
1b144df1d7d69d Marc St-Jean        2007-07-12 @355  	return rc;
1b144df1d7d69d Marc St-Jean        2007-07-12  356  }

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

_______________________________________________
kbuild mailing list -- kbuild@lists.01.org
To unsubscribe send an email to kbuild-leave@lists.01.org


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

end of thread, other threads:[~2021-06-29  7:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23 20:48 [PATCH 0/5] Correctly handle plaform_get_irq()'s result in the i2C drivers Sergey Shtylyov
2021-06-23 20:53 ` [PATCH 1/5] i2c: hix5hd2: fix IRQ check Sergey Shtylyov
2021-06-23 20:56 ` [PATCH 2/5] i2c: mt65xx: " Sergey Shtylyov
2021-06-23 20:58 ` [PATCH 3/5] i2c: pmcmsp: fix-IRQ-check Sergey Shtylyov
2021-06-29  7:19   ` [kbuild] " Dan Carpenter
2021-06-23 21:01 ` [PATCH 4/5] i2c: s3c2410: fix IRQ check Sergey Shtylyov
2021-06-23 21:06 ` [PATCH 5/5] i2c: xlp9xx: fix main " Sergey Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).