All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock
@ 2020-01-08  3:13 Baolin Wang
  2020-01-08  3:13 ` [PATCH RESEND 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource() Baolin Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Baolin Wang @ 2020-01-08  3:13 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] 9+ messages in thread

* [PATCH RESEND 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource()
  2020-01-08  3:13 [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock Baolin Wang
@ 2020-01-08  3:13 ` Baolin Wang
  2020-01-08  3:14 ` [PATCH RESEND 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory Baolin Wang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Baolin Wang @ 2020-01-08  3:13 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] 9+ messages in thread

* [PATCH RESEND 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory
  2020-01-08  3:13 [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock Baolin Wang
  2020-01-08  3:13 ` [PATCH RESEND 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource() Baolin Wang
@ 2020-01-08  3:14 ` Baolin Wang
  2020-01-08  3:14 ` [PATCH RESEND 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller Baolin Wang
  2020-01-22  0:16   ` Bjorn Andersson
  3 siblings, 0 replies; 9+ messages in thread
From: Baolin Wang @ 2020-01-08  3:14 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] 9+ messages in thread

* [PATCH RESEND 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller
  2020-01-08  3:13 [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock Baolin Wang
  2020-01-08  3:13 ` [PATCH RESEND 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource() Baolin Wang
  2020-01-08  3:14 ` [PATCH RESEND 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory Baolin Wang
@ 2020-01-08  3:14 ` Baolin Wang
  2020-01-22  0:15     ` Bjorn Andersson
  2020-01-22  0:16   ` Bjorn Andersson
  3 siblings, 1 reply; 9+ messages in thread
From: Baolin Wang @ 2020-01-08  3:14 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] 9+ messages in thread

* Re: [PATCH RESEND 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller
  2020-01-08  3:14 ` [PATCH RESEND 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller Baolin Wang
@ 2020-01-22  0:15     ` Bjorn Andersson
  0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2020-01-22  0:15 UTC (permalink / raw)
  To: Baolin Wang; +Cc: ohad, linux-omap, linux-remoteproc, linux-kernel

On Tue 07 Jan 19:14 PST 2020, Baolin Wang wrote:

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

Relying on devm_hwspin_lock_register() to hwspin_lock_unregister() will
mean that pm_runtime_disable() will now be called before the spinlocks
are unregistered.

Regards,
Bjorn

>  	pm_runtime_disable(&pdev->dev);
>  
>  	return 0;
> -- 
> 1.7.9.5
> 

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

* Re: [PATCH RESEND 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller
@ 2020-01-22  0:15     ` Bjorn Andersson
  0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2020-01-22  0:15 UTC (permalink / raw)
  To: Baolin Wang; +Cc: ohad, linux-omap, linux-remoteproc, linux-kernel

On Tue 07 Jan 19:14 PST 2020, Baolin Wang wrote:

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

Relying on devm_hwspin_lock_register() to hwspin_lock_unregister() will
mean that pm_runtime_disable() will now be called before the spinlocks
are unregistered.

Regards,
Bjorn

>  	pm_runtime_disable(&pdev->dev);
>  
>  	return 0;
> -- 
> 1.7.9.5
> 

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

* Re: [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock
  2020-01-08  3:13 [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock Baolin Wang
@ 2020-01-22  0:16   ` Bjorn Andersson
  2020-01-08  3:14 ` [PATCH RESEND 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory Baolin Wang
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2020-01-22  0:15 UTC (permalink / raw)
  To: Baolin Wang; +Cc: ohad, linux-omap, linux-remoteproc, linux-kernel

On Tue 07 Jan 19:13 PST 2020, Baolin Wang wrote:

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

Applied the first 2 patches, thanks.

> 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] 9+ messages in thread

* Re: [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock
@ 2020-01-22  0:16   ` Bjorn Andersson
  0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2020-01-22  0:16 UTC (permalink / raw)
  To: Baolin Wang; +Cc: ohad, linux-omap, linux-remoteproc, linux-kernel

On Tue 07 Jan 19:13 PST 2020, Baolin Wang wrote:

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

Applied the first 2 patches, thanks.

> 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] 9+ messages in thread

* Re: [PATCH RESEND 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller
  2020-01-22  0:15     ` Bjorn Andersson
  (?)
@ 2020-01-25  4:10     ` Baolin Wang
  -1 siblings, 0 replies; 9+ messages in thread
From: Baolin Wang @ 2020-01-25  4:10 UTC (permalink / raw)
  To: Bjorn Andersson; +Cc: Ohad Ben Cohen, linux-omap, linux-remoteproc, LKML

Hi Bjorn,

On Wed, Jan 22, 2020 at 8:15 AM Bjorn Andersson
<bjorn.andersson@linaro.org> wrote:
>
> On Tue 07 Jan 19:14 PST 2020, Baolin Wang wrote:
>
> > 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;
> > -     }
> > -
>
> Relying on devm_hwspin_lock_register() to hwspin_lock_unregister() will
> mean that pm_runtime_disable() will now be called before the spinlocks
> are unregistered.

Yes, you are right. Thanks for catching this issue.

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

end of thread, other threads:[~2020-01-25  4:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08  3:13 [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock Baolin Wang
2020-01-08  3:13 ` [PATCH RESEND 1/3] hwspinlock: omap: Change to use devm_platform_ioremap_resource() Baolin Wang
2020-01-08  3:14 ` [PATCH RESEND 2/3] hwspinlock: omap: Use devm_kzalloc() to allocate memory Baolin Wang
2020-01-08  3:14 ` [PATCH RESEND 3/3] hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller Baolin Wang
2020-01-22  0:15   ` Bjorn Andersson
2020-01-22  0:15     ` Bjorn Andersson
2020-01-25  4:10     ` Baolin Wang
2020-01-22  0:15 ` [PATCH RESEND 0/3] Some improvements for OMAP hwspinlock Bjorn Andersson
2020-01-22  0:16   ` Bjorn Andersson

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.