All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Some improvements for OMAP hwspinlock
@ 2019-12-04  9:31 Baolin Wang
  2019-12-04  9:31 ` [PATCH 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource() Baolin Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Baolin Wang @ 2019-12-04  9:31 UTC (permalink / raw)
  To: ohad, bjorn.andersson
  Cc: baolin.wang7, linux-omap, linux-remoteproc, linux-kernel

This patch set did some optimization for OMAP hwlock controller with
changing to use some devm_xxx APIs to simplify code.

Baolin Wang (3):
  hwspinlock: omap: Change to use devm_platform_ioremap_resource()
  hwspinlock: omap: Use devm_kzalloc() to allocate memory
  hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock
    controller

 drivers/hwspinlock/omap_hwspinlock.c |   45 ++++++++++------------------------
 1 file changed, 13 insertions(+), 32 deletions(-)

-- 
1.7.9.5


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

* [PATCH 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource()
  2019-12-04  9:31 [PATCH 0/3] Some improvements for OMAP hwspinlock Baolin Wang
@ 2019-12-04  9:31 ` Baolin Wang
  2019-12-04  9:31 ` [PATCH 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory Baolin Wang
  2019-12-04  9:31 ` [PATCH 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller Baolin Wang
  2 siblings, 0 replies; 4+ messages in thread
From: Baolin Wang @ 2019-12-04  9:31 UTC (permalink / raw)
  To: ohad, bjorn.andersson
  Cc: baolin.wang7, linux-omap, linux-remoteproc, linux-kernel

Use the new helper that wraps the calls to platform_get_resource()
and devm_ioremap_resource() together, which can simpify the code.
Meanwhile renaming the error label to make more sense after removing
iounmap().

Signed-off-by: Baolin Wang <baolin.wang7@gmail.com>
---
 drivers/hwspinlock/omap_hwspinlock.c |   24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c
index 14e1a53..dbb1a4c 100644
--- a/drivers/hwspinlock/omap_hwspinlock.c
+++ b/drivers/hwspinlock/omap_hwspinlock.c
@@ -76,7 +76,6 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 	struct device_node *node = pdev->dev.of_node;
 	struct hwspinlock_device *bank;
 	struct hwspinlock *hwlock;
-	struct resource *res;
 	void __iomem *io_base;
 	int num_locks, i, ret;
 	/* Only a single hwspinlock block device is supported */
@@ -85,13 +84,9 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 	if (!node)
 		return -ENODEV;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENODEV;
-
-	io_base = ioremap(res->start, resource_size(res));
-	if (!io_base)
-		return -ENOMEM;
+	io_base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(io_base))
+		return PTR_ERR(io_base);
 
 	/*
 	 * make sure the module is enabled and clocked before reading
@@ -101,7 +96,7 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 	ret = pm_runtime_get_sync(&pdev->dev);
 	if (ret < 0) {
 		pm_runtime_put_noidle(&pdev->dev);
-		goto iounmap_base;
+		goto runtime_err;
 	}
 
 	/* Determine number of locks */
@@ -114,12 +109,12 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 	 */
 	ret = pm_runtime_put(&pdev->dev);
 	if (ret < 0)
-		goto iounmap_base;
+		goto runtime_err;
 
 	/* one of the four lsb's must be set, and nothing else */
 	if (hweight_long(i & 0xf) != 1 || i > 8) {
 		ret = -EINVAL;
-		goto iounmap_base;
+		goto runtime_err;
 	}
 
 	num_locks = i * 32; /* actual number of locks in this device */
@@ -127,7 +122,7 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 	bank = kzalloc(struct_size(bank, lock, num_locks), GFP_KERNEL);
 	if (!bank) {
 		ret = -ENOMEM;
-		goto iounmap_base;
+		goto runtime_err;
 	}
 
 	platform_set_drvdata(pdev, bank);
@@ -147,16 +142,14 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 
 reg_fail:
 	kfree(bank);
-iounmap_base:
+runtime_err:
 	pm_runtime_disable(&pdev->dev);
-	iounmap(io_base);
 	return ret;
 }
 
 static int omap_hwspinlock_remove(struct platform_device *pdev)
 {
 	struct hwspinlock_device *bank = platform_get_drvdata(pdev);
-	void __iomem *io_base = bank->lock[0].priv - LOCK_BASE_OFFSET;
 	int ret;
 
 	ret = hwspin_lock_unregister(bank);
@@ -166,7 +159,6 @@ static int omap_hwspinlock_remove(struct platform_device *pdev)
 	}
 
 	pm_runtime_disable(&pdev->dev);
-	iounmap(io_base);
 	kfree(bank);
 
 	return 0;
-- 
1.7.9.5


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

