Re: [PATCH 2/3] staging: hv: check return values from alloc calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 03, 2010 at 05:50:44PM -0400, Bill Pemberton wrote:
> The return from k*alloc() should be checked and action taking for when
> the allocation fails.  In many places hv did this with an ASSERT()
> call or didn't check the value at all.
> 
> Signed-off-by: Bill Pemberton <wfp5p@xxxxxxxxxxxx>
> ---
>  drivers/staging/hv/Channel.c     |   50 ++++++++++++++++++++++++++++----------
>  drivers/staging/hv/ChannelMgmt.c |    6 ++++-
>  drivers/staging/hv/Connection.c  |    4 +++
>  3 files changed, 46 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
> index 328d3a0..94e5214 100644
> --- a/drivers/staging/hv/Channel.c
> +++ b/drivers/staging/hv/Channel.c
> @@ -181,6 +181,13 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
>  
>  	DPRINT_ENTER(VMBUS);
>  
> +	/* Create and init the channel open message */
> +	openInfo = kmalloc(sizeof(*openInfo) +
> +			   sizeof(struct vmbus_channel_open_channel),
> +			   GFP_KERNEL);
> +	if (!openInfo)
> +		return -ENOMEM;
> +
>  	/* Aligned to page size */
>  	ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1)));
>  	ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1)));
> @@ -226,12 +233,6 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
>  		   NewChannel->Inbound.RingSize,
>  		   SendRingBufferSize);
>  
> -	/* Create and init the channel open message */
> -	openInfo = kmalloc(sizeof(*openInfo) +
> -			   sizeof(struct vmbus_channel_open_channel),
> -			   GFP_KERNEL);
> -	ASSERT(openInfo != NULL);
> -

Why did you move this allocation up so high in the function?  You need
to then free it if the osd_PageAlloc() call fails, right?

Care to fix this up?

The other parts of the file look fine, but I would like to get Hank's
ack before applying it.  Care to respin it with this fix so he can test
it out?

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux