diff mbox

[v2] crypto: omap-sham: Check for return value from pm_runtime_get_sync

Message ID 1425808861-17004-1-git-send-email-pali.rohar@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pali Rohár March 8, 2015, 10:01 a.m. UTC
Function pm_runtime_get_sync could fail and we need to check return
value to prevent kernel crash.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
v2: Check return value for all pm_runtime_get_sync() calls
---
 drivers/crypto/omap-sham.c |   23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

Comments

Pavel Machek March 9, 2015, 8:52 p.m. UTC | #1
On Sun 2015-03-08 11:01:01, Pali Rohár wrote:
> Function pm_runtime_get_sync could fail and we need to check return
> value to prevent kernel crash.
> 
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>

Acked-by: Pavel Machek <pavel@ucw.cz>
Pali Rohár May 14, 2015, 9:40 p.m. UTC | #2
On Sunday 08 March 2015 11:01:01 Pali Rohár wrote:
> Function pm_runtime_get_sync could fail and we need to check return
> value to prevent kernel crash.
> 
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> ---
> v2: Check return value for all pm_runtime_get_sync() calls
> ---
>  drivers/crypto/omap-sham.c |   23 ++++++++++++++++++++---
>  1 file changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
> index b20e374..c5df53d 100644
> --- a/drivers/crypto/omap-sham.c
> +++ b/drivers/crypto/omap-sham.c
> @@ -362,7 +362,13 @@ static void omap_sham_copy_ready_hash(struct
> ahash_request *req)
> 
>  static int omap_sham_hw_init(struct omap_sham_dev *dd)
>  {
> -	pm_runtime_get_sync(dd->dev);
> +	int err;
> +
> +	err = pm_runtime_get_sync(dd->dev);
> +	if (err < 0) {
> +		dev_err(dd->dev, "failed to get sync: %d\n", err);
> +		return err;
> +	}
> 
>  	if (!test_bit(FLAGS_INIT, &dd->flags)) {
>  		set_bit(FLAGS_INIT, &dd->flags);
> @@ -1949,7 +1955,13 @@ static int omap_sham_probe(struct
> platform_device *pdev) dd->flags |= dd->pdata->flags;
> 
>  	pm_runtime_enable(dev);
> -	pm_runtime_get_sync(dev);
> +
> +	err = pm_runtime_get_sync(dev);
> +	if (err < 0) {
> +		dev_err(dev, "failed to get sync: %d\n", err);
> +		goto err_pm;
> +	}
> +
>  	rev = omap_sham_read(dd, SHA_REG_REV(dd));
>  	pm_runtime_put_sync(&pdev->dev);
> 
> @@ -1979,6 +1991,7 @@ err_algs:
>  		for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--)
>  			crypto_unregister_ahash(
>  					&dd->pdata->algs_info[i].algs_list[j]);
> +err_pm:
>  	pm_runtime_disable(dev);
>  	if (dd->dma_lch)
>  		dma_release_channel(dd->dma_lch);
> @@ -2021,7 +2034,11 @@ static int omap_sham_suspend(struct device
> *dev)
> 
>  static int omap_sham_resume(struct device *dev)
>  {
> -	pm_runtime_get_sync(dev);
> +	int err = pm_runtime_get_sync(dev);
> +	if (err < 0) {
> +		dev_err(dev, "failed to get sync: %d\n", err);
> +		return err;
> +	}
>  	return 0;
>  }
>  #endif

Herbert, can you apply this patch?
Herbert Xu May 15, 2015, 12:15 a.m. UTC | #3
On Thu, May 14, 2015 at 11:40:37PM +0200, Pali Rohár wrote:
>
> Herbert, can you apply this patch?

OK I dug this out of patchwork for you.  In future please post
patches that you want me to apply separately.

Thanks,
Herbert Xu May 15, 2015, 7:02 a.m. UTC | #4
On Thu, May 14, 2015 at 11:40:37PM +0200, Pali Rohár wrote:
> On Sunday 08 March 2015 11:01:01 Pali Rohár wrote:
> > Function pm_runtime_get_sync could fail and we need to check return
> > value to prevent kernel crash.
> > 
> > Signed-off-by: Pali Rohár <pali.rohar@gmail.com>

Applied.
Pali Rohár May 15, 2015, 9:20 a.m. UTC | #5
On Friday 15 May 2015 15:02:29 Herbert Xu wrote:
> On Thu, May 14, 2015 at 11:40:37PM +0200, Pali Rohár wrote:
> > On Sunday 08 March 2015 11:01:01 Pali Rohár wrote:
> > > Function pm_runtime_get_sync could fail and we need to check return
> > > value to prevent kernel crash.
> > > 
> > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> 
> Applied.

Thanks! In this patch series is also another one patch for crypto
subsystem. I replied to that patch email.
diff mbox

Patch

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index b20e374..c5df53d 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -362,7 +362,13 @@  static void omap_sham_copy_ready_hash(struct ahash_request *req)
 
 static int omap_sham_hw_init(struct omap_sham_dev *dd)
 {
-	pm_runtime_get_sync(dd->dev);
+	int err;
+
+	err = pm_runtime_get_sync(dd->dev);
+	if (err < 0) {
+		dev_err(dd->dev, "failed to get sync: %d\n", err);
+		return err;
+	}
 
 	if (!test_bit(FLAGS_INIT, &dd->flags)) {
 		set_bit(FLAGS_INIT, &dd->flags);
@@ -1949,7 +1955,13 @@  static int omap_sham_probe(struct platform_device *pdev)
 	dd->flags |= dd->pdata->flags;
 
 	pm_runtime_enable(dev);
-	pm_runtime_get_sync(dev);
+
+	err = pm_runtime_get_sync(dev);
+	if (err < 0) {
+		dev_err(dev, "failed to get sync: %d\n", err);
+		goto err_pm;
+	}
+
 	rev = omap_sham_read(dd, SHA_REG_REV(dd));
 	pm_runtime_put_sync(&pdev->dev);
 
@@ -1979,6 +1991,7 @@  err_algs:
 		for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--)
 			crypto_unregister_ahash(
 					&dd->pdata->algs_info[i].algs_list[j]);
+err_pm:
 	pm_runtime_disable(dev);
 	if (dd->dma_lch)
 		dma_release_channel(dd->dma_lch);
@@ -2021,7 +2034,11 @@  static int omap_sham_suspend(struct device *dev)
 
 static int omap_sham_resume(struct device *dev)
 {
-	pm_runtime_get_sync(dev);
+	int err = pm_runtime_get_sync(dev);
+	if (err < 0) {
+		dev_err(dev, "failed to get sync: %d\n", err);
+		return err;
+	}
 	return 0;
 }
 #endif