Staging: winbond: Check for unsuccessful allocation immediately
Check to see if allocation by kzalloc() or usb_alloc_urb() was unsuccessful immediately after the allocation. Exit from the function can be right at that point in case of allocation failure. This avoids unnecessary use of usb_alloc_urb() & usb_free_urb() if kzalloc() returns NULL. Also, makes the code better structured & easier to understand. Signed-off-by: Harsh Kumar <harsh1kumar@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
bf1ace2a3f
commit
d3d472b6e5
1 changed files with 136 additions and 129 deletions
|
@ -30,8 +30,15 @@ unsigned char Wb35Reg_BurstWrite(struct hw_data *pHwData, u16 RegisterNo, u32 *p
|
||||||
/* Trying to use burst write function if use new hardware */
|
/* Trying to use burst write function if use new hardware */
|
||||||
UrbSize = sizeof(struct wb35_reg_queue) + DataSize + sizeof(struct usb_ctrlrequest);
|
UrbSize = sizeof(struct wb35_reg_queue) + DataSize + sizeof(struct usb_ctrlrequest);
|
||||||
reg_queue = kzalloc(UrbSize, GFP_ATOMIC);
|
reg_queue = kzalloc(UrbSize, GFP_ATOMIC);
|
||||||
|
if (reg_queue == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
||||||
if (urb && reg_queue) {
|
if (urb == NULL) {
|
||||||
|
kfree(reg_queue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
reg_queue->DIRECT = 2; /* burst write register */
|
reg_queue->DIRECT = 2; /* burst write register */
|
||||||
reg_queue->INDEX = RegisterNo;
|
reg_queue->INDEX = RegisterNo;
|
||||||
reg_queue->pBuffer = (u32 *)((u8 *)reg_queue + sizeof(struct wb35_reg_queue));
|
reg_queue->pBuffer = (u32 *)((u8 *)reg_queue + sizeof(struct wb35_reg_queue));
|
||||||
|
@ -63,12 +70,6 @@ unsigned char Wb35Reg_BurstWrite(struct hw_data *pHwData, u16 RegisterNo, u32 *p
|
||||||
Wb35Reg_EP0VM_start(pHwData);
|
Wb35Reg_EP0VM_start(pHwData);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
usb_free_urb(urb);
|
|
||||||
kfree(reg_queue);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wb35Reg_Update(struct hw_data *pHwData, u16 RegisterNo, u32 RegisterValue)
|
void Wb35Reg_Update(struct hw_data *pHwData, u16 RegisterNo, u32 RegisterValue)
|
||||||
|
@ -173,8 +174,15 @@ unsigned char Wb35Reg_Write(struct hw_data *pHwData, u16 RegisterNo, u32 Registe
|
||||||
/* update the register by send urb request */
|
/* update the register by send urb request */
|
||||||
UrbSize = sizeof(struct wb35_reg_queue) + sizeof(struct usb_ctrlrequest);
|
UrbSize = sizeof(struct wb35_reg_queue) + sizeof(struct usb_ctrlrequest);
|
||||||
reg_queue = kzalloc(UrbSize, GFP_ATOMIC);
|
reg_queue = kzalloc(UrbSize, GFP_ATOMIC);
|
||||||
|
if (reg_queue == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
||||||
if (urb && reg_queue) {
|
if (urb == NULL) {
|
||||||
|
kfree(reg_queue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
reg_queue->DIRECT = 1; /* burst write register */
|
reg_queue->DIRECT = 1; /* burst write register */
|
||||||
reg_queue->INDEX = RegisterNo;
|
reg_queue->INDEX = RegisterNo;
|
||||||
reg_queue->VALUE = cpu_to_le32(RegisterValue);
|
reg_queue->VALUE = cpu_to_le32(RegisterValue);
|
||||||
|
@ -204,11 +212,6 @@ unsigned char Wb35Reg_Write(struct hw_data *pHwData, u16 RegisterNo, u32 Registe
|
||||||
Wb35Reg_EP0VM_start(pHwData);
|
Wb35Reg_EP0VM_start(pHwData);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
usb_free_urb(urb);
|
|
||||||
kfree(reg_queue);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -236,8 +239,15 @@ unsigned char Wb35Reg_WriteWithCallbackValue(struct hw_data *pHwData,
|
||||||
/* update the register by send urb request */
|
/* update the register by send urb request */
|
||||||
UrbSize = sizeof(struct wb35_reg_queue) + sizeof(struct usb_ctrlrequest);
|
UrbSize = sizeof(struct wb35_reg_queue) + sizeof(struct usb_ctrlrequest);
|
||||||
reg_queue = kzalloc(UrbSize, GFP_ATOMIC);
|
reg_queue = kzalloc(UrbSize, GFP_ATOMIC);
|
||||||
|
if (reg_queue == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
||||||
if (urb && reg_queue) {
|
if (urb == NULL) {
|
||||||
|
kfree(reg_queue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
reg_queue->DIRECT = 1; /* burst write register */
|
reg_queue->DIRECT = 1; /* burst write register */
|
||||||
reg_queue->INDEX = RegisterNo;
|
reg_queue->INDEX = RegisterNo;
|
||||||
reg_queue->VALUE = cpu_to_le32(RegisterValue);
|
reg_queue->VALUE = cpu_to_le32(RegisterValue);
|
||||||
|
@ -266,12 +276,8 @@ unsigned char Wb35Reg_WriteWithCallbackValue(struct hw_data *pHwData,
|
||||||
|
|
||||||
/* Start EP0VM */
|
/* Start EP0VM */
|
||||||
Wb35Reg_EP0VM_start(pHwData);
|
Wb35Reg_EP0VM_start(pHwData);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
usb_free_urb(urb);
|
|
||||||
kfree(reg_queue);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -341,8 +347,14 @@ unsigned char Wb35Reg_Read(struct hw_data *pHwData, u16 RegisterNo, u32 *pRegist
|
||||||
/* update the variable by send Urb to read register */
|
/* update the variable by send Urb to read register */
|
||||||
UrbSize = sizeof(struct wb35_reg_queue) + sizeof(struct usb_ctrlrequest);
|
UrbSize = sizeof(struct wb35_reg_queue) + sizeof(struct usb_ctrlrequest);
|
||||||
reg_queue = kzalloc(UrbSize, GFP_ATOMIC);
|
reg_queue = kzalloc(UrbSize, GFP_ATOMIC);
|
||||||
|
if (reg_queue == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
urb = usb_alloc_urb(0, GFP_ATOMIC);
|
||||||
if (urb && reg_queue) {
|
if (urb == NULL) {
|
||||||
|
kfree(reg_queue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
reg_queue->DIRECT = 0; /* read register */
|
reg_queue->DIRECT = 0; /* read register */
|
||||||
reg_queue->INDEX = RegisterNo;
|
reg_queue->INDEX = RegisterNo;
|
||||||
reg_queue->pBuffer = pRegisterValue;
|
reg_queue->pBuffer = pRegisterValue;
|
||||||
|
@ -370,11 +382,6 @@ unsigned char Wb35Reg_Read(struct hw_data *pHwData, u16 RegisterNo, u32 *pRegist
|
||||||
Wb35Reg_EP0VM_start(pHwData);
|
Wb35Reg_EP0VM_start(pHwData);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
usb_free_urb(urb);
|
|
||||||
kfree(reg_queue);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue