linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] spmi: Add and use managed resource helpers
@ 2023-08-24 10:40 Fei Shao
  2023-08-24 10:40 ` [PATCH 1/5] spmi: Introduce device-managed functions Fei Shao
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Fei Shao @ 2023-08-24 10:40 UTC (permalink / raw)
  To: Stephen Boyd, Chen-Yu Tsai
  Cc: Mauro Carvalho Chehab, linux-kernel, linux-mediatek,
	Matthias Brugger, linux-arm-kernel, AngeloGioacchino Del Regno

Hi,

This series adds and converts to the devm_* helpers in the SPMI driver,
based on the suggestion in [1].

While at it, I have some patches fixing other minor issues as well, like
reordering the remove sequence in spmi-mtk-pmif and using proper error
return code etc.

This patch is based on next-20230824 and [2] which is not yet applied,
in order to avoid potential conflicts.

[1]: https://lore.kernel.org/all/20230821033532.GA21555@google.com/
[2]: https://lore.kernel.org/all/20230717173934.1.If004a6e055a189c7f2d0724fa814422c26789839@changeid/


Fei Shao (5):
  spmi: Introduce device-managed functions
  spmi: Use devm_spmi_controller_alloc()
  spmi: mtk-pmif: Reorder driver remove sequence
  spmi: hisi-spmi-controller: Use devm_spmi_controller_add()
  spmi: Return meaningful errors in spmi_controller_alloc()

 drivers/spmi/Makefile               |  2 +-
 drivers/spmi/devres.c               | 61 ++++++++++++++++++++
 drivers/spmi/hisi-spmi-controller.c | 32 +++--------
 drivers/spmi/spmi-mtk-pmif.c        | 28 ++++------
 drivers/spmi/spmi-pmic-arb.c        | 87 ++++++++++-------------------
 drivers/spmi/spmi.c                 |  6 +-
 include/linux/spmi.h                |  3 +
 7 files changed, 116 insertions(+), 103 deletions(-)
 create mode 100644 drivers/spmi/devres.c

-- 
2.42.0.rc1.204.g551eb34607-goog



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/5] spmi: Introduce device-managed functions
  2023-08-24 10:40 [PATCH 0/5] spmi: Add and use managed resource helpers Fei Shao
@ 2023-08-24 10:40 ` Fei Shao
  2023-09-13  9:11   ` AngeloGioacchino Del Regno
  2023-08-24 10:40 ` [PATCH 2/5] spmi: Use devm_spmi_controller_alloc() Fei Shao
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Fei Shao @ 2023-08-24 10:40 UTC (permalink / raw)
  To: Stephen Boyd, Chen-Yu Tsai; +Cc: linux-mediatek, linux-kernel

Utilize the managed resource (devres) framework and add the following
devm_* helpers for the SPMI driver:

- devm_spmi_controller_alloc()
- devm_spmi_controller_add()

Signed-off-by: Fei Shao <fshao@chromium.org>
---

 drivers/spmi/Makefile |  2 +-
 drivers/spmi/devres.c | 61 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/spmi.h  |  3 +++
 3 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 drivers/spmi/devres.c

diff --git a/drivers/spmi/Makefile b/drivers/spmi/Makefile
index 9d974424c8c1..02d917f4df34 100644
--- a/drivers/spmi/Makefile
+++ b/drivers/spmi/Makefile
@@ -2,7 +2,7 @@
 #
 # Makefile for kernel SPMI framework.
 #
-obj-$(CONFIG_SPMI)	+= spmi.o
+obj-$(CONFIG_SPMI)	+= spmi.o devres.o
 
 obj-$(CONFIG_SPMI_HISI3670)	+= hisi-spmi-controller.o
 obj-$(CONFIG_SPMI_MSM_PMIC_ARB)	+= spmi-pmic-arb.o
