linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: st_rc: Handle errors of clk_prepare_enable()
@ 2021-05-15 12:39 Evgeny Novikov
  2021-05-17 11:09 ` Patrice CHOTARD
  2021-05-31 10:09 ` Sean Young
  0 siblings, 2 replies; 3+ messages in thread
From: Evgeny Novikov @ 2021-05-15 12:39 UTC (permalink / raw)
  To: Patrice Chotard
  Cc: Evgeny Novikov, Sean Young, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-media, linux-kernel, ldv-project

Hadle errors of clk_prepare_enable() in st_rc_hardware_init() and its
callers.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
---
 drivers/media/rc/st_rc.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c
index 3237fef5d502..f524fcf55acf 100644
--- a/drivers/media/rc/st_rc.c
+++ b/drivers/media/rc/st_rc.c
@@ -157,8 +157,9 @@ static irqreturn_t st_rc_rx_interrupt(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static void st_rc_hardware_init(struct st_rc_device *dev)
+static int st_rc_hardware_init(struct st_rc_device *dev)
 {
+	int ret;
 	int baseclock, freqdiff;
 	unsigned int rx_max_symbol_per = MAX_SYMB_TIME;
 	unsigned int rx_sampling_freq_div;
@@ -166,7 +167,10 @@ static void st_rc_hardware_init(struct st_rc_device *dev)
 	/* Enable the IP */
 	reset_control_deassert(dev->rstc);
 
-	clk_prepare_enable(dev->sys_clock);
+	ret = clk_prepare_enable(dev->sys_clock);
+	if (ret)
+		return ret;
+
 	baseclock = clk_get_rate(dev->sys_clock);
 
 	/* IRB input pins are inverted internally from high to low. */
@@ -184,6 +188,8 @@ static void st_rc_hardware_init(struct st_rc_device *dev)
 	}
 
 	writel(rx_max_symbol_per, dev->rx_base + IRB_MAX_SYM_PERIOD);
+
+	return 0;
 }
 
 static int st_rc_remove(struct platform_device *pdev)
@@ -287,7 +293,9 @@ static int st_rc_probe(struct platform_device *pdev)
 
 	rc_dev->dev = dev;
 	platform_set_drvdata(pdev, rc_dev);
-	st_rc_hardware_init(rc_dev);
+	ret = st_rc_hardware_init(rc_dev);
+	if (ret)
+		goto err;
 
 	rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
 	/* rx sampling rate is 10Mhz */
