[3/6] pvrusb2: check for allocation failures

Message ID 20110326015221.GH2008@bicker (mailing list archive)
State Superseded, archived
Headers

Commit Message

Dan Carpenter March 26, 2011, 1:52 a.m. UTC
  This function returns NULL on failure so lets do that if kzalloc()
fails.  There is a separate problem that the caller for this function
doesn't check for errors...

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

Mike Isely March 26, 2011, 4:33 a.m. UTC | #1
Acked-By: Mike Isely <isely@pobox.com>

On Sat, 26 Mar 2011, Dan Carpenter wrote:

> This function returns NULL on failure so lets do that if kzalloc()
> fails.  There is a separate problem that the caller for this function
> doesn't check for errors...
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> 
> diff --git a/drivers/media/video/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
> index 370a9ab..b214f77 100644
> --- a/drivers/media/video/pvrusb2/pvrusb2-std.c
> +++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
> @@ -388,6 +388,9 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
>  
>  	stddefs = kzalloc(sizeof(struct v4l2_standard) * std_cnt,
>  			  GFP_KERNEL);
> +	if (!stddefs)
> +		return NULL;
> +
>  	for (idx = 0; idx < std_cnt; idx++)
>  		stddefs[idx].index = idx;
>  
>
  
Dan Carpenter March 26, 2011, 6:48 a.m. UTC | #2
On Fri, Mar 25, 2011 at 11:33:36PM -0500, Mike Isely wrote:
> 
> Acked-By: Mike Isely <isely@pobox.com>
> 

I'd need to reformat this one to get it to apply... :/  It doesn't
actually fix the bug so it's not worth it.

regards,
dan carpenter
--
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
  
Mike Isely March 26, 2011, 6:07 p.m. UTC | #3
I'll look at the surrounding code and see what makes sense there. Having 
an error leg for allocation failures is a useful thing.

-Mike


Dan Carpenter wrote:
> On Fri, Mar 25, 2011 at 11:33:36PM -0500, Mike Isely wrote:
>   
>> Acked-By: Mike Isely <isely@pobox.com>
>>
>>     
>
> I'd need to reformat this one to get it to apply... :/  It doesn't
> actually fix the bug so it's not worth it.
>
> regards,
> dan carpenter
> --
> 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/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
index 370a9ab..b214f77 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
@@ -388,6 +388,9 @@  struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
 
 	stddefs = kzalloc(sizeof(struct v4l2_standard) * std_cnt,
 			  GFP_KERNEL);
+	if (!stddefs)
+		return NULL;
+
 	for (idx = 0; idx < std_cnt; idx++)
 		stddefs[idx].index = idx;