Skip to content

Commit

Permalink
hwspinlock: omap: Change to use devm_platform_ioremap_resource()
Browse files Browse the repository at this point in the history
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>
Link: https://lore.kernel.org/r/6c09c5034a7e68fdfc22d2cb5daa375bccb33a66.1578453062.git.baolin.wang7@gmail.com
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
  • Loading branch information
Baolin Wang authored and Bjorn Andersson committed Jan 22, 2020
1 parent ed0611a commit bf27400
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions drivers/hwspinlock/omap_hwspinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -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 */
Expand All @@ -114,20 +109,20 @@ 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 */

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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit bf27400

Please sign in to comment.