Skip to content

Commit

Permalink
hwspinlock: omap: Use devm_kzalloc() to allocate memory
Browse files Browse the repository at this point in the history
Use devm_kzalloc() to allocate memory, which can simplify the error
handling.

Signed-off-by: Baolin Wang <baolin.wang7@gmail.com>
Link: https://lore.kernel.org/r/c066ad704c1a5fd52c3002cac80ddd59b3901b01.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 bf27400 commit 42f291e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions drivers/hwspinlock/omap_hwspinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -159,7 +158,6 @@ static int omap_hwspinlock_remove(struct platform_device *pdev)
}

pm_runtime_disable(&pdev->dev);
kfree(bank);

return 0;
}
Expand Down

0 comments on commit 42f291e

Please sign in to comment.