[v2] media: imx7-mipi-csis: Add a check for devm_regulator_get
diff mbox series

Message ID 20191015135915.6530-1-hslester96@gmail.com
State New
Headers show
Series
  • [v2] media: imx7-mipi-csis: Add a check for devm_regulator_get
Related show

Commit Message

Chuhong Yuan Oct. 15, 2019, 1:59 p.m. UTC
devm_regulator_get may return an error but mipi_csis_phy_init misses
a check for it.
This may lead to problems when regulator_set_voltage uses the unchecked
pointer.
This patch adds a check for devm_regulator_get to avoid potential risk.

Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
Changes in v2:
  - Add a check in mipi_csis_probe for the modified mipi_csis_phy_init.

 drivers/staging/media/imx/imx7-mipi-csis.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Marco Felsch Oct. 16, 2019, 9:06 a.m. UTC | #1
Hi Chuhong,

On 19-10-15 21:59, Chuhong Yuan wrote:
> devm_regulator_get may return an error but mipi_csis_phy_init misses
> a check for it.
> This may lead to problems when regulator_set_voltage uses the unchecked
> pointer.
> This patch adds a check for devm_regulator_get to avoid potential risk.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
> Changes in v2:
>   - Add a check in mipi_csis_probe for the modified mipi_csis_phy_init.

Did you miss the check for -EPROBE_DEFER?

Regards,
  Marco

