]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mfd: mfd-core: Protect against NULL call-back function pointer
authorLee Jones <lee.jones@linaro.org>
Mon, 21 Oct 2019 09:16:34 +0000 (10:16 +0100)
committerLee Jones <lee.jones@linaro.org>
Mon, 11 Nov 2019 08:45:03 +0000 (08:45 +0000)
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>
Reviewed-by: Mark Brown <broonie@kernel.org>
drivers/mfd/mfd-core.c

index 23276a80e3b48334b39735807be139f054fbc420..96d02b6f06fd8f61975f78eefe48c658bbdfb7b1 100644 (file)
@@ -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);