linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: staging: rkisp1: isp: check return value from phy_*
@ 2020-06-17 18:22 Helen Koike
  2020-06-17 21:08 ` Tomasz Figa
  0 siblings, 1 reply; 2+ messages in thread
From: Helen Koike @ 2020-06-17 18:22 UTC (permalink / raw)
  To: linux-media
  Cc: mchehab, dafna.hirschfeld, linux-kernel, tfiga, hans.verkuil,
	kernel, Helen Koike, Wojciech Zabolotny

When starting streaming, do not ignore return value from phy_set_mode(),
phy_configure() and phy_power_on().
If it fails, return error to the user.

Fixes: d65dd85281fb ("media: staging: rkisp1: add Rockchip ISP1 base driver")

Reported-by: Wojciech Zabolotny <wzab01@gmail.com>
Signed-off-by: Helen Koike <helen.koike@collabora.com>

---

 drivers/staging/media/rkisp1/rkisp1-isp.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/rkisp1/rkisp1-isp.c b/drivers/staging/media/rkisp1/rkisp1-isp.c
index dc2b59a0160a8..531047fc34a01 100644
--- a/drivers/staging/media/rkisp1/rkisp1-isp.c
+++ b/drivers/staging/media/rkisp1/rkisp1-isp.c
@@ -892,6 +892,7 @@ static int rkisp1_mipi_csi2_start(struct rkisp1_isp *isp,
 	union phy_configure_opts opts;
 	struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy;
 	s64 pixel_clock;
+	int ret;
 
 	if (!sensor->pixel_rate_ctrl) {
 		dev_warn(sensor->sd->dev, "No pixel rate control in subdev\n");
@@ -906,9 +907,24 @@ static int rkisp1_mipi_csi2_start(struct rkisp1_isp *isp,
 
 	phy_mipi_dphy_get_default_config(pixel_clock, isp->sink_fmt->bus_width,
 					 sensor->lanes, cfg);
-	phy_set_mode(sensor->dphy, PHY_MODE_MIPI_DPHY);
-	phy_configure(sensor->dphy, &opts);
-	phy_power_on(sensor->dphy);
+
+	ret = phy_set_mode(sensor->dphy, PHY_MODE_MIPI_DPHY);
+	if (ret) {
+		dev_err(sensor->sd->dev, "Fail setting MIPI DPHY mode\n");
+		return -EINVAL;
+	}
+
+	ret = phy_configure(sensor->dphy, &opts);
+	if (ret && ret != -EOPNOTSUPP) {
+		dev_err(sensor->sd->dev, "Fail configuring MIPI DPHY\n");
+		return -EINVAL;
+	}
+
+	ret = phy_power_on(sensor->dphy);
+	if (ret) {
+		dev_err(sensor->sd->dev, "Fail powering on MIPI DPHY\n");
+		return -EINVAL;
+	}
 
 	return 0;
 }
-- 
2.26.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: staging: rkisp1: isp: check return value from phy_*
  2020-06-17 18:22 [PATCH] media: staging: rkisp1: isp: check return value from phy_* Helen Koike
@ 2020-06-17 21:08 ` Tomasz Figa
  0 siblings, 0 replies; 2+ messages in thread
From: Tomasz Figa @ 2020-06-17 21:08 UTC (permalink / raw)
  To: Helen Koike
  Cc: linux-media, mchehab, dafna.hirschfeld, linux-kernel, tfiga,
	hans.verkuil, kernel, Wojciech Zabolotny

Hi Helen,

On Wed, Jun 17, 2020 at 03:22:29PM -0300, Helen Koike wrote:
> When starting streaming, do not ignore return value from phy_set_mode(),
> phy_configure() and phy_power_on().
> If it fails, return error to the user.
> 
> Fixes: d65dd85281fb ("media: staging: rkisp1: add Rockchip ISP1 base driver")
> 
> Reported-by: Wojciech Zabolotny <wzab01@gmail.com>
> Signed-off-by: Helen Koike <helen.koike@collabora.com>
> 
> ---
> 
>  drivers/staging/media/rkisp1/rkisp1-isp.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 

Thank you for the patch. Please see my comments inline.

> diff --git a/drivers/staging/media/rkisp1/rkisp1-isp.c b/drivers/staging/media/rkisp1/rkisp1-isp.c
> index dc2b59a0160a8..531047fc34a01 100644
> --- a/drivers/staging/media/rkisp1/rkisp1-isp.c
> +++ b/drivers/staging/media/rkisp1/rkisp1-isp.c
> @@ -892,6 +892,7 @@ static int rkisp1_mipi_csi2_start(struct rkisp1_isp *isp,
>  	union phy_configure_opts opts;
>  	struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy;
>  	s64 pixel_clock;
> +	int ret;
>  
>  	if (!sensor->pixel_rate_ctrl) {
>  		dev_warn(sensor->sd->dev, "No pixel rate control in subdev\n");
> @@ -906,9 +907,24 @@ static int rkisp1_mipi_csi2_start(struct rkisp1_isp *isp,
>  
>  	phy_mipi_dphy_get_default_config(pixel_clock, isp->sink_fmt->bus_width,
>  					 sensor->lanes, cfg);
> -	phy_set_mode(sensor->dphy, PHY_MODE_MIPI_DPHY);
> -	phy_configure(sensor->dphy, &opts);
> -	phy_power_on(sensor->dphy);
> +
> +	ret = phy_set_mode(sensor->dphy, PHY_MODE_MIPI_DPHY);
> +	if (ret) {

nit: I don't seem to be able to find any documentation for this API and
it's not clear if it's guaranteed that the API doesn't return positive
values. It would probably be safer to check for ret < 0.

> +		dev_err(sensor->sd->dev, "Fail setting MIPI DPHY mode\n");
> +		return -EINVAL;

Should we just return ret?

> +	}
> +
> +	ret = phy_configure(sensor->dphy, &opts);
> +	if (ret && ret != -EOPNOTSUPP) {

Why are we okay with -EOPNOTSUPP?

> +		dev_err(sensor->sd->dev, "Fail configuring MIPI DPHY\n");
> +		return -EINVAL;
> +	}
> +
> +	ret = phy_power_on(sensor->dphy);
> +	if (ret) {
> +		dev_err(sensor->sd->dev, "Fail powering on MIPI DPHY\n");
> +		return -EINVAL;

Ditto.

Best regards,
Tomasz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-17 21:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 18:22 [PATCH] media: staging: rkisp1: isp: check return value from phy_* Helen Koike
2020-06-17 21:08 ` Tomasz Figa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).