Staging: bcm: Alter return value for copy_to/from_user() to "return -EFAULT" when an error occurs.

In this clean up patch, I altered functions: copy_to/
from_user() to return -EFAULT when an error occurs.
I also replaced break statements when an error occurs
from copy_to/from_user() with direct returns of -EFAULT.

Signed-off-by: Kevin McKinney <klmckinney1@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Kevin McKinney 2011-12-05 22:17:03 -05:00 committed by Greg Kroah-Hartman
parent 6561f91d68
commit d3a21c3c4b

View file

@ -235,8 +235,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
(PUINT)temp_buff, Bufflen); (PUINT)temp_buff, Bufflen);
if (bytes > 0) { if (bytes > 0) {
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
Status = -EFAULT; kfree(temp_buff);
return -EFAULT;
}
} else { } else {
Status = bytes; Status = bytes;
} }
@ -330,8 +332,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
if (bytes > 0) { if (bytes > 0) {
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
Status = -EFAULT; kfree(temp_buff);
return -EFAULT;
}
} else { } else {
Status = bytes; Status = bytes;
} }
@ -625,7 +629,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Failed while copying Content to IOBufer for user space err:%d", Status); "Failed while copying Content to IOBufer for user space err:%d", Status);
break; return -EFAULT;
} }
} }
break; break;
@ -701,7 +705,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Failed while copying Content to IOBufer for user space err:%d", Status); "Failed while copying Content to IOBufer for user space err:%d", Status);
break; return -EFAULT;
} }
} }
break; break;
@ -729,9 +733,8 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
return -ENOMEM; return -ENOMEM;
if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) { if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
Status = -EFAULT;
kfree(pvBuffer); kfree(pvBuffer);
break; return -EFAULT;
} }
down(&Adapter->LowPowerModeSync); down(&Adapter->LowPowerModeSync);
@ -1012,8 +1015,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
/* Copy Ioctl Buffer structure */ /* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) { if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
Status = -EFAULT; return -EFAULT;
break;
} }
if (IoBuffer.OutputLength != sizeof(link_state)) { if (IoBuffer.OutputLength != sizeof(link_state)) {
@ -1028,8 +1030,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t, sizeof(link_state), IoBuffer.OutputLength))) { if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t, sizeof(link_state), IoBuffer.OutputLength))) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
Status = -EFAULT; return -EFAULT;
break;
} }
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
break; break;
@ -1095,8 +1096,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
GetDroppedAppCntrlPktMibs(temp_buff, pTarang); GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
if (Status != STATUS_FAILURE) if (Status != STATUS_FAILURE)
if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(S_MIBS_HOST_STATS_MIBS))) if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(S_MIBS_HOST_STATS_MIBS))) {
Status = -EFAULT; kfree(temp_buff);
return -EFAULT;
}
kfree(temp_buff); kfree(temp_buff);
break; break;
@ -1138,8 +1141,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
/* Get WrmBuffer structure */ /* Get WrmBuffer structure */
if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) { if (copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
kfree(pvBuffer); kfree(pvBuffer);
Status = -EFAULT; return -EFAULT;
break;
} }
pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer; pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
@ -1479,7 +1481,9 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes); Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy to use failed with status :%d", Status); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy to use failed with status :%d", Status);
break; up(&Adapter->NVMRdmWrmLock);
kfree(pReadBuff);
return -EFAULT;
} }
NOB = NOB - ReadBytes; NOB = NOB - ReadBytes;
if (NOB) { if (NOB) {
@ -1571,7 +1575,9 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes); Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes);
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to user failed with status :%d", Status); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to user failed with status :%d", Status);
break; up(&Adapter->NVMRdmWrmLock);
kfree(pWriteBuff);
return -EFAULT;
} }
BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes); BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes);
@ -1631,8 +1637,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap); BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
up(&Adapter->NVMRdmWrmLock); up(&Adapter->NVMRdmWrmLock);
if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP))) if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP))) {
Status = -EFAULT; kfree(psFlash2xBitMap);
return -EFAULT;
}
kfree(psFlash2xBitMap); kfree(psFlash2xBitMap);
} }
@ -1650,13 +1658,13 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
return Status; return -EFAULT;
} }
Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT)); Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
return Status; return -EFAULT;
} }
down(&Adapter->NVMRdmWrmLock); down(&Adapter->NVMRdmWrmLock);
@ -1700,13 +1708,13 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
return Status; return -EFAULT;
} }
Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION)); Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
return Status; return -EFAULT;
} }
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
@ -1767,7 +1775,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
break; return -EFAULT;
} }
if (Adapter->eNVMType != NVM_FLASH) { if (Adapter->eNVMType != NVM_FLASH) {
@ -1806,12 +1814,12 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
return Status; return -EFAULT;
} }
Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT)); Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
return Status; return -EFAULT;
} }
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read Section :%d", eFlash2xSectionVal); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read Section :%d", eFlash2xSectionVal);
@ -1853,8 +1861,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
/* Copy Ioctl Buffer structure */ /* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) { if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
Status = -EFAULT; return -EFAULT;
break;
} }
if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer, sizeof(NVM_READWRITE))) if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer, sizeof(NVM_READWRITE)))
@ -1909,7 +1916,9 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes); Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to use failed with status :%d", Status); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to use failed with status :%d", Status);
break; up(&Adapter->NVMRdmWrmLock);
kfree(pReadBuff);
return -EFAULT;
} }
NOB = NOB - ReadBytes; NOB = NOB - ReadBytes;
if (NOB) { if (NOB) {
@ -1930,8 +1939,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of Ioctl buffer is failed from user space"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of Ioctl buffer is failed from user space");
Status = -EFAULT; return -EFAULT;
break;
} }
if (IoBuffer.InputLength != sizeof(unsigned long)) { if (IoBuffer.InputLength != sizeof(unsigned long)) {
@ -1942,8 +1950,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength); Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
if (Status) { if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of control bit mask failed from user space"); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of control bit mask failed from user space");
Status = -EFAULT; return -EFAULT;
break;
} }
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask); BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask; pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask;