1

spmi: Use devm_spmi_controller_alloc()

Convert to the device-managed version of spmi_controller_alloc() and
simplify the excess error handling code.

Signed-off-by: Fei Shao <fshao@chromium.org>
Link: https://lore.kernel.org/r/20230824104101.4083400-3-fshao@chromium.org
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Link: https://lore.kernel.org/r/20231206231733.4031901-5-sboyd@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Fei Shao 2023-12-06 15:17:27 -08:00 committed by Greg Kroah-Hartman
parent b6e53731e0
commit ffdfbafdc4
3 changed files with 46 additions and 89 deletions

View File

@ -267,10 +267,10 @@ static int spmi_controller_probe(struct platform_device *pdev)
struct resource *iores; struct resource *iores;
int ret; int ret;
ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*spmi_controller)); ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*spmi_controller));
if (!ctrl) { if (IS_ERR(ctrl)) {
dev_err(&pdev->dev, "can not allocate spmi_controller data\n"); dev_err(&pdev->dev, "can not allocate spmi_controller data\n");
return -ENOMEM; return PTR_ERR(ctrl);
} }
spmi_controller = spmi_controller_get_drvdata(ctrl); spmi_controller = spmi_controller_get_drvdata(ctrl);
spmi_controller->controller = ctrl; spmi_controller->controller = ctrl;
@ -278,24 +278,21 @@ static int spmi_controller_probe(struct platform_device *pdev)
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!iores) { if (!iores) {
dev_err(&pdev->dev, "can not get resource!\n"); dev_err(&pdev->dev, "can not get resource!\n");
ret = -EINVAL; return -EINVAL;
goto err_put_controller;
} }
spmi_controller->base = devm_ioremap(&pdev->dev, iores->start, spmi_controller->base = devm_ioremap(&pdev->dev, iores->start,
resource_size(iores)); resource_size(iores));
if (!spmi_controller->base) { if (!spmi_controller->base) {
dev_err(&pdev->dev, "can not remap base addr!\n"); dev_err(&pdev->dev, "can not remap base addr!\n");
ret = -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
goto err_put_controller;
} }
ret = of_property_read_u32(pdev->dev.of_node, "hisilicon,spmi-channel", ret = of_property_read_u32(pdev->dev.of_node, "hisilicon,spmi-channel",
&spmi_controller->channel); &spmi_controller->channel);
if (ret) { if (ret) {
dev_err(&pdev->dev, "can not get channel\n"); dev_err(&pdev->dev, "can not get channel\n");
ret = -ENODEV; return -ENODEV;
goto err_put_controller;
} }
platform_set_drvdata(pdev, spmi_controller); platform_set_drvdata(pdev, spmi_controller);
@ -314,14 +311,10 @@ static int spmi_controller_probe(struct platform_device *pdev)
ret = spmi_controller_add(ctrl); ret = spmi_controller_add(ctrl);
if (ret) { if (ret) {
dev_err(&pdev->dev, "spmi_controller_add failed with error %d!\n", ret); dev_err(&pdev->dev, "spmi_controller_add failed with error %d!\n", ret);
goto err_put_controller; return ret;
} }
return 0; return 0;
err_put_controller:
spmi_controller_put(ctrl);
return ret;
} }
static void spmi_del_controller(struct platform_device *pdev) static void spmi_del_controller(struct platform_device *pdev)
@ -329,7 +322,6 @@ static void spmi_del_controller(struct platform_device *pdev)
struct spmi_controller *ctrl = platform_get_drvdata(pdev); struct spmi_controller *ctrl = platform_get_drvdata(pdev);
spmi_controller_remove(ctrl); spmi_controller_remove(ctrl);
spmi_controller_put(ctrl);
} }
static const struct of_device_id spmi_controller_match_table[] = { static const struct of_device_id spmi_controller_match_table[] = {

View File

@ -447,29 +447,24 @@ static int mtk_spmi_probe(struct platform_device *pdev)
int err, i; int err, i;
u32 chan_offset; u32 chan_offset;
ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*arb)); ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*arb));
if (!ctrl) if (IS_ERR(ctrl))
return -ENOMEM; return PTR_ERR(ctrl);
arb = spmi_controller_get_drvdata(ctrl); arb = spmi_controller_get_drvdata(ctrl);
arb->data = device_get_match_data(&pdev->dev); arb->data = device_get_match_data(&pdev->dev);
if (!arb->data) { if (!arb->data) {
err = -EINVAL;
dev_err(&pdev->dev, "Cannot get drv_data\n"); dev_err(&pdev->dev, "Cannot get drv_data\n");
goto err_put_ctrl; return -EINVAL;
} }
arb->base = devm_platform_ioremap_resource_byname(pdev, "pmif"); arb->base = devm_platform_ioremap_resource_byname(pdev, "pmif");
if (IS_ERR(arb->base)) { if (IS_ERR(arb->base))
err = PTR_ERR(arb->base); return PTR_ERR(arb->base);
goto err_put_ctrl;
}
arb->spmimst_base = devm_platform_ioremap_resource_byname(pdev, "spmimst"); arb->spmimst_base = devm_platform_ioremap_resource_byname(pdev, "spmimst");
if (IS_ERR(arb->spmimst_base)) { if (IS_ERR(arb->spmimst_base))
err = PTR_ERR(arb->spmimst_base); return PTR_ERR(arb->spmimst_base);
goto err_put_ctrl;
}
arb->nclks = ARRAY_SIZE(pmif_clock_names); arb->nclks = ARRAY_SIZE(pmif_clock_names);
for (i = 0; i < arb->nclks; i++) for (i = 0; i < arb->nclks; i++)
@ -478,7 +473,7 @@ static int mtk_spmi_probe(struct platform_device *pdev)
err = clk_bulk_get(&pdev->dev, arb->nclks, arb->clks); err = clk_bulk_get(&pdev->dev, arb->nclks, arb->clks);
if (err) { if (err) {
dev_err(&pdev->dev, "Failed to get clocks: %d\n", err); dev_err(&pdev->dev, "Failed to get clocks: %d\n", err);
goto err_put_ctrl; return err;
} }
err = clk_bulk_prepare_enable(arb->nclks, arb->clks); err = clk_bulk_prepare_enable(arb->nclks, arb->clks);
@ -512,8 +507,6 @@ err_domain_remove:
clk_bulk_disable_unprepare(arb->nclks, arb->clks); clk_bulk_disable_unprepare(arb->nclks, arb->clks);
err_put_clks: err_put_clks:
clk_bulk_put(arb->nclks, arb->clks); clk_bulk_put(arb->nclks, arb->clks);
err_put_ctrl:
spmi_controller_put(ctrl);
return err; return err;
} }
@ -525,7 +518,6 @@ static void mtk_spmi_remove(struct platform_device *pdev)
clk_bulk_disable_unprepare(arb->nclks, arb->clks); clk_bulk_disable_unprepare(arb->nclks, arb->clks);
clk_bulk_put(arb->nclks, arb->clks); clk_bulk_put(arb->nclks, arb->clks);
spmi_controller_remove(ctrl); spmi_controller_remove(ctrl);
spmi_controller_put(ctrl);
} }
static const struct of_device_id mtk_spmi_match_table[] = { static const struct of_device_id mtk_spmi_match_table[] = {

View File

@ -1443,9 +1443,9 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
u32 channel, ee, hw_ver; u32 channel, ee, hw_ver;
int err; int err;
ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*pmic_arb)); ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*pmic_arb));
if (!ctrl) if (IS_ERR(ctrl))
return -ENOMEM; return PTR_ERR(ctrl);
pmic_arb = spmi_controller_get_drvdata(ctrl); pmic_arb = spmi_controller_get_drvdata(ctrl);
pmic_arb->spmic = ctrl; pmic_arb->spmic = ctrl;
@ -1462,20 +1462,16 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
*/ */
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core");
core = devm_ioremap(&ctrl->dev, res->start, resource_size(res)); core = devm_ioremap(&ctrl->dev, res->start, resource_size(res));
if (IS_ERR(core)) { if (IS_ERR(core))
err = PTR_ERR(core); return PTR_ERR(core);
goto err_put_ctrl;
}
pmic_arb->core_size = resource_size(res); pmic_arb->core_size = resource_size(res);
pmic_arb->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID, pmic_arb->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID,
sizeof(*pmic_arb->ppid_to_apid), sizeof(*pmic_arb->ppid_to_apid),
GFP_KERNEL); GFP_KERNEL);
if (!pmic_arb->ppid_to_apid) { if (!pmic_arb->ppid_to_apid)
err = -ENOMEM; return -ENOMEM;
goto err_put_ctrl;
}
hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); hw_ver = readl_relaxed(core + PMIC_ARB_VERSION);
@ -1499,19 +1495,15 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
"obsrvr"); "obsrvr");
pmic_arb->rd_base = devm_ioremap(&ctrl->dev, res->start, pmic_arb->rd_base = devm_ioremap(&ctrl->dev, res->start,
resource_size(res)); resource_size(res));
if (IS_ERR(pmic_arb->rd_base)) { if (IS_ERR(pmic_arb->rd_base))
err = PTR_ERR(pmic_arb->rd_base); return PTR_ERR(pmic_arb->rd_base);
goto err_put_ctrl;
}
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
"chnls"); "chnls");
pmic_arb->wr_base = devm_ioremap(&ctrl->dev, res->start, pmic_arb->wr_base = devm_ioremap(&ctrl->dev, res->start,
resource_size(res)); resource_size(res));
if (IS_ERR(pmic_arb->wr_base)) { if (IS_ERR(pmic_arb->wr_base))
err = PTR_ERR(pmic_arb->wr_base); return PTR_ERR(pmic_arb->wr_base);
goto err_put_ctrl;
}
} }
pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS; pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS;
@ -1522,10 +1514,9 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
of_property_read_u32(pdev->dev.of_node, "qcom,bus-id", of_property_read_u32(pdev->dev.of_node, "qcom,bus-id",
&pmic_arb->bus_instance); &pmic_arb->bus_instance);
if (pmic_arb->bus_instance > 1) { if (pmic_arb->bus_instance > 1) {
err = -EINVAL;
dev_err(&pdev->dev, "invalid bus instance (%u) specified\n", dev_err(&pdev->dev, "invalid bus instance (%u) specified\n",
pmic_arb->bus_instance); pmic_arb->bus_instance);
goto err_put_ctrl; return -EINVAL;
} }
if (pmic_arb->bus_instance == 0) { if (pmic_arb->bus_instance == 0) {
@ -1543,10 +1534,9 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
} }
if (pmic_arb->base_apid + pmic_arb->apid_count > pmic_arb->max_periphs) { if (pmic_arb->base_apid + pmic_arb->apid_count > pmic_arb->max_periphs) {
err = -EINVAL;
dev_err(&pdev->dev, "Unsupported APID count %d detected\n", dev_err(&pdev->dev, "Unsupported APID count %d detected\n",
pmic_arb->base_apid + pmic_arb->apid_count); pmic_arb->base_apid + pmic_arb->apid_count);
goto err_put_ctrl; return -EINVAL;
} }
} else if (hw_ver >= PMIC_ARB_VERSION_V5_MIN) { } else if (hw_ver >= PMIC_ARB_VERSION_V5_MIN) {
pmic_arb->base_apid = 0; pmic_arb->base_apid = 0;
@ -1554,55 +1544,45 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
PMIC_ARB_FEATURES_PERIPH_MASK; PMIC_ARB_FEATURES_PERIPH_MASK;
if (pmic_arb->apid_count > pmic_arb->max_periphs) { if (pmic_arb->apid_count > pmic_arb->max_periphs) {
err = -EINVAL;
dev_err(&pdev->dev, "Unsupported APID count %d detected\n", dev_err(&pdev->dev, "Unsupported APID count %d detected\n",
pmic_arb->apid_count); pmic_arb->apid_count);
goto err_put_ctrl; return -EINVAL;
} }
} }
pmic_arb->apid_data = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, pmic_arb->apid_data = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs,
sizeof(*pmic_arb->apid_data), sizeof(*pmic_arb->apid_data),
GFP_KERNEL); GFP_KERNEL);
if (!pmic_arb->apid_data) { if (!pmic_arb->apid_data)
err = -ENOMEM; return -ENOMEM;
goto err_put_ctrl;
}
dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n", dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n",
pmic_arb->ver_ops->ver_str, hw_ver); pmic_arb->ver_ops->ver_str, hw_ver);
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr");
pmic_arb->intr = devm_ioremap_resource(&ctrl->dev, res); pmic_arb->intr = devm_ioremap_resource(&ctrl->dev, res);
if (IS_ERR(pmic_arb->intr)) { if (IS_ERR(pmic_arb->intr))
err = PTR_ERR(pmic_arb->intr); return PTR_ERR(pmic_arb->intr);
goto err_put_ctrl;
}
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cnfg"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cnfg");
pmic_arb->cnfg = devm_ioremap_resource(&ctrl->dev, res); pmic_arb->cnfg = devm_ioremap_resource(&ctrl->dev, res);
if (IS_ERR(pmic_arb->cnfg)) { if (IS_ERR(pmic_arb->cnfg))
err = PTR_ERR(pmic_arb->cnfg); return PTR_ERR(pmic_arb->cnfg);
goto err_put_ctrl;
}
pmic_arb->irq = platform_get_irq_byname(pdev, "periph_irq"); pmic_arb->irq = platform_get_irq_byname(pdev, "periph_irq");
if (pmic_arb->irq < 0) { if (pmic_arb->irq < 0)
err = pmic_arb->irq; return pmic_arb->irq;
goto err_put_ctrl;
}
err = of_property_read_u32(pdev->dev.of_node, "qcom,channel", &channel); err = of_property_read_u32(pdev->dev.of_node, "qcom,channel", &channel);
if (err) { if (err) {
dev_err(&pdev->dev, "channel unspecified.\n"); dev_err(&pdev->dev, "channel unspecified.\n");
goto err_put_ctrl; return err;
} }
if (channel > 5) { if (channel > 5) {
dev_err(&pdev->dev, "invalid channel (%u) specified.\n", dev_err(&pdev->dev, "invalid channel (%u) specified.\n",
channel); channel);
err = -EINVAL; return -EINVAL;
goto err_put_ctrl;
} }
pmic_arb->channel = channel; pmic_arb->channel = channel;
@ -1610,22 +1590,19 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
err = of_property_read_u32(pdev->dev.of_node, "qcom,ee", &ee); err = of_property_read_u32(pdev->dev.of_node, "qcom,ee", &ee);
if (err) { if (err) {
dev_err(&pdev->dev, "EE unspecified.\n"); dev_err(&pdev->dev, "EE unspecified.\n");
goto err_put_ctrl; return err;
} }
if (ee > 5) { if (ee > 5) {
dev_err(&pdev->dev, "invalid EE (%u) specified\n", ee); dev_err(&pdev->dev, "invalid EE (%u) specified\n", ee);
err = -EINVAL; return -EINVAL;
goto err_put_ctrl;
} }
pmic_arb->ee = ee; pmic_arb->ee = ee;
mapping_table = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, mapping_table = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs,
sizeof(*mapping_table), GFP_KERNEL); sizeof(*mapping_table), GFP_KERNEL);
if (!mapping_table) { if (!mapping_table)
err = -ENOMEM; return -ENOMEM;
goto err_put_ctrl;
}
pmic_arb->mapping_table = mapping_table; pmic_arb->mapping_table = mapping_table;
/* Initialize max_apid/min_apid to the opposite bounds, during /* Initialize max_apid/min_apid to the opposite bounds, during
@ -1645,7 +1622,7 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
if (err) { if (err) {
dev_err(&pdev->dev, "could not read APID->PPID mapping table, rc= %d\n", dev_err(&pdev->dev, "could not read APID->PPID mapping table, rc= %d\n",
err); err);
goto err_put_ctrl; return err;
} }
} }
@ -1654,8 +1631,7 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
&pmic_arb_irq_domain_ops, pmic_arb); &pmic_arb_irq_domain_ops, pmic_arb);
if (!pmic_arb->domain) { if (!pmic_arb->domain) {
dev_err(&pdev->dev, "unable to create irq_domain\n"); dev_err(&pdev->dev, "unable to create irq_domain\n");
err = -ENOMEM; return -ENOMEM;
goto err_put_ctrl;
} }
irq_set_chained_handler_and_data(pmic_arb->irq, pmic_arb_chained_irq, irq_set_chained_handler_and_data(pmic_arb->irq, pmic_arb_chained_irq,
@ -1669,8 +1645,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
err_domain_remove: err_domain_remove:
irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL); irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL);
irq_domain_remove(pmic_arb->domain); irq_domain_remove(pmic_arb->domain);
err_put_ctrl:
spmi_controller_put(ctrl);
return err; return err;
} }
@ -1681,7 +1655,6 @@ static void spmi_pmic_arb_remove(struct platform_device *pdev)
spmi_controller_remove(ctrl); spmi_controller_remove(ctrl);
irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL); irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL);
irq_domain_remove(pmic_arb->domain); irq_domain_remove(pmic_arb->domain);
spmi_controller_put(ctrl);
} }
static const struct of_device_id spmi_pmic_arb_match_table[] = { static const struct of_device_id spmi_pmic_arb_match_table[] = {