Skip to content

Commit b195e10

Browse files
author
Lee Jones
committed
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: Lee Jones <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Reviewed-by: Mark Brown <[email protected]>
1 parent 99cd105 commit b195e10

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/mfd/mfd-core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ int mfd_cell_enable(struct platform_device *pdev)
2828
const struct mfd_cell *cell = mfd_get_cell(pdev);
2929
int err = 0;
3030

31+
if (!cell->enable) {
32+
dev_dbg(&pdev->dev, "No .enable() call-back registered\n");
33+
return 0;
34+
}
35+
3136
/* only call enable hook if the cell wasn't previously enabled */
3237
if (atomic_inc_return(cell->usage_count) == 1)
3338
err = cell->enable(pdev);
@@ -45,6 +50,11 @@ int mfd_cell_disable(struct platform_device *pdev)
4550
const struct mfd_cell *cell = mfd_get_cell(pdev);
4651
int err = 0;
4752

53+
if (!cell->disable) {
54+
dev_dbg(&pdev->dev, "No .disable() call-back registered\n");
55+
return 0;
56+
}
57+
4858
/* only disable if no other clients are using it */
4959
if (atomic_dec_return(cell->usage_count) == 0)
5060
err = cell->disable(pdev);

0 commit comments

Comments
 (0)