diff --git a/drivers/spmi/devres.c b/drivers/spmi/devres.c
new file mode 100644
index 000000000000..f18cbbe28812
--- /dev/null
+++ b/drivers/spmi/devres.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2023 Google LLC.
+ */
+
+#include <linux/device.h>
+#include <linux/spmi.h>
+
+static void devm_spmi_controller_release(struct device *parent, void *res)
+{
+	spmi_controller_put(*(struct spmi_controller **)res);
+}
+
+struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size)
+{
+	struct spmi_controller **ptr, *ctrl;
+
+	ptr = devres_alloc(devm_spmi_controller_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	ctrl = spmi_controller_alloc(parent, size);
+	if (!ctrl) {
+		devres_free(ptr);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	*ptr = ctrl;
+	devres_add(parent, ptr);
+
+	return ctrl;
+}
+EXPORT_SYMBOL_GPL(devm_spmi_controller_alloc);
+
+static void devm_spmi_controller_remove(struct device *parent, void *res)
+{
+	spmi_controller_remove(*(struct spmi_controller **)res);
+}
+
+int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl)
+{
+	struct spmi_controller **ptr;
+	int ret;
+
+	ptr = devres_alloc(devm_spmi_controller_remove, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return -ENOMEM;
+
+	ret = spmi_controller_add(ctrl);
+	if (ret) {
+		devres_free(ptr);
+		return ret;
+	}
+
+	*ptr = ctrl;
+	devres_add(parent, ptr);
+
+	return 0;
+
+}
+EXPORT_SYMBOL_GPL(devm_spmi_controller_add);
diff --git a/include/linux/spmi.h b/include/linux/spmi.h
index eac1956a8727..14597708fdbc 100644
--- a/include/linux/spmi.h
+++ b/include/linux/spmi.h
@@ -120,6 +120,9 @@ static inline void spmi_controller_put(struct spmi_controller *ctrl)
 int spmi_controller_add(struct spmi_controller *ctrl);
 void spmi_controller_remove(struct spmi_controller *ctrl);
 
+struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size);
+int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl);
+
 /**
  * struct spmi_driver - SPMI slave device driver
  * @driver:	SPMI device drivers should initialize name and owner field of
-- 
2.42.0.rc1.204.g551eb34607-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/5] spmi: Use devm_spmi_controller_alloc()
  2023-08-24 10:40 [PATCH 0/5] spmi: Add and use managed resource helpers Fei Shao
  2023-08-24 10:40 ` [PATCH 1/5] spmi: Introduce device-managed functions Fei Shao
@ 2023-08-24 10:40 ` Fei Shao
  2023-09-13  9:11   ` AngeloGioacchino Del Regno
  2023-08-24 10:40 ` [PATCH 3/5] spmi: mtk-pmif: Reorder driver remove sequence Fei Shao
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Fei Shao @ 2023-08-24 10:40 UTC (permalink / raw)
  To: Stephen Boyd, Chen-Yu Tsai
  Cc: Mauro Carvalho Chehab, linux-kernel, linux-mediatek,
	Matthias Brugger, linux-arm-kernel, AngeloGioacchino Del Regno

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>
---

 drivers/spmi/hisi-spmi-controller.c | 22 +++-----
 drivers/spmi/spmi-mtk-pmif.c        | 26 +++------
 drivers/spmi/spmi-pmic-arb.c        | 87 ++++++++++-------------------
 3 files changed, 46 insertions(+), 89 deletions(-)

diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c
index 9cbd473487cb..a5525902656a 100644
--- a/drivers/spmi/hisi-spmi-controller.c
+++ b/drivers/spmi/hisi-spmi-controller.c
@@ -267,10 +267,10 @@ static int spmi_controller_probe(struct platform_device *pdev)
 	struct resource *iores;
 	int ret;
 
-	ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*spmi_controller));
-	if (!ctrl) {
+	ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*spmi_controller));
+	if (IS_ERR(ctrl)) {
 		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->controller = ctrl;
@@ -278,24 +278,21 @@ static int spmi_controller_probe(struct platform_device *pdev)
 	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!iores) {
 		dev_err(&pdev->dev, "can not get resource!\n");
-		ret = -EINVAL;
-		goto err_put_controller;
+		return -EINVAL;
 	}
 
 	spmi_controller->base = devm_ioremap(&pdev->dev, iores->start,
 					     resource_size(iores));
 	if (!spmi_controller->base) {
 		dev_err(&pdev->dev, "can not remap base addr!\n");
-		ret = -EADDRNOTAVAIL;
-		goto err_put_controller;
+		return -EADDRNOTAVAIL;
 	}
 
 	ret = of_property_read_u32(pdev->dev.of_node, "hisilicon,spmi-channel",
 				   &spmi_controller->channel);
 	if (ret) {
 		dev_err(&pdev->dev, "can not get channel\n");
-		ret = -ENODEV;
-		goto err_put_controller;
+		return -ENODEV;
 	}
 
 	platform_set_drvdata(pdev, spmi_controller);
@@ -314,14 +311,10 @@ static int spmi_controller_probe(struct platform_device *pdev)
 	ret = spmi_controller_add(ctrl);
 	if (ret) {
 		dev_err(&pdev->dev, "spmi_controller_add failed with error %d!\n", ret);
-		goto err_put_controller;
+		return ret;
 	}
 
 	return 0;
-
-err_put_controller:
-	spmi_controller_put(ctrl);
-	return ret;
 }
 
 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);
 
 	spmi_controller_remove(ctrl);
-	spmi_controller_put(ctrl);
 }
 
 static const struct of_device_id spmi_controller_match_table[] = {
diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c
index 74b73f9bc222..eb909a6e3b9e 100644
--- a/drivers/spmi/spmi-mtk-pmif.c
+++ b/drivers/spmi/spmi-mtk-pmif.c
@@ -437,29 +437,24 @@ static int mtk_spmi_probe(struct platform_device *pdev)
 	int err, i;
 	u32 chan_offset;
 
-	ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*arb));
-	if (!ctrl)
-		return -ENOMEM;
+	ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*arb));
+	if (IS_ERR(ctrl))
+		return PTR_ERR(ctrl);
 
 	arb = spmi_controller_get_drvdata(ctrl);
 	arb->data = device_get_match_data(&pdev->dev);
 	if (!arb->data) {
-		err = -EINVAL;
 		dev_err(&pdev->dev, "Cannot get drv_data\n");
-		goto err_put_ctrl;
+		return -EINVAL;
 	}
 
 	arb->base = devm_platform_ioremap_resource_byname(pdev, "pmif");
-	if (IS_ERR(arb->base)) {
-		err = PTR_ERR(arb->base);
-		goto err_put_ctrl;
-	}
+	if (IS_ERR(arb->base))
+		return PTR_ERR(arb->base);
 
 	arb->spmimst_base = devm_platform_ioremap_resource_byname(pdev, "spmimst");
-	if (IS_ERR(arb->spmimst_base)) {
-		err = PTR_ERR(arb->spmimst_base);
-		goto err_put_ctrl;
-	}
+	if (IS_ERR(arb->spmimst_base))
+		return PTR_ERR(arb->spmimst_base);
 
 	arb->nclks = ARRAY_SIZE(pmif_clock_names);
 	for (i = 0; i < arb->nclks; i++)
@@ -468,7 +463,7 @@ static int mtk_spmi_probe(struct platform_device *pdev)
 	err = clk_bulk_get(&pdev->dev, arb->nclks, arb->clks);
 	if (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);
@@ -500,8 +495,6 @@ static int mtk_spmi_probe(struct platform_device *pdev)
 	clk_bulk_disable_unprepare(arb->nclks, arb->clks);
 err_put_clks:
 	clk_bulk_put(arb->nclks, arb->clks);
-err_put_ctrl:
-	spmi_controller_put(ctrl);
 	return err;
 }
 
@@ -513,7 +506,6 @@ static void mtk_spmi_remove(struct platform_device *pdev)
 	clk_bulk_disable_unprepare(arb->nclks, arb->clks);
 	clk_bulk_put(arb->nclks, arb->clks);
 	spmi_controller_remove(ctrl);
-	spmi_controller_put(ctrl);
 }
 
 static const struct of_device_id mtk_spmi_match_table[] = {
diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c
index dcb675d980d4..9ed1180fe31f 100644
--- a/drivers/spmi/spmi-pmic-arb.c
+++ b/drivers/spmi/spmi-pmic-arb.c
@@ -1443,9 +1443,9 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
 	u32 channel, ee, hw_ver;
 	int err;
 
-	ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*pmic_arb));
-	if (!ctrl)
-		return -ENOMEM;
+	ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*pmic_arb));
+	if (IS_ERR(ctrl))
+		return PTR_ERR(ctrl);
 
 	pmic_arb = spmi_controller_get_drvdata(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");
 	core = devm_ioremap(&ctrl->dev, res->start, resource_size(res));
-	if (IS_ERR(core)) {
-		err = PTR_ERR(core);
-		goto err_put_ctrl;
-	}
+	if (IS_ERR(core))
+		return PTR_ERR(core);
 
 	pmic_arb->core_size = resource_size(res);
 
 	pmic_arb->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID,
 					      sizeof(*pmic_arb->ppid_to_apid),
 					      GFP_KERNEL);
-	if (!pmic_arb->ppid_to_apid) {
-		err = -ENOMEM;
-		goto err_put_ctrl;
-	}
+	if (!pmic_arb->ppid_to_apid)
+		return -ENOMEM;
 
 	hw_ver = readl_relaxed(core + PMIC_ARB_VERSION);
 
@@ -1499,19 +1495,15 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
 						   "obsrvr");
 		pmic_arb->rd_base = devm_ioremap(&ctrl->dev, res->start,
 						 resource_size(res));
-		if (IS_ERR(pmic_arb->rd_base)) {
-			err = PTR_ERR(pmic_arb->rd_base);
-			goto err_put_ctrl;
-		}
+		if (IS_ERR(pmic_arb->rd_base))
+			return PTR_ERR(pmic_arb->rd_base);
 
 		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
 						   "chnls");
 		pmic_arb->wr_base = devm_ioremap(&ctrl->dev, res->start,
 						 resource_size(res));
-		if (IS_ERR(pmic_arb->wr_base)) {
-			err = PTR_ERR(pmic_arb->wr_base);
-			goto err_put_ctrl;
-		}
+		if (IS_ERR(pmic_arb->wr_base))
+			return PTR_ERR(pmic_arb->wr_base);
 	}
 
 	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",
 					&pmic_arb->bus_instance);
 		if (pmic_arb->bus_instance > 1) {
-			err = -EINVAL;
 			dev_err(&pdev->dev, "invalid bus instance (%u) specified\n",
 				pmic_arb->bus_instance);
-			goto err_put_ctrl;
+			return -EINVAL;
 		}
 
 		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) {
-			err = -EINVAL;
 			dev_err(&pdev->dev, "Unsupported APID count %d detected\n",
 				pmic_arb->base_apid + pmic_arb->apid_count);
-			goto err_put_ctrl;
+			return -EINVAL;
 		}
 	} else if (hw_ver >= PMIC_ARB_VERSION_V5_MIN) {
 		pmic_arb->base_apid = 0;
@@ -1554,55 +1544,45 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev)
 					PMIC_ARB_FEATURES_PERIPH_MASK;
 
 		if (pmic_arb->apid_count > pmic_arb->max_periphs) {
-			err = -EINVAL;
 			dev_err(&pdev->dev, "Unsupported APID count %d detected\n",
 				pmic_arb->apid_count);
-			goto err_put_ctrl;
+			return -EINVAL;
 		}
 	}
 
 	pmic_arb->apid_data = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs,
 					   sizeof(*pmic_arb->apid_data),
 					   GFP_KERNEL);
-	if (!pmic_arb->apid_data) {
-		err = -ENOMEM;
-		goto err_put_ctrl;
-	}
+	if (!pmic_arb->apid_data)
+		return -ENOMEM;
 
 	dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n",
 		 pmic_arb->ver_ops->ver_str, hw_ver);
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr");
 	pmic_arb->intr = devm_ioremap_resource(&ctrl->dev, res);
-	if (IS_ERR(pmic_arb->intr)) {
-		err = PTR_ERR(pmic_arb->intr);
-		goto err_put_ctrl;
-	}
+	if (IS_ERR(pmic_arb->intr))
+		return PTR_ERR(pmic_arb->intr);
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cnfg");
 	pmic_arb->cnfg = devm_ioremap_resource(&ctrl->dev, res);
-	if (IS_ERR(pmic_arb->cnfg)) {
-		err = PTR_ERR(pmic_arb->cnfg);
-		goto err_put_ctrl;
-	}
+	if (IS_ERR(pmic_arb->cnfg))
+		return PTR_ERR(pmic_arb->cnfg);
 
 	pmic_arb->irq = platform_get_irq_byname(pdev, "periph_irq");
-	if (pmic_arb->irq < 0) {
-		err = pmic_arb->irq;
-		goto err_put_ctrl;
-	}
+	if (pmic_arb->irq < 0)
+		return pmic_arb->irq;
 
 	err = of_property_read_u32(pdev->dev.of_node, "qcom,channel", &channel);
 	if (err) {
 		dev_err(&pdev->dev, "channel unspecified.\n");
-		goto err_put_ctrl;
+		return err;
 	}
 
 	if (channel > 5) {
 		dev_err(&pdev->dev, "invalid channel (%u) specified.\n",
 			channel);
-		err = -EINVAL;
-		goto err_put_ctrl;
+		return -EINVAL;
 	}
 
 	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);
 	if (err) {
 		dev_err(&pdev->dev, "EE unspecified.\n");
-		goto err_put_ctrl;
+		return err;
 	}
 
 	if (ee > 5) {
 		dev_err(&pdev->dev, "invalid EE (%u) specified\n", ee);
-		err = -EINVAL;
-		goto err_put_ctrl;
+		return -EINVAL;
 	}
 
 	pmic_arb->ee = ee;
 	mapping_table = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs,
 					sizeof(*mapping_table), GFP_KERNEL);
-	if (!mapping_table) {
-		err = -ENOMEM;
-		goto err_put_ctrl;
-	}
+	if (!mapping_table)
+		return -ENOMEM;
 
 	pmic_arb->mapping_table = mapping_table;
 	/* 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) {
 			dev_err(&pdev->dev, "could not read APID->PPID mapping table, rc= %d\n",
 				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);
 	if (!pmic_arb->domain) {
 		dev_err(&pdev->dev, "unable to create irq_domain\n");
-		err = -ENOMEM;
-		goto err_put_ctrl;
+		return -ENOMEM;
 	}
 
 	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:
 	irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL);
 	irq_domain_remove(pmic_arb->domain);
-err_put_ctrl:
-	spmi_controller_put(ctrl);
 	return err;
 }
 
@@ -1681,7 +1655,6 @@ static void spmi_pmic_arb_remove(struct platform_device *pdev)
 	spmi_controller_remove(ctrl);
 	irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL);
 	irq_domain_remove(pmic_arb->domain);
-	spmi_controller_put(ctrl);
 }
 
 static const struct of_device_id spmi_pmic_arb_match_table[] = {
-- 
2.42.0.rc1.204.g551eb34607-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/5] spmi: mtk-pmif: Reorder driver remove sequence
  2023-08-24 10:40 [PATCH 0/5] spmi: Add and use managed resource helpers Fei Shao
  2023-08-24 10:40 ` [PATCH 1/5] spmi: Introduce device-managed functions Fei Shao
  2023-08-24 10:40 ` [PATCH 2/5] spmi: Use devm_spmi_controller_alloc() Fei Shao
@ 2023-08-24 10:40 ` Fei Shao
  2023-09-13  9:11   ` AngeloGioacchino Del Regno
  2023-08-24 10:40 ` [PATCH 4/5] spmi: hisi-spmi-controller: Use devm_spmi_controller_add() Fei Shao
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Fei Shao @ 2023-08-24 10:40 UTC (permalink / raw)
  To: Stephen Boyd, Chen-Yu Tsai
  Cc: linux-kernel, linux-mediatek, Matthias Brugger, linux-arm-kernel,
	AngeloGioacchino Del Regno

This driver enables clocks and then adds SPMI controller in probing, so
we expect the reversed sequence in removal.
Fix the order in the remove callback.

Signed-off-by: Fei Shao <fshao@chromium.org>
---

 drivers/spmi/spmi-mtk-pmif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c
index eb909a6e3b9e..2127bbd2f856 100644
--- a/drivers/spmi/spmi-mtk-pmif.c
+++ b/drivers/spmi/spmi-mtk-pmif.c
@@ -503,9 +503,9 @@ static void mtk_spmi_remove(struct platform_device *pdev)
 	struct spmi_controller *ctrl = platform_get_drvdata(pdev);
 	struct pmif *arb = spmi_controller_get_drvdata(ctrl);
 
+	spmi_controller_remove(ctrl);
 	clk_bulk_disable_unprepare(arb->nclks, arb->clks);
 	clk_bulk_put(arb->nclks, arb->clks);
-	spmi_controller_remove(ctrl);
 }
 
 static const struct of_device_id mtk_spmi_match_table[] = {
-- 
2.42.0.rc1.204.g551eb34607-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/5] spmi: hisi-spmi-controller: Use devm_spmi_controller_add()
  2023-08-24 10:40 [PATCH 0/5] spmi: Add and use managed resource helpers Fei Shao
                   ` (2 preceding siblings ...)
  2023-08-24 10:40 ` [PATCH 3/5] spmi: mtk-pmif: Reorder driver remove sequence Fei Shao
@ 2023-08-24 10:40 ` Fei Shao
  2023-08-24 10:40 ` [PATCH 5/5] spmi: Return meaningful errors in spmi_controller_alloc() Fei Shao
  2023-10-24  2:02 ` [PATCH 0/5] spmi: Add and use managed resource helpers Stephen Boyd
  5 siblings, 0 replies; 10+ messages in thread
From: Fei Shao @ 2023-08-24 10:40 UTC (permalink / raw)
  To: Stephen Boyd, Chen-Yu Tsai
  Cc: Mauro Carvalho Chehab, linux-mediatek, linux-kernel

Convert to the device-managed version of spmi_controller_add() and
delete the unnecessary driver remove callback.

Signed-off-by: Fei Shao <fshao@chromium.org>
---
Note that I skipped the conversions in spmi-mtk-pmif.c and
spmi-pmic-arb.c because the driver remove sequence would have been
changed, as using the devm version will postpone
spmi_controller_remove() to where after remove callback is executed.
So it turns out only hisi-spmi-controller.c is updated.

 drivers/spmi/hisi-spmi-controller.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c
index a5525902656a..674a350cc676 100644
--- a/drivers/spmi/hisi-spmi-controller.c
+++ b/drivers/spmi/hisi-spmi-controller.c
@@ -308,7 +308,7 @@ static int spmi_controller_probe(struct platform_device *pdev)
 	ctrl->read_cmd = spmi_read_cmd;
 	ctrl->write_cmd = spmi_write_cmd;
 
-	ret = spmi_controller_add(ctrl);
+	ret = devm_spmi_controller_add(&pdev->dev, ctrl);
 	if (ret) {
 		dev_err(&pdev->dev, "spmi_controller_add failed with error %d!\n", ret);
 		return ret;
@@ -317,13 +317,6 @@ static int spmi_controller_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void spmi_del_controller(struct platform_device *pdev)
-{
-	struct spmi_controller *ctrl = platform_get_drvdata(pdev);
-
-	spmi_controller_remove(ctrl);
-}
-
 static const struct of_device_id spmi_controller_match_table[] = {
 	{
 		.compatible = "hisilicon,kirin970-spmi-controller",
@@ -334,7 +327,6 @@ MODULE_DEVICE_TABLE(of, spmi_controller_match_table);
 
 static struct platform_driver spmi_controller_driver = {
 	.probe		= spmi_controller_probe,
-	.remove_new	= spmi_del_controller,
 	.driver		= {
 		.name	= "hisi_spmi_controller",
 		.of_match_table = spmi_controller_match_table,
-- 
2.42.0.rc1.204.g551eb34607-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/5] spmi: Return meaningful errors in spmi_controller_alloc()
  2023-08-24 10:40 [PATCH 0/5] spmi: Add and use managed resource helpers Fei Shao
                   ` (3 preceding siblings ...)
  2023-08-24 10:40 ` [PATCH 4/5] spmi: hisi-spmi-controller: Use devm_spmi_controller_add() Fei Shao
@ 2023-08-24 10:40 ` Fei Shao
  2023-10-24  2:02 ` [PATCH 0/5] spmi: Add and use managed resource helpers Stephen Boyd
  5 siblings, 0 replies; 10+ messages in thread
From: Fei Shao @ 2023-08-24 10:40 UTC (permalink / raw)
  To: Stephen Boyd, Chen-Yu Tsai; +Cc: linux-mediatek, linux-kernel

spmi_controller_alloc() currently returns NULL to all types of errors,
which can be improved.

Use appropriate error code in returns and pass the errors from used
functions where possible.

Signed-off-by: Fei Shao <fshao@chromium.org>
---

 drivers/spmi/devres.c | 4 ++--
 drivers/spmi/spmi.c   | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/spmi/devres.c b/drivers/spmi/devres.c
index f18cbbe28812..c19f09243bc3 100644
--- a/drivers/spmi/devres.c
+++ b/drivers/spmi/devres.c
@@ -20,9 +20,9 @@ struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t
 		return ERR_PTR(-ENOMEM);
 
 	ctrl = spmi_controller_alloc(parent, size);
-	if (!ctrl) {
+	if (IS_ERR(ctrl)) {
 		devres_free(ptr);
-		return ERR_PTR(-ENOMEM);
+		return ctrl;
 	}
 
 	*ptr = ctrl;
diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c
index 7313d4c18a04..5f11ced3f8b9 100644
--- a/drivers/spmi/spmi.c
+++ b/drivers/spmi/spmi.c
@@ -445,11 +445,11 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent,
 	int id;
 
 	if (WARN_ON(!parent))
-		return NULL;
+		return ERR_PTR(-EINVAL);
 
 	ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL);
 	if (!ctrl)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	device_initialize(&ctrl->dev);
 	ctrl->dev.type = &spmi_ctrl_type;
@@ -463,7 +463,7 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent,
 		dev_err(parent,
 			"unable to allocate SPMI controller identifier.\n");
 		spmi_controller_put(ctrl);
-		return NULL;
+		return ERR_PTR(id);
 	}
 
 	ctrl->nr = id;
-- 
2.42.0.rc1.204.g551eb34607-goog



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/5] spmi: mtk-pmif: Reorder driver remove sequence
  2023-08-24 10:40 ` [PATCH 3/5] spmi: mtk-pmif: Reorder driver remove sequence Fei Shao
@ 2023-09-13  9:11   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-09-13  9:11 UTC (permalink / raw)
  To: Fei Shao, Stephen Boyd, Chen-Yu Tsai
  Cc: linux-kernel, linux-mediatek, Matthias Brugger, linux-arm-kernel

Il 24/08/23 12:40, Fei Shao ha scritto:
> This driver enables clocks and then adds SPMI controller in probing, so
> we expect the reversed sequence in removal.
> Fix the order in the remove callback.
> 
> Signed-off-by: Fei Shao <fshao@chromium.org>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/5] spmi: Use devm_spmi_controller_alloc()
  2023-08-24 10:40 ` [PATCH 2/5] spmi: Use devm_spmi_controller_alloc() Fei Shao
@ 2023-09-13  9:11   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-09-13  9:11 UTC (permalink / raw)
  To: Fei Shao, Stephen Boyd, Chen-Yu Tsai
  Cc: Mauro Carvalho Chehab, linux-kernel, linux-mediatek,
	Matthias Brugger, linux-arm-kernel

Il 24/08/23 12:40, Fei Shao ha scritto:
> 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>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/5] spmi: Introduce device-managed functions
  2023-08-24 10:40 ` [PATCH 1/5] spmi: Introduce device-managed functions Fei Shao
@ 2023-09-13  9:11   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 10+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-09-13  9:11 UTC (permalink / raw)
  To: Fei Shao, Stephen Boyd, Chen-Yu Tsai; +Cc: linux-mediatek, linux-kernel

Il 24/08/23 12:40, Fei Shao ha scritto:
> Utilize the managed resource (devres) framework and add the following
> devm_* helpers for the SPMI driver:
> 
> - devm_spmi_controller_alloc()
> - devm_spmi_controller_add()
> 
> Signed-off-by: Fei Shao <fshao@chromium.org>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/5] spmi: Add and use managed resource helpers
  2023-08-24 10:40 [PATCH 0/5] spmi: Add and use managed resource helpers Fei Shao
                   ` (4 preceding siblings ...)
  2023-08-24 10:40 ` [PATCH 5/5] spmi: Return meaningful errors in spmi_controller_alloc() Fei Shao
@ 2023-10-24  2:02 ` Stephen Boyd
  5 siblings, 0 replies; 10+ messages in thread
From: Stephen Boyd @ 2023-10-24  2:02 UTC (permalink / raw)
  To: Chen-Yu Tsai, Fei Shao
  Cc: Mauro Carvalho Chehab, linux-kernel, linux-mediatek,
	Matthias Brugger, linux-arm-kernel, AngeloGioacchino Del Regno

Quoting Fei Shao (2023-08-24 03:40:07)
> Hi,
> 
> This series adds and converts to the devm_* helpers in the SPMI driver,
> based on the suggestion in [1].
> 
> While at it, I have some patches fixing other minor issues as well, like
> reordering the remove sequence in spmi-mtk-pmif and using proper error
> return code etc.
> 
> This patch is based on next-20230824 and [2] which is not yet applied,
> in order to avoid potential conflicts.
> 
> [1]: https://lore.kernel.org/all/20230821033532.GA21555@google.com/
> [2]: https://lore.kernel.org/all/20230717173934.1.If004a6e055a189c7f2d0724fa814422c26789839@changeid/
> 
> 
> Fei Shao (5):
>   spmi: Introduce device-managed functions
>   spmi: Use devm_spmi_controller_alloc()
>   spmi: mtk-pmif: Reorder driver remove sequence
>   spmi: hisi-spmi-controller: Use devm_spmi_controller_add()
>   spmi: Return meaningful errors in spmi_controller_alloc()
> 
>  drivers/spmi/Makefile               |  2 +-
>  drivers/spmi/devres.c               | 61 ++++++++++++++++++++
>  drivers/spmi/hisi-spmi-controller.c | 32 +++--------

Applied the series to spmi-next.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-10-24  2:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-24 10:40 [PATCH 0/5] spmi: Add and use managed resource helpers Fei Shao
2023-08-24 10:40 ` [PATCH 1/5] spmi: Introduce device-managed functions Fei Shao
2023-09-13  9:11   ` AngeloGioacchino Del Regno
2023-08-24 10:40 ` [PATCH 2/5] spmi: Use devm_spmi_controller_alloc() Fei Shao
2023-09-13  9:11   ` AngeloGioacchino Del Regno
2023-08-24 10:40 ` [PATCH 3/5] spmi: mtk-pmif: Reorder driver remove sequence Fei Shao
2023-09-13  9:11   ` AngeloGioacchino Del Regno
2023-08-24 10:40 ` [PATCH 4/5] spmi: hisi-spmi-controller: Use devm_spmi_controller_add() Fei Shao
2023-08-24 10:40 ` [PATCH 5/5] spmi: Return meaningful errors in spmi_controller_alloc() Fei Shao
2023-10-24  2:02 ` [PATCH 0/5] spmi: Add and use managed resource helpers Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).