summaryrefslogtreecommitdiffstats
path: root/drivers/irqchip
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2019-05-27 08:04:12 -0400
committerMarc Zyngier <marc.zyngier@arm.com>2019-05-29 05:42:26 -0400
commit4770533f71de8d1891795d92b55633d82a80f882 (patch)
tree26938aab0c998130849960f621dda1907e64f27b /drivers/irqchip
parent000e20c510819fa209b4fd37d5038e41f9885e0e (diff)
irqchip/renesas-irqc: Convert to managed initializations
Simplify error handling by converting the driver to use managed allocations and initializations. Note that platform_get_resource() and ioremap_nocache() are combined in devm_platform_ioremap_resource(). Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Simon Horman <horms+renesas@verge.net.au> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'drivers/irqchip')
-rw-r--r--drivers/irqchip/irq-renesas-irqc.c54
1 files changed, 15 insertions, 39 deletions
diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
index af03ee31a87b..cde9f9c0687e 100644
--- a/drivers/irqchip/irq-renesas-irqc.c
+++ b/drivers/irqchip/irq-renesas-irqc.c
@@ -126,16 +126,13 @@ static int irqc_probe(struct platform_device *pdev)
126 struct device *dev = &pdev->dev; 126 struct device *dev = &pdev->dev;
127 const char *name = dev_name(dev); 127 const char *name = dev_name(dev);
128 struct irqc_priv *p; 128 struct irqc_priv *p;
129 struct resource *io;
130 struct resource *irq; 129 struct resource *irq;
131 int ret; 130 int ret;
132 int k; 131 int k;
133 132
134 p = kzalloc(sizeof(*p), GFP_KERNEL); 133 p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
135 if (!p) { 134 if (!p)
136 ret = -ENOMEM; 135 return -ENOMEM;
137 goto err0;
138 }
139 136
140 p->dev = dev; 137 p->dev = dev;
141 platform_set_drvdata(pdev, p); 138 platform_set_drvdata(pdev, p);
@@ -143,14 +140,6 @@ static int irqc_probe(struct platform_device *pdev)
143 pm_runtime_enable(dev); 140 pm_runtime_enable(dev);
144 pm_runtime_get_sync(dev); 141 pm_runtime_get_sync(dev);
145 142
146 /* get hold of manadatory IOMEM */
147 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
148 if (!io) {
149 dev_err(dev, "not enough IOMEM resources\n");
150 ret = -EINVAL;
151 goto err1;
152 }
153
154 /* allow any number of IRQs between 1 and IRQC_IRQ_MAX */ 143 /* allow any number of IRQs between 1 and IRQC_IRQ_MAX */
155 for (k = 0; k < IRQC_IRQ_MAX; k++) { 144 for (k = 0; k < IRQC_IRQ_MAX; k++) {
156 irq = platform_get_resource(pdev, IORESOURCE_IRQ, k); 145 irq = platform_get_resource(pdev, IORESOURCE_IRQ, k);
@@ -166,14 +155,14 @@ static int irqc_probe(struct platform_device *pdev)
166 if (p->number_of_irqs < 1) { 155 if (p->number_of_irqs < 1) {
167 dev_err(dev, "not enough IRQ resources\n"); 156 dev_err(dev, "not enough IRQ resources\n");
168 ret = -EINVAL; 157 ret = -EINVAL;
169 goto err1; 158 goto err_runtime_pm_disable;
170 } 159 }
171 160
172 /* ioremap IOMEM and setup read/write callbacks */ 161 /* ioremap IOMEM and setup read/write callbacks */
173 p->iomem = ioremap_nocache(io->start, resource_size(io)); 162 p->iomem = devm_platform_ioremap_resource(pdev, 0);
174 if (!p->iomem) { 163 if (IS_ERR(p->iomem)) {
175 ret = -ENXIO; 164 ret = PTR_ERR(p->iomem);
176 goto err2; 165 goto err_runtime_pm_disable;
177 } 166 }
178 167
179 p->cpu_int_base = p->iomem + IRQC_INT_CPU_BASE(0); /* SYS-SPI */ 168 p->cpu_int_base = p->iomem + IRQC_INT_CPU_BASE(0); /* SYS-SPI */
@@ -183,7 +172,7 @@ static int irqc_probe(struct platform_device *pdev)
183 if (!p->irq_domain) { 172 if (!p->irq_domain) {
184 ret = -ENXIO; 173 ret = -ENXIO;
185 dev_err(dev, "cannot initialize irq domain\n"); 174 dev_err(dev, "cannot initialize irq domain\n");
186 goto err2; 175 goto err_runtime_pm_disable;
187 } 176 }
188 177
189 ret = irq_alloc_domain_generic_chips(p->irq_domain, p->number_of_irqs, 178 ret = irq_alloc_domain_generic_chips(p->irq_domain, p->number_of_irqs,
@@ -191,7 +180,7 @@ static int irqc_probe(struct platform_device *pdev)
191 0, 0, IRQ_GC_INIT_NESTED_LOCK); 180 0, 0, IRQ_GC_INIT_NESTED_LOCK);
192 if (ret) { 181 if (ret) {
193 dev_err(dev, "cannot allocate generic chip\n"); 182 dev_err(dev, "cannot allocate generic chip\n");
194 goto err3; 183 goto err_remove_domain;
195 } 184 }
196 185
197 p->gc = irq_get_domain_generic_chip(p->irq_domain, 0); 186 p->gc = irq_get_domain_generic_chip(p->irq_domain, 0);
@@ -206,46 +195,33 @@ static int irqc_probe(struct platform_device *pdev)
206 195
207 /* request interrupts one by one */ 196 /* request interrupts one by one */
208 for (k = 0; k < p->number_of_irqs; k++) { 197 for (k = 0; k < p->number_of_irqs; k++) {
209 if (request_irq(p->irq[k].requested_irq, irqc_irq_handler, 198 if (devm_request_irq(dev, p->irq[k].requested_irq,
210 0, name, &p->irq[k])) { 199 irqc_irq_handler, 0, name, &p->irq[k])) {
211 dev_err(dev, "failed to request IRQ\n"); 200 dev_err(dev, "failed to request IRQ\n");
212 ret = -ENOENT; 201 ret = -ENOENT;
213 goto err4; 202 goto err_remove_domain;
214 } 203 }
215 } 204 }
216 205
217 dev_info(dev, "driving %d irqs\n", p->number_of_irqs); 206 dev_info(dev, "driving %d irqs\n", p->number_of_irqs);
218 207
219 return 0; 208 return 0;
220err4:
221 while (--k >= 0)
222 free_irq(p->irq[k].requested_irq, &p->irq[k]);
223 209
224err3: 210err_remove_domain:
225 irq_domain_remove(p->irq_domain); 211 irq_domain_remove(p->irq_domain);
226err2: 212err_runtime_pm_disable:
227 iounmap(p->iomem);
228err1:
229 pm_runtime_put(dev); 213 pm_runtime_put(dev);
230 pm_runtime_disable(dev); 214 pm_runtime_disable(dev);
231 kfree(p);
232err0:
233 return ret; 215 return ret;
234} 216}
235 217
236static int irqc_remove(struct platform_device *pdev) 218static int irqc_remove(struct platform_device *pdev)
237{ 219{
238 struct irqc_priv *p = platform_get_drvdata(pdev); 220 struct irqc_priv *p = platform_get_drvdata(pdev);
239 int k;
240
241 for (k = 0; k < p->number_of_irqs; k++)
242 free_irq(p->irq[k].requested_irq, &p->irq[k]);
243 221
244 irq_domain_remove(p->irq_domain); 222 irq_domain_remove(p->irq_domain);
245 iounmap(p->iomem);
246 pm_runtime_put(&pdev->dev); 223 pm_runtime_put(&pdev->dev);
247 pm_runtime_disable(&pdev->dev); 224 pm_runtime_disable(&pdev->dev);
248 kfree(p);
249 return 0; 225 return 0;
250} 226}
251 227