@@ -359,6 +367,7 @@ static int st_rc_suspend(struct device *dev)
 
 static int st_rc_resume(struct device *dev)
 {
+	int ret;
 	struct st_rc_device *rc_dev = dev_get_drvdata(dev);
 	struct rc_dev	*rdev = rc_dev->rdev;
 
@@ -367,7 +376,10 @@ static int st_rc_resume(struct device *dev)
 		rc_dev->irq_wake = 0;
 	} else {
 		pinctrl_pm_select_default_state(dev);
-		st_rc_hardware_init(rc_dev);
+		ret = st_rc_hardware_init(rc_dev);
+		if (ret)
+			return ret;
+
 		if (rdev->users) {
 			writel(IRB_RX_INTS, rc_dev->rx_base + IRB_RX_INT_EN);
 			writel(0x01, rc_dev->rx_base + IRB_RX_EN);
-- 
2.26.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] media: st_rc: Handle errors of clk_prepare_enable()
  2021-05-15 12:39 [PATCH] media: st_rc: Handle errors of clk_prepare_enable() Evgeny Novikov
@ 2021-05-17 11:09 ` Patrice CHOTARD
  2021-05-31 10:09 ` Sean Young
  1 sibling, 0 replies; 3+ messages in thread
From: Patrice CHOTARD @ 2021-05-17 11:09 UTC (permalink / raw)
  To: Evgeny Novikov
  Cc: Sean Young, Mauro Carvalho Chehab, linux-arm-kernel, linux-media,
	linux-kernel, ldv-project

Hi Avgeny

On 5/15/21 2:39 PM, Evgeny Novikov wrote:
> Hadle errors of clk_prepare_enable() in st_rc_hardware_init() and its
> callers.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
> ---
>  drivers/media/rc/st_rc.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c
> index 3237fef5d502..f524fcf55acf 100644
> --- a/drivers/media/rc/st_rc.c
> +++ b/drivers/media/rc/st_rc.c
> @@ -157,8 +157,9 @@ static irqreturn_t st_rc_rx_interrupt(int irq, void *data)
>  	return IRQ_HANDLED;
>  }
>  
> -static void st_rc_hardware_init(struct st_rc_device *dev)
> +static int st_rc_hardware_init(struct st_rc_device *dev)
>  {
> +	int ret;
>  	int baseclock, freqdiff;
>  	unsigned int rx_max_symbol_per = MAX_SYMB_TIME;
>  	unsigned int rx_sampling_freq_div;
> @@ -166,7 +167,10 @@ static void st_rc_hardware_init(struct st_rc_device *dev)
>  	/* Enable the IP */
>  	reset_control_deassert(dev->rstc);
>  
> -	clk_prepare_enable(dev->sys_clock);
> +	ret = clk_prepare_enable(dev->sys_clock);
> +	if (ret)
> +		return ret;
> +
>  	baseclock = clk_get_rate(dev->sys_clock);
>  
>  	/* IRB input pins are inverted internally from high to low. */
> @@ -184,6 +188,8 @@ static void st_rc_hardware_init(struct st_rc_device *dev)
>  	}
>  
>  	writel(rx_max_symbol_per, dev->rx_base + IRB_MAX_SYM_PERIOD);
> +
> +	return 0;
>  }
>  
>  static int st_rc_remove(struct platform_device *pdev)
> @@ -287,7 +293,9 @@ static int st_rc_probe(struct platform_device *pdev)
>  
>  	rc_dev->dev = dev;
>  	platform_set_drvdata(pdev, rc_dev);
> -	st_rc_hardware_init(rc_dev);
> +	ret = st_rc_hardware_init(rc_dev);
> +	if (ret)
> +		goto err;
>  
>  	rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
>  	/* rx sampling rate is 10Mhz */
> @@ -359,6 +367,7 @@ static int st_rc_suspend(struct device *dev)
>  
>  static int st_rc_resume(struct device *dev)
>  {
> +	int ret;
>  	struct st_rc_device *rc_dev = dev_get_drvdata(dev);
>  	struct rc_dev	*rdev = rc_dev->rdev;
>  
> @@ -367,7 +376,10 @@ static int st_rc_resume(struct device *dev)
>  		rc_dev->irq_wake = 0;
>  	} else {
>  		pinctrl_pm_select_default_state(dev);
> -		st_rc_hardware_init(rc_dev);
> +		ret = st_rc_hardware_init(rc_dev);
> +		if (ret)
> +			return ret;
> +
>  		if (rdev->users) {
>  			writel(IRB_RX_INTS, rc_dev->rx_base + IRB_RX_INT_EN);
>  			writel(0x01, rc_dev->rx_base + IRB_RX_EN);
> 

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] media: st_rc: Handle errors of clk_prepare_enable()
  2021-05-15 12:39 [PATCH] media: st_rc: Handle errors of clk_prepare_enable() Evgeny Novikov
  2021-05-17 11:09 ` Patrice CHOTARD
@ 2021-05-31 10:09 ` Sean Young
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Young @ 2021-05-31 10:09 UTC (permalink / raw)
  To: Evgeny Novikov
  Cc: Patrice Chotard, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-media, linux-kernel, ldv-project

On Sat, May 15, 2021 at 03:39:09PM +0300, Evgeny Novikov wrote:
> Hadle errors of clk_prepare_enable() in st_rc_hardware_init() and its
> callers.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
> ---
>  drivers/media/rc/st_rc.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c
> index 3237fef5d502..f524fcf55acf 100644
> --- a/drivers/media/rc/st_rc.c
> +++ b/drivers/media/rc/st_rc.c
> @@ -157,8 +157,9 @@ static irqreturn_t st_rc_rx_interrupt(int irq, void *data)
>  	return IRQ_HANDLED;
>  }
>  
> -static void st_rc_hardware_init(struct st_rc_device *dev)
> +static int st_rc_hardware_init(struct st_rc_device *dev)
>  {
> +	int ret;
>  	int baseclock, freqdiff;
>  	unsigned int rx_max_symbol_per = MAX_SYMB_TIME;
>  	unsigned int rx_sampling_freq_div;
> @@ -166,7 +167,10 @@ static void st_rc_hardware_init(struct st_rc_device *dev)
>  	/* Enable the IP */
>  	reset_control_deassert(dev->rstc);
>  
> -	clk_prepare_enable(dev->sys_clock);
> +	ret = clk_prepare_enable(dev->sys_clock);
> +	if (ret)
> +		return ret;

Now if probe or resume fails because of clk_prepare_enable() failing, no
error is logged. Please add a dev_err().

Thanks

Sean

> +
>  	baseclock = clk_get_rate(dev->sys_clock);
>  
>  	/* IRB input pins are inverted internally from high to low. */
> @@ -184,6 +188,8 @@ static void st_rc_hardware_init(struct st_rc_device *dev)
>  	}
>  
>  	writel(rx_max_symbol_per, dev->rx_base + IRB_MAX_SYM_PERIOD);
> +
> +	return 0;
>  }
>  
>  static int st_rc_remove(struct platform_device *pdev)
> @@ -287,7 +293,9 @@ static int st_rc_probe(struct platform_device *pdev)
>  
>  	rc_dev->dev = dev;
>  	platform_set_drvdata(pdev, rc_dev);
> -	st_rc_hardware_init(rc_dev);
> +	ret = st_rc_hardware_init(rc_dev);
> +	if (ret)
> +		goto err;
>  
>  	rdev->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
>  	/* rx sampling rate is 10Mhz */
> @@ -359,6 +367,7 @@ static int st_rc_suspend(struct device *dev)
>  
>  static int st_rc_resume(struct device *dev)
>  {
> +	int ret;
>  	struct st_rc_device *rc_dev = dev_get_drvdata(dev);
>  	struct rc_dev	*rdev = rc_dev->rdev;
>  
> @@ -367,7 +376,10 @@ static int st_rc_resume(struct device *dev)
>  		rc_dev->irq_wake = 0;
>  	} else {
>  		pinctrl_pm_select_default_state(dev);
> -		st_rc_hardware_init(rc_dev);
> +		ret = st_rc_hardware_init(rc_dev);
> +		if (ret)
> +			return ret;
> +
>  		if (rdev->users) {
>  			writel(IRB_RX_INTS, rc_dev->rx_base + IRB_RX_INT_EN);
>  			writel(0x01, rc_dev->rx_base + IRB_RX_EN);
> -- 
> 2.26.2

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-05-31 10:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-15 12:39 [PATCH] media: st_rc: Handle errors of clk_prepare_enable() Evgeny Novikov
2021-05-17 11:09 ` Patrice CHOTARD
2021-05-31 10:09 ` Sean Young

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).