Some improvements for OMAP hwspinlock
Subsystems (2)
Baolin Wang
reviewercover Some improvements for OMAP hwspinlock
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(-)
Signature · 1 line
1.7.9.5
Baolin Wang
reviewerPATCH 1/3 hwspinlock: omap: Change to use devm_platform_ioremap_resource()
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().
--- drivers/hwspinlock/omap_hwspinlock.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/hwspinlock/omap_hwspinlock.c +8 -16
@@ -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 ;
Signature · 1 line
1.7.9.5
Baolin Wang
reviewerPATCH 2/3 hwspinlock: omap: Use devm_kzalloc() to allocate memory
In reply to Baolin WangUse devm_kzalloc() to allocate memory, which can simplify the error handling.
--- drivers/hwspinlock/omap_hwspinlock.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/hwspinlock/omap_hwspinlock.c +3 -5
@@ -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 ; }
Signature · 1 line
1.7.9.5
Baolin Wang
reviewerPATCH 3/3 hwspinlock: omap: Use devm_hwspin_lock_register() to register hwlock controller
In reply to Baolin WangUse devm_hwspin_lock_register() to register the hwlock controller instead of unregistering the hwlock controller explicitly when removing the device.
--- drivers/hwspinlock/omap_hwspinlock.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/hwspinlock/omap_hwspinlock.c +2 -11
@@ -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 ;
Signature · 1 line
1.7.9.5