> 
>  drivers/staging/media/imx/imx7-mipi-csis.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> index 73d8354e618c..e8a6acaa969e 100644
> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
> @@ -350,6 +350,8 @@ static void mipi_csis_sw_reset(struct csi_state *state)
>  static int mipi_csis_phy_init(struct csi_state *state)
>  {
>  	state->mipi_phy_regulator = devm_regulator_get(state->dev, "phy");
> +	if (IS_ERR(state->mipi_phy_regulator))
> +		return PTR_ERR(state->mipi_phy_regulator);
>  
>  	return regulator_set_voltage(state->mipi_phy_regulator, 1000000,
>  				     1000000);
> @@ -966,7 +968,10 @@ static int mipi_csis_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	mipi_csis_phy_init(state);
> +	ret = mipi_csis_phy_init(state);
> +	if (ret < 0)
> +		return ret;
> +
>  	mipi_csis_phy_reset(state);
>  
>  	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -- 
> 2.20.1
> 
> 
>
Rui Miguel Silva Oct. 16, 2019, 1:43 p.m. UTC | #2
Hi Marco,
On Wed 16 Oct 2019 at 10:06, Marco Felsch wrote:
> Hi Chuhong,
>
> On 19-10-15 21:59, Chuhong Yuan wrote:
>> devm_regulator_get may return an error but mipi_csis_phy_init misses
>> a check for it.
>> This may lead to problems when regulator_set_voltage uses the unchecked
>> pointer.
>> This patch adds a check for devm_regulator_get to avoid potential risk.
>>
>> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
>> ---
>> Changes in v2:
>>   - Add a check in mipi_csis_probe for the modified mipi_csis_phy_init.
>
> Did you miss the check for -EPROBE_DEFER?
>

I think nothing special is really needed to do in case of
EPROBE_DEFER, or am I missing something?
It just return to probe and probe returns also. I just talked
about it because it was not cover in the original code.

---
Cheers,
	Rui

>
> Regards,
>   Marco
>
>>
>>  drivers/staging/media/imx/imx7-mipi-csis.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
>> index 73d8354e618c..e8a6acaa969e 100644
>> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
>> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
>> @@ -350,6 +350,8 @@ static void mipi_csis_sw_reset(struct csi_state *state)
>>  static int mipi_csis_phy_init(struct csi_state *state)
>>  {
>>  	state->mipi_phy_regulator = devm_regulator_get(state->dev, "phy");
>> +	if (IS_ERR(state->mipi_phy_regulator))
>> +		return PTR_ERR(state->mipi_phy_regulator);
>>
>>  	return regulator_set_voltage(state->mipi_phy_regulator, 1000000,
>>  				     1000000);
>> @@ -966,7 +968,10 @@ static int mipi_csis_probe(struct platform_device *pdev)
>>  		return ret;
>>  	}
>>
>> -	mipi_csis_phy_init(state);
>> +	ret = mipi_csis_phy_init(state);
>> +	if (ret < 0)
>> +		return ret;
>> +
>>  	mipi_csis_phy_reset(state);
>>
>>  	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> --
>> 2.20.1
>>
>>
>>
Marco Felsch Oct. 17, 2019, 8:10 a.m. UTC | #3
Hi Rui,

On 19-10-16 14:43, Rui Miguel Silva wrote:
> Hi Marco,
> On Wed 16 Oct 2019 at 10:06, Marco Felsch wrote:
> > Hi Chuhong,
> >
> > On 19-10-15 21:59, Chuhong Yuan wrote:
> >> devm_regulator_get may return an error but mipi_csis_phy_init misses
> >> a check for it.
> >> This may lead to problems when regulator_set_voltage uses the unchecked
> >> pointer.
> >> This patch adds a check for devm_regulator_get to avoid potential risk.
> >>
> >> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> >> ---
> >> Changes in v2:
> >>   - Add a check in mipi_csis_probe for the modified mipi_csis_phy_init.
> >
> > Did you miss the check for -EPROBE_DEFER?
> >
> 
> I think nothing special is really needed to do in case of
> EPROBE_DEFER, or am I missing something?
> It just return to probe and probe returns also. I just talked
> about it because it was not cover in the original code.

Yes, your are right... I shouldn't comment on anything I read with one
eye. Sorry.

Regards,
  Marco

> ---
> Cheers,
> 	Rui
> 
> >
> > Regards,
> >   Marco
> >
> >>
> >>  drivers/staging/media/imx/imx7-mipi-csis.c | 8 +++++++-
> >>  1 file changed, 7 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> >> index 73d8354e618c..e8a6acaa969e 100644
> >> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
> >> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
> >> @@ -350,6 +350,8 @@ static void mipi_csis_sw_reset(struct csi_state *state)
> >>  static int mipi_csis_phy_init(struct csi_state *state)
> >>  {
> >>  	state->mipi_phy_regulator = devm_regulator_get(state->dev, "phy");
> >> +	if (IS_ERR(state->mipi_phy_regulator))
> >> +		return PTR_ERR(state->mipi_phy_regulator);
> >>
> >>  	return regulator_set_voltage(state->mipi_phy_regulator, 1000000,
> >>  				     1000000);
> >> @@ -966,7 +968,10 @@ static int mipi_csis_probe(struct platform_device *pdev)
> >>  		return ret;
> >>  	}
> >>
> >> -	mipi_csis_phy_init(state);
> >> +	ret = mipi_csis_phy_init(state);
> >> +	if (ret < 0)
> >> +		return ret;
> >> +
> >>  	mipi_csis_phy_reset(state);
> >>
> >>  	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> >> --
> >> 2.20.1
> >>
> >>
> >>
> 
>
Rui Miguel Silva Oct. 17, 2019, 9:43 a.m. UTC | #4
Hi Marco,
On Thu 17 Oct 2019 at 09:10, Marco Felsch wrote:
> Hi Rui,
>
> On 19-10-16 14:43, Rui Miguel Silva wrote:
>> Hi Marco,
>> On Wed 16 Oct 2019 at 10:06, Marco Felsch wrote:
>> > Hi Chuhong,
>> >
>> > On 19-10-15 21:59, Chuhong Yuan wrote:
>> >> devm_regulator_get may return an error but mipi_csis_phy_init misses
>> >> a check for it.
>> >> This may lead to problems when regulator_set_voltage uses the unchecked
>> >> pointer.
>> >> This patch adds a check for devm_regulator_get to avoid potential risk.
>> >>
>> >> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
>> >> ---
>> >> Changes in v2:
>> >>   - Add a check in mipi_csis_probe for the modified mipi_csis_phy_init.
>> >
>> > Did you miss the check for -EPROBE_DEFER?
>> >
>>
>> I think nothing special is really needed to do in case of
>> EPROBE_DEFER, or am I missing something?
>> It just return to probe and probe returns also. I just talked
>> about it because it was not cover in the original code.
>
> Yes, your are right... I shouldn't comment on anything I read with one
> eye. Sorry.
>

ehehe, no problem and thanks for your inputs.

---
Cheers,
	Rui

>
> Regards,
>   Marco
>
>> ---
>> Cheers,
>> 	Rui
>>
>> >
>> > Regards,
>> >   Marco
>> >
>> >>
>> >>  drivers/staging/media/imx/imx7-mipi-csis.c | 8 +++++++-
>> >>  1 file changed, 7 insertions(+), 1 deletion(-)
>> >>
>> >> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
>> >> index 73d8354e618c..e8a6acaa969e 100644
>> >> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
>> >> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
>> >> @@ -350,6 +350,8 @@ static void mipi_csis_sw_reset(struct csi_state *state)
>> >>  static int mipi_csis_phy_init(struct csi_state *state)
>> >>  {
>> >>  	state->mipi_phy_regulator = devm_regulator_get(state->dev, "phy");
>> >> +	if (IS_ERR(state->mipi_phy_regulator))
>> >> +		return PTR_ERR(state->mipi_phy_regulator);
>> >>
>> >>  	return regulator_set_voltage(state->mipi_phy_regulator, 1000000,
>> >>  				     1000000);
>> >> @@ -966,7 +968,10 @@ static int mipi_csis_probe(struct platform_device *pdev)
>> >>  		return ret;
>> >>  	}
>> >>
>> >> -	mipi_csis_phy_init(state);
>> >> +	ret = mipi_csis_phy_init(state);
>> >> +	if (ret < 0)
>> >> +		return ret;
>> >> +
>> >>  	mipi_csis_phy_reset(state);
>> >>
>> >>  	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> >> --
>> >> 2.20.1
>> >>
>> >>
>> >>
>>
>>
Rui Miguel Silva Oct. 17, 2019, 9:46 a.m. UTC | #5
Hi Chuhong,
many thanks for the patch.

On Tue 15 Oct 2019 at 14:59, Chuhong Yuan wrote:
> devm_regulator_get may return an error but mipi_csis_phy_init misses
> a check for it.
> This may lead to problems when regulator_set_voltage uses the unchecked
> pointer.
> This patch adds a check for devm_regulator_get to avoid potential risk.
>
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>

Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>

---
Cheers,
	Rui

> ---
> Changes in v2:
>   - Add a check in mipi_csis_probe for the modified mipi_csis_phy_init.
>
>  drivers/staging/media/imx/imx7-mipi-csis.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> index 73d8354e618c..e8a6acaa969e 100644
> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
> @@ -350,6 +350,8 @@ static void mipi_csis_sw_reset(struct csi_state *state)
>  static int mipi_csis_phy_init(struct csi_state *state)
>  {
>  	state->mipi_phy_regulator = devm_regulator_get(state->dev, "phy");
> +	if (IS_ERR(state->mipi_phy_regulator))
> +		return PTR_ERR(state->mipi_phy_regulator);
>
>  	return regulator_set_voltage(state->mipi_phy_regulator, 1000000,
>  				     1000000);
> @@ -966,7 +968,10 @@ static int mipi_csis_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>
> -	mipi_csis_phy_init(state);
> +	ret = mipi_csis_phy_init(state);
> +	if (ret < 0)
> +		return ret;
> +
>  	mipi_csis_phy_reset(state);
>
>  	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

Patch
diff mbox series

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 73d8354e618c..e8a6acaa969e 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -350,6 +350,8 @@  static void mipi_csis_sw_reset(struct csi_state *state)
 static int mipi_csis_phy_init(struct csi_state *state)
 {
 	state->mipi_phy_regulator = devm_regulator_get(state->dev, "phy");
+	if (IS_ERR(state->mipi_phy_regulator))
+		return PTR_ERR(state->mipi_phy_regulator);
 
 	return regulator_set_voltage(state->mipi_phy_regulator, 1000000,
 				     1000000);
@@ -966,7 +968,10 @@  static int mipi_csis_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	mipi_csis_phy_init(state);
+	ret = mipi_csis_phy_init(state);
+	if (ret < 0)
+		return ret;
+
 	mipi_csis_phy_reset(state);
 
 	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);