Skip to contentSkip to conversation

i2c: cadence: Add an error handling for platform_get_irq()

PATCH In review Dejin Zheng 3 participants 7 messages May 20, 2020 – May 23, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: cadence: Add an error handling for platform_get_irq()

The driver initialization should be end immediately after found the platform_get_irq() function return an error.

Fixes df8eb5691c48d3b0 ("i2c: Add driver for Cadence I2C controller")

---
v1 -> v2:
- add Fixes tag.

 drivers/i2c/busses/i2c-cadence.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-cadence.c +2 -0
index 89d58f7d2a25..0e8debe32cea 100644
@@ -912,6 +912,8 @@ static int cdns_i2c_probe(struct platform_device *pdev)
 		return PTR_ERR(id->membase);
 
 	id->irq = platform_get_irq(pdev, 0);
+	if (id->irq < 0)
+		return id->irq;
 
 	id->adap.owner = THIS_MODULE;
 	id->adap.dev.of_node = pdev->dev.of_node;
Signature · 1 line
2.25.0
Acked-by on v2 1/1
#1 lore raw
Quoted 4 lines · Dejin Zheng

The driver initialization should be end immediately after found the platform_get_irq() function return an error.

Fixes df8eb5691c48d3b0 ("i2c: Add driver for Cadence I2C controller")

I wouldn't really consider this as bug. Driver is likely not failing when irq is not defined. It should just fail later on when devm_request_irq is called.
Or is there any other issue with it?

Quoted 14 lines

---
v1 -> v2:
- add Fixes tag.

 drivers/i2c/busses/i2c-cadence.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-cadence.c +0 -0
index 89d58f7d2a25..0e8debe32cea 100644

drivers/i2c/busses/i2c-cadence.c static int cdns_i2c_probe(struct platform_device *pdev) · line 919

Quoted 8 lines
drivers/i2c/busses/i2c-cadence.c +2 -0
@@ -912,6 +912,8 @@ static int cdns_i2c_probe(struct platform_device *pdev)
 		return PTR_ERR(id->membase);
 
 	id->irq = platform_get_irq(pdev, 0);
+	if (id->irq < 0)
+		return id->irq;
 
 	id->adap.owner = THIS_MODULE;
 	id->adap.dev.of_node = pdev->dev.of_node;

The change is valid but the question is if make sense to do it in this way. Some drivers are using devm_request_irq to do do job.

For example:

 	id->irq = platform_get_irq(pdev, 0);
        ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0,
                                  DRIVER_NAME, id);
        if (ret)
		return ret;

But I am also fine with solution above where you fail in quickest way.

Without that Fixed tag

Thanks,
Michal

#2 lore raw
Quoted 10 lines

The change is valid but the question is if make sense to do it in this way. Some drivers are using devm_request_irq to do do job.

For example:

 	id->irq = platform_get_irq(pdev, 0);
        ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0,
                                  DRIVER_NAME, id);
        if (ret)
		return ret;

I like this version better. Maybe we should simply move the platform_get_irq() line to the devm_request_irq() call?

#3 lore raw
Quoted 11 lines · Wolfram Sang
Quoted 10 lines

The change is valid but the question is if make sense to do it in this way. Some drivers are using devm_request_irq to do do job.

For example:

 	id->irq = platform_get_irq(pdev, 0);
        ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0,
                                  DRIVER_NAME, id);
        if (ret)
		return ret;
Quoted 2 lines

I like this version better. Maybe we should simply move the platform_get_irq() line to the devm_request_irq() call?

You know about
devm_platform_get_and_ioremap_resource()
usage.
Maybe that's the way to go. Because as of today there is no way to pass
position of irq resource.

But I expect it will come in near future.

Thanks,
Michal

#5 lore raw
Quoted 7 lines · Wolfram Sang
Quoted 7 lines

You know about
devm_platform_get_and_ioremap_resource()
usage.
Maybe that's the way to go. Because as of today there is no way to pass
position of irq resource.

Quoted 6 lines
Quoted 1 line

But I expect it will come in near future.

Has been tried, has been nacked:

http://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/

Wolfram and Michal, Thanks very much for your comments, I will resend devm_platform_request_irq() again.

BR,
Dejin

#6 lore raw
In reply to Michal Simek
Quoted 44 lines · Michal Simek
Quoted 4 lines · Dejin Zheng

The driver initialization should be end immediately after found the platform_get_irq() function return an error.

Fixes df8eb5691c48d3b0 ("i2c: Add driver for Cadence I2C controller")

I wouldn't really consider this as bug. Driver is likely not failing when irq is not defined. It should just fail later on when devm_request_irq is called.
Or is there any other issue with it?

Quoted 14 lines

---
v1 -> v2:
- add Fixes tag.

 drivers/i2c/busses/i2c-cadence.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-cadence.c +0 -0
index 89d58f7d2a25..0e8debe32cea 100644

drivers/i2c/busses/i2c-cadence.c static int cdns_i2c_probe(struct platform_device *pdev) · line 919

Quoted 8 lines
drivers/i2c/busses/i2c-cadence.c +2 -0
@@ -912,6 +912,8 @@ static int cdns_i2c_probe(struct platform_device *pdev)
 		return PTR_ERR(id->membase);
 
 	id->irq = platform_get_irq(pdev, 0);
+	if (id->irq < 0)
+		return id->irq;
 
 	id->adap.owner = THIS_MODULE;
 	id->adap.dev.of_node = pdev->dev.of_node;

The change is valid but the question is if make sense to do it in this way. Some drivers are using devm_request_irq to do do job.

For example:

 	id->irq = platform_get_irq(pdev, 0);
        ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0,
                                  DRIVER_NAME, id);
        if (ret)
		return ret;
Quoted 5 lines

But I am also fine with solution above where you fail in quickest way.

Without that Fixed tag

Michal, Thanks very much for review my patch, As you said, maybe the better way is provide a function like the devm_platform_get_and_ioremap_resource(). So I resend a patch of I gave up before, It's here now:
https://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/

Abandon this patch and Thanks again!

BR,
Dejin

Quoted 2 lines

Thanks,
Michal