Message ID | 20191024163832.31326-9-lee.jones@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | Simplify MFD Core | expand |
On Thu, Oct 24, 2019 at 05:38:30PM +0100, Lee Jones wrote: > 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: Lee Jones <lee.jones@linaro.org> > Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org> Shouldn't this be earlier in the patch set (to avoid transient regressions)? Daniel.
On Thu, Oct 24, 2019 at 05:38:30PM +0100, Lee Jones wrote: > 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. Reviwed-by: Mark Brown <broonie@kernel.org>
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c index 8126665bb2d8..e38e411ca775 100644 --- a/drivers/mfd/mfd-core.c +++ b/drivers/mfd/mfd-core.c @@ -28,6 +28,11 @@ int mfd_cell_enable(struct platform_device *pdev) const struct mfd_cell *cell = mfd_get_cell(pdev); 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 */ if (atomic_inc_return(cell->usage_count) == 1) err = cell->enable(pdev); @@ -45,6 +50,11 @@ int mfd_cell_disable(struct platform_device *pdev) const struct mfd_cell *cell = mfd_get_cell(pdev); 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 */ if (atomic_dec_return(cell->usage_count) == 0) err = cell->disable(pdev);