提交 cb5faba9 编写于 作者: V Viresh Kumar 提交者: Samuel Ortiz

mfd: stmpe: Use devm_*() routines

This patch frees stmpe driver from tension of freeing resources.
devm_* derivatives of multiple routines are used while allocating resources,
which would be freed automatically by kernel.
Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
Acked-by: NLee Jones <lee.jones@linaro.org>
Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
上级 0c418844
...@@ -1052,17 +1052,17 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum) ...@@ -1052,17 +1052,17 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
int ret; int ret;
if (!pdata) { if (!pdata) {
if (np) { if (!np)
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
stmpe_of_probe(pdata, np);
} else
return -EINVAL; return -EINVAL;
pdata = devm_kzalloc(ci->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
stmpe_of_probe(pdata, np);
} }
stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL); stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL);
if (!stmpe) if (!stmpe)
return -ENOMEM; return -ENOMEM;
...@@ -1084,11 +1084,12 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum) ...@@ -1084,11 +1084,12 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
ci->init(stmpe); ci->init(stmpe);
if (pdata->irq_over_gpio) { if (pdata->irq_over_gpio) {
ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe"); ret = devm_gpio_request_one(ci->dev, pdata->irq_gpio,
GPIOF_DIR_IN, "stmpe");
if (ret) { if (ret) {
dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
ret); ret);
goto out_free; return ret;
} }
stmpe->irq = gpio_to_irq(pdata->irq_gpio); stmpe->irq = gpio_to_irq(pdata->irq_gpio);
...@@ -1105,48 +1106,37 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum) ...@@ -1105,48 +1106,37 @@ int __devinit stmpe_probe(struct stmpe_client_info *ci, int partnum)
dev_err(stmpe->dev, dev_err(stmpe->dev,
"%s does not support no-irq mode!\n", "%s does not support no-irq mode!\n",
stmpe->variant->name); stmpe->variant->name);
ret = -ENODEV; return -ENODEV;
goto free_gpio;
} }
stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum];
} }
ret = stmpe_chip_init(stmpe); ret = stmpe_chip_init(stmpe);
if (ret) if (ret)
goto free_gpio; return ret;
if (stmpe->irq >= 0) { if (stmpe->irq >= 0) {
ret = stmpe_irq_init(stmpe, np); ret = stmpe_irq_init(stmpe, np);
if (ret) if (ret)
goto free_gpio; return ret;
ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq, ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL,
pdata->irq_trigger | IRQF_ONESHOT, stmpe_irq, pdata->irq_trigger | IRQF_ONESHOT,
"stmpe", stmpe); "stmpe", stmpe);
if (ret) { if (ret) {
dev_err(stmpe->dev, "failed to request IRQ: %d\n", dev_err(stmpe->dev, "failed to request IRQ: %d\n",
ret); ret);
goto free_gpio; return ret;
} }
} }
ret = stmpe_devices_init(stmpe); ret = stmpe_devices_init(stmpe);
if (ret) { if (!ret)
dev_err(stmpe->dev, "failed to add children\n"); return 0;
goto out_removedevs;
}
return 0;
out_removedevs: dev_err(stmpe->dev, "failed to add children\n");
mfd_remove_devices(stmpe->dev); mfd_remove_devices(stmpe->dev);
if (stmpe->irq >= 0)
free_irq(stmpe->irq, stmpe);
free_gpio:
if (pdata->irq_over_gpio)
gpio_free(pdata->irq_gpio);
out_free:
kfree(stmpe);
return ret; return ret;
} }
...@@ -1154,14 +1144,6 @@ int stmpe_remove(struct stmpe *stmpe) ...@@ -1154,14 +1144,6 @@ int stmpe_remove(struct stmpe *stmpe)
{ {
mfd_remove_devices(stmpe->dev); mfd_remove_devices(stmpe->dev);
if (stmpe->irq >= 0)
free_irq(stmpe->irq, stmpe);
if (stmpe->pdata->irq_over_gpio)
gpio_free(stmpe->pdata->irq_gpio);
kfree(stmpe);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册