Commit b195e101 authored by Lee Jones's avatar Lee Jones

mfd: mfd-core: Protect against NULL call-back function pointer

If a child device calls mfd_cell_{en,dis}able() without an appropriate
call-back being set, we are likely to encounter a panic.  Avoid this
by adding suitable checking.
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Reviewed-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Reviewed-by: default avatarMark Brown <broonie@kernel.org>
parent 99cd1059
...@@ -28,6 +28,11 @@ int mfd_cell_enable(struct platform_device *pdev) ...@@ -28,6 +28,11 @@ int mfd_cell_enable(struct platform_device *pdev)
const struct mfd_cell *cell = mfd_get_cell(pdev); const struct mfd_cell *cell = mfd_get_cell(pdev);
int err = 0; int err = 0;
if (!cell->enable) {
dev_dbg(&pdev->dev, "No .enable() call-back registered\n");
return 0;
}
/* only call enable hook if the cell wasn't previously enabled */ /* only call enable hook if the cell wasn't previously enabled */
if (atomic_inc_return(cell->usage_count) == 1) if (atomic_inc_return(cell->usage_count) == 1)
err = cell->enable(pdev); err = cell->enable(pdev);
...@@ -45,6 +50,11 @@ int mfd_cell_disable(struct platform_device *pdev) ...@@ -45,6 +50,11 @@ int mfd_cell_disable(struct platform_device *pdev)
const struct mfd_cell *cell = mfd_get_cell(pdev); const struct mfd_cell *cell = mfd_get_cell(pdev);
int err = 0; int err = 0;
if (!cell->disable) {
dev_dbg(&pdev->dev, "No .disable() call-back registered\n");
return 0;
}
/* only disable if no other clients are using it */ /* only disable if no other clients are using it */
if (atomic_dec_return(cell->usage_count) == 0) if (atomic_dec_return(cell->usage_count) == 0)
err = cell->disable(pdev); err = cell->disable(pdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment