diff mbox series

[v2,7/9] mfd: mfd-core: Protect against NULL call-back function pointer

Message ID 20191021105822.20271-8-lee.jones@linaro.org
State Superseded
Headers show
Series Simplify MFD Core | expand

Commit Message

Lee Jones Oct. 21, 2019, 10:58 a.m. UTC
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>

---
 drivers/mfd/mfd-core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

-- 
2.17.1

Comments

Daniel Thompson Oct. 21, 2019, 12:30 p.m. UTC | #1
On Mon, Oct 21, 2019 at 11:58:20AM +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>


> ---

>  drivers/mfd/mfd-core.c | 10 ++++++++++

>  1 file changed, 10 insertions(+)

> 

> diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c

> index 8126665bb2d8..90b43b44a15a 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->enable) {

> +		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);

> -- 

> 2.17.1

>
Daniel Thompson Oct. 21, 2019, 12:32 p.m. UTC | #2
On Mon, Oct 21, 2019 at 11:58:20AM +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>

> ---

>  drivers/mfd/mfd-core.c | 10 ++++++++++

>  1 file changed, 10 insertions(+)

> 

> diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c

> index 8126665bb2d8..90b43b44a15a 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->enable) {


Oops.

Cancel the R-B: ;-). Shouldn't this be !cell->disable() ?


Daniel.



> +		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);

> -- 

> 2.17.1

>
Lee Jones Oct. 21, 2019, 12:40 p.m. UTC | #3
On Mon, 21 Oct 2019, Daniel Thompson wrote:

> On Mon, Oct 21, 2019 at 11:58:20AM +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>

> > ---

> >  drivers/mfd/mfd-core.c | 10 ++++++++++

> >  1 file changed, 10 insertions(+)

> > 

> > diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c

> > index 8126665bb2d8..90b43b44a15a 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->enable) {

> 

> Oops.

> 

> Cancel the R-B: ;-). Shouldn't this be !cell->disable() ?


Yes. Looks like a C/P error.

Will fix and add your R-b.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
diff mbox series

Patch

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 8126665bb2d8..90b43b44a15a 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->enable) {
+		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);