[1/3] V4L/DVB: s5p-fimc: add unlock on error path

Message ID 20101021192243.GJ5985@bicker (mailing list archive)
State Superseded, archived
Headers

Commit Message

Dan Carpenter Oct. 21, 2010, 7:22 p.m. UTC
  There was an unlock missing if kzalloc() failed.

Signed-off-by: Dan Carpenter <error27@gmail.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Comments

Sylwester Nawrocki Oct. 22, 2010, 6:57 a.m. UTC | #1
> -----Original Message-----
> From: Dan Carpenter [mailto:error27@gmail.com]
> Sent: Thursday, October 21, 2010 9:23 PM
> To: Mauro Carvalho Chehab
> Cc: Kyungmin Park; Sylwester Nawrocki; Marek Szyprowski; Pawel Osciak;
> linux-media@vger.kernel.org; kernel-janitors@vger.kernel.org
> Subject: [patch 1/3] V4L/DVB: s5p-fimc: add unlock on error path
> 
> There was an unlock missing if kzalloc() failed.
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> 
> diff --git a/drivers/media/video/s5p-fimc/fimc-core.c
> b/drivers/media/video/s5p-fimc/fimc-core.c
> index 1802701..8335045 100644
> --- a/drivers/media/video/s5p-fimc/fimc-core.c
> +++ b/drivers/media/video/s5p-fimc/fimc-core.c
> @@ -1326,16 +1326,18 @@ static int fimc_m2m_open(struct file *file)
>  	 * is already opened.
>  	 */
>  	if (fimc->vid_cap.refcnt > 0) {
> -		mutex_unlock(&fimc->lock);
> -		return -EBUSY;
> +		err = -EBUSY;
> +		goto err_unlock;
>  	}
> 
>  	fimc->m2m.refcnt++;
>  	set_bit(ST_OUTDMA_RUN, &fimc->state);
> 
>  	ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
> -	if (!ctx)
> -		return -ENOMEM;
> +	if (!ctx) {
> +		err = -ENOMEM;
> +		goto err_unlock;
> +	}
> 
>  	file->private_data = ctx;
>  	ctx->fimc_dev = fimc;
> @@ -1355,6 +1357,7 @@ static int fimc_m2m_open(struct file *file)
>  		kfree(ctx);
>  	}
> 
> +err_unlock:
>  	mutex_unlock(&fimc->lock);
>  	return err;
>  }

Indeed it's my omission. Thanks.

Acked-by: Sylwester Nawrocki <s.nawrocki@samsung.com>

--
Sylwester Nawrocki
Linux Platform Group
Samsung Poland R&D Center

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Patch

diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c
index 1802701..8335045 100644
--- a/drivers/media/video/s5p-fimc/fimc-core.c
+++ b/drivers/media/video/s5p-fimc/fimc-core.c
@@ -1326,16 +1326,18 @@  static int fimc_m2m_open(struct file *file)
 	 * is already opened.
 	 */
 	if (fimc->vid_cap.refcnt > 0) {
-		mutex_unlock(&fimc->lock);
-		return -EBUSY;
+		err = -EBUSY;
+		goto err_unlock;
 	}
 
 	fimc->m2m.refcnt++;
 	set_bit(ST_OUTDMA_RUN, &fimc->state);
 
 	ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
-	if (!ctx)
-		return -ENOMEM;
+	if (!ctx) {
+		err = -ENOMEM;
+		goto err_unlock;
+	}
 
 	file->private_data = ctx;
 	ctx->fimc_dev = fimc;
@@ -1355,6 +1357,7 @@  static int fimc_m2m_open(struct file *file)
 		kfree(ctx);
 	}
 
+err_unlock:
 	mutex_unlock(&fimc->lock);
 	return err;
 }