use devm and get irq in probe
v2 cover use devm and get irq in probe
Simplifies probe slightly and handles potential -EPROBE_DEFER a bit better.
v2: reword descriptions slightly. Handle iic_force_poll before getting the irq.
Rosen Penev (3):
i2c: ibm_iic: ioremap with platform pointer
i2c: ibm_iic: get the irq early in probe
i2c: ibm_iic: use devm for main allocation
drivers/i2c/busses/i2c-ibm_iic.c | 65 +++++++++++++++----------------- 1 file changed, 31 insertions(+), 34 deletions(-)
Signature · 1 line
2.55.0
PATCH v2 1/3 i2c: ibm_iic: ioremap with platform pointer
Use devm_platform_ioremap_resource() as it only needs a platform_device pointer. Call it early to avoid allocation of the main struct and to avoid having to use goto.
--- drivers/i2c/busses/i2c-ibm_iic.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-ibm_iic.c +6 -11
@@ -38,7 +38,6 @@#include <linux/io.h> #include <linux/i2c.h> #include <linux/of.h> -#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/platform_device.h>
@@ -684,21 +683,21 @@ static int iic_probe(struct platform_device *ofdev)struct device_node *np = ofdev->dev.of_node;struct ibm_iic_private *dev;struct i2c_adapter *adap; +void __iomem *vaddr;const u32 *freq;int ret; + vaddr =devm_platform_ioremap_resource (ofdev,0 ); +if (IS_ERR (vaddr)) +return PTR_ERR (vaddr); + dev =kzalloc_obj (*dev);if (!dev)return -ENOMEM ;platform_set_drvdata (ofdev, dev); - dev->vaddr =of_iomap (np,0 ); -if (dev->vaddr ==NULL ) { -dev_err (&ofdev->dev,"failed to iomap device\n" ); - ret = -ENXIO ; - goto error_cleanup; - } + dev->vaddr = vaddr;init_waitqueue_head (&dev->wq);
@@ -751,9 +750,6 @@ static int iic_probe(struct platform_device *ofdev)free_irq (dev->irq, dev); } -if (dev->vaddr) -iounmap (dev->vaddr); -kfree (dev);return ret; }
@@ -772,7 +768,6 @@ static void iic_remove(struct platform_device *ofdev)free_irq (dev->irq, dev); } -iounmap (dev->vaddr);kfree (dev); }
Signature · 1 line
2.55.0
PATCH v2 2/3 i2c: ibm_iic: get the irq early in probe
In reply to Rosen PenevUse platform_get_irq() which can return -EPROBE_DEFER, unlike irq_of_map_and_parse().
Check for iic_force_poll before doing so to avoid pointless work.
--- drivers/i2c/busses/i2c-ibm_iic.c | 43 ++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-)
drivers/i2c/busses/i2c-ibm_iic.c +24 -19
@@ -648,31 +648,22 @@ static inline u8 iic_clckdiv(unsigned int opb) }static int iic_request_irq (struct platform_device *ofdev, -struct ibm_iic_private *dev) +struct ibm_iic_private *dev) { -struct device_node *np = ofdev->dev.of_node; -int irq; - -if (iic_force_poll) -return 0 ; - - irq =irq_of_parse_and_map (np,0 ); -if (!irq) { -dev_err (&ofdev->dev,"irq_of_parse_and_map failed\n" ); -return 0 ; - } +int ret;/* Disable interrupts until we finish initialization, assumes * level-sensitive IRQ setup... */ iic_interrupt_mode (dev,0 ); -if (request_irq (irq, iic_handler,0 ,"IBM IIC" , dev)) { -dev_err (&ofdev->dev,"request_irq %d failed\n" , irq); + ret = request_irq(dev->irq, iic_handler, 0, "IBM IIC", dev) +if (ret) { +dev_err (&ofdev->dev,"request_irq %d failed\n" , dev->irq);/* Fallback to the polling mode */ -return 0 ; +return ret; } -return irq; +return ret; }/*
@@ -685,12 +676,23 @@ static int iic_probe(struct platform_device *ofdev)struct i2c_adapter *adap;void __iomem *vaddr;const u32 *freq; +int irq;int ret; vaddr =devm_platform_ioremap_resource (ofdev,0 );if (IS_ERR (vaddr))return PTR_ERR (vaddr); +if (iic_force_poll) { + irq =0 ; + }else { + irq =platform_get_irq (ofdev,0 ); +if (irq == -EPROBE_DEFER ) +return irq; +if (irq <0 ) +dev_warn (&ofdev->dev,"using polling mode\n" ); + } + dev =kzalloc_obj (*dev);if (!dev)return -ENOMEM ;
@@ -701,9 +703,12 @@ static int iic_probe(struct platform_device *ofdev)init_waitqueue_head (&dev->wq); - dev->irq =iic_request_irq (ofdev, dev); -if (!dev->irq) -dev_warn (&ofdev->dev,"using polling mode\n" ); + dev->irq = irq; +if (dev->irq >0 ) { + ret =iic_request_irq (ofdev, dev, irq); +if (ret) + dev->irq =0 ; + }/* Board specific settings */ if (iic_force_fast ||of_get_property (np,"fast-mode" ,NULL ))
Signature · 1 line
2.55.0
PATCH v2 3/3 i2c: ibm_iic: use devm for main allocation
In reply to Rosen PenevGet rid of kfree in failure and remove paths.
--- drivers/i2c/busses/i2c-ibm_iic.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/i2c/busses/i2c-ibm_iic.c +1 -4
@@ -693,7 +693,7 @@ static int iic_probe(struct platform_device *ofdev)dev_warn (&ofdev->dev,"using polling mode\n" ); } - dev =kzalloc_obj (*dev); + dev =devm_kzalloc (&ofdev->dev,sizeof (*dev),GFP_KERNEL );if (!dev)return -ENOMEM ;
@@ -755,7 +755,6 @@ static int iic_probe(struct platform_device *ofdev)free_irq (dev->irq, dev); } -kfree (dev);return ret; }
@@ -772,8 +771,6 @@ static void iic_remove(struct platform_device *ofdev)iic_interrupt_mode (dev,0 );free_irq (dev->irq, dev); } - -kfree (dev); }static const struct of_device_id ibm_iic_match[] = {
Signature · 1 line
2.55.0