* [PATCH 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory
  2019-12-04  9:31 [PATCH 0/3] Some improvements for OMAP hwspinlock Baolin Wang
  2019-12-04  9:31 ` [PATCH 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource() Baolin Wang
@ 2019-12-04  9:31 ` Baolin Wang
  2019-12-04  9:31 ` [PATCH 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller Baolin Wang
  2 siblings, 0 replies; 4+ messages in thread
From: Baolin Wang @ 2019-12-04  9:31 UTC (permalink / raw)
  To: ohad, bjorn.andersson
  Cc: baolin.wang7, linux-omap, linux-remoteproc, linux-kernel

Use devm_kzalloc() to allocate memory, which can simplify the error
handling.

Signed-off-by: Baolin Wang <baolin.wang7@gmail.com>
---
 drivers/hwspinlock/omap_hwspinlock.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c
index dbb1a4c..3b05560 100644
--- a/drivers/hwspinlock/omap_hwspinlock.c
+++ b/drivers/hwspinlock/omap_hwspinlock.c
@@ -119,7 +119,8 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 
 	num_locks = i * 32; /* actual number of locks in this device */
 
-	bank = kzalloc(struct_size(bank, lock, num_locks), GFP_KERNEL);
+	bank = devm_kzalloc(&pdev->dev, struct_size(bank, lock, num_locks),
+			    GFP_KERNEL);
 	if (!bank) {
 		ret = -ENOMEM;
 		goto runtime_err;
@@ -133,15 +134,13 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 	ret = hwspin_lock_register(bank, &pdev->dev, &omap_hwspinlock_ops,
 						base_id, num_locks);
 	if (ret)
-		goto reg_fail;
+		goto runtime_err;
 
 	dev_dbg(&pdev->dev, "Registered %d locks with HwSpinlock core\n",
 		num_locks);
 
 	return 0;
 
-reg_fail:
-	kfree(bank);
 runtime_err:
 	pm_runtime_disable(&pdev->dev);
 	return ret;
@@ -159,7 +158,6 @@ static int omap_hwspinlock_remove(struct platform_device *pdev)
 	}
 
 	pm_runtime_disable(&pdev->dev);
-	kfree(bank);
 
 	return 0;
 }
-- 
1.7.9.5


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

* [PATCH 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller
  2019-12-04  9:31 [PATCH 0/3] Some improvements for OMAP hwspinlock Baolin Wang
  2019-12-04  9:31 ` [PATCH 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource() Baolin Wang
  2019-12-04  9:31 ` [PATCH 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory Baolin Wang
@ 2019-12-04  9:31 ` Baolin Wang
  2 siblings, 0 replies; 4+ messages in thread
From: Baolin Wang @ 2019-12-04  9:31 UTC (permalink / raw)
  To: ohad, bjorn.andersson
  Cc: baolin.wang7, linux-omap, linux-remoteproc, linux-kernel

Use devm_hwspin_lock_register() to register the hwlock controller instead of
unregistering the hwlock controller explicitly when removing the device.

Signed-off-by: Baolin Wang <baolin.wang7@gmail.com>
---
 drivers/hwspinlock/omap_hwspinlock.c |   13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c
index 3b05560..9e8a8c2 100644
--- a/drivers/hwspinlock/omap_hwspinlock.c
+++ b/drivers/hwspinlock/omap_hwspinlock.c
@@ -131,8 +131,8 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 	for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++)
 		hwlock->priv = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i;
 
-	ret = hwspin_lock_register(bank, &pdev->dev, &omap_hwspinlock_ops,
-						base_id, num_locks);
+	ret = devm_hwspin_lock_register(&pdev->dev, bank, &omap_hwspinlock_ops,
+					base_id, num_locks);
 	if (ret)
 		goto runtime_err;
 
@@ -148,15 +148,6 @@ static int omap_hwspinlock_probe(struct platform_device *pdev)
 
 static int omap_hwspinlock_remove(struct platform_device *pdev)
 {
-	struct hwspinlock_device *bank = platform_get_drvdata(pdev);
-	int ret;
-
-	ret = hwspin_lock_unregister(bank);
-	if (ret) {
-		dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
-		return ret;
-	}
-
 	pm_runtime_disable(&pdev->dev);
 
 	return 0;
-- 
1.7.9.5


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

end of thread, other threads:[~2019-12-04  9:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04  9:31 [PATCH 0/3] Some improvements for OMAP hwspinlock Baolin Wang
2019-12-04  9:31 ` [PATCH 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource() Baolin Wang
2019-12-04  9:31 ` [PATCH 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory Baolin Wang
2019-12-04  9:31 ` [PATCH 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller Baolin Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.