@@ -368,7 +368,7 @@ static const struct mtk_eint_xt mtk_eint_xt = {
int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
- unsigned int i, j, count_reg_names;
+ int ret, i, j, count_reg_names;
if (!IS_ENABLED(CONFIG_EINT_MTK))
return 0;
@@ -377,7 +377,7 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
return -ENODEV;
count_reg_names = of_property_count_strings(np, "reg-names");
- if (count_reg_names < 0 || count_reg_names < hw->soc->nbase_names)
+ if (count_reg_names < hw->soc->nbase_names)
return -EINVAL;
hw->eint = devm_kmalloc(hw->dev, sizeof(*hw->eint), GFP_KERNEL);
@@ -385,33 +385,53 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
return -ENOMEM;
hw->eint->nbase = count_reg_names - hw->soc->nbase_names;
- hw->eint->base = devm_kmalloc_array(&pdev->dev, hw->eint->nbase,
+ hw->eint->base = devm_kmalloc_array(hw->dev, hw->eint->nbase,
sizeof(*hw->eint->base), GFP_KERNEL);
- if (!hw->eint->base)
- return -ENOMEM;
+ if (!hw->eint->base) {
+ ret = -ENOMEM;
+ goto err_free_eint;
+ }
for (i = hw->soc->nbase_names, j = 0; i < count_reg_names; i++, j++) {
hw->eint->base[j] = of_iomap(np, i);
- if (IS_ERR(hw->eint->base[j]))
- return PTR_ERR(hw->eint->base[j]);
+ if (IS_ERR(hw->eint->base[j])) {
+ ret = PTR_ERR(hw->eint->base[j]);
+ goto err_free_eint;
+ }
}
- if (!of_property_read_bool(np, "interrupt-controller"))
- return -ENODEV;
+ if (!of_property_read_bool(np, "interrupt-controller")) {
+ ret = -ENODEV;
+ goto err_free_eint;
+ }
hw->eint->irq = irq_of_parse_and_map(np, 0);
- if (!hw->eint->irq)
- return -EINVAL;
-
- if (hw->soc->eint_pin)
- hw->eint->pins = hw->soc->eint_pin;
+ if (!hw->eint->irq) {
+ ret = -EINVAL;
+ goto err_free_eint;
+ }
hw->eint->dev = &pdev->dev;
hw->eint->hw = hw->soc->eint_hw;
hw->eint->pctl = hw;
hw->eint->gpio_xlate = &mtk_eint_xt;
- return mtk_eint_do_init(hw->eint);
+ ret = mtk_eint_do_init(hw->eint);
+ if (ret)
+ goto err_free_eint;
+
+ return 0;
+
+err_free_eint:
+ for (j = 0; j < hw->eint->nbase; j++) {
+ if (hw->eint->base[j])
+ iounmap(hw->eint->base[j]);
+ }
+ if (hw->eint->base)
+ devm_kfree(hw->dev, hw->eint->base);
+ devm_kfree(hw->dev, hw->eint);
+ hw->eint = NULL;
+ return ret;
}
EXPORT_SYMBOL_GPL(mtk_build_eint);