From 9c434f8e23c29c8cd2ff88048ca6508e9d3ed360 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 13 Feb 2014 14:46:32 -0500 Subject: [PATCH] staging/bcm: move IOCTL_BCM_GET_CURRENT_STATUS case out to its own function. bcm_char_ioctl is one of the longest non-generated functions in the kernel, at 1906 lines. Splitting it up into multiple functions should simplify this a lot. Signed-off-by: Dave Jones Signed-off-by: Greg Kroah-Hartman --- drivers/staging/bcm/Bcmchar.c | 55 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c index 17d2a3f..da84435 100644 --- a/drivers/staging/bcm/Bcmchar.c +++ b/drivers/staging/bcm/Bcmchar.c @@ -1030,6 +1030,32 @@ static int bcm_char_ioctl_get_driver_version(void __user *argp) return STATUS_SUCCESS; } +static int bcm_char_ioctl_get_current_status(void __user *argp, struct bcm_mini_adapter *Adapter) +{ + struct bcm_link_state link_state; + struct bcm_ioctl_buffer IoBuffer; + + /* Copy Ioctl Buffer structure */ + if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) { + BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n"); + return -EFAULT; + } + + if (IoBuffer.OutputLength != sizeof(link_state)) + return -EINVAL; + + memset(&link_state, 0, sizeof(link_state)); + link_state.bIdleMode = Adapter->IdleMode; + link_state.bShutdownMode = Adapter->bShutStatus; + link_state.ucLinkStatus = Adapter->LinkStatus; + + 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"); + return -EFAULT; + } + return STATUS_SUCCESS; +} + static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg) { @@ -1180,32 +1206,9 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg) Status = bcm_char_ioctl_get_driver_version(argp); return Status; - case IOCTL_BCM_GET_CURRENT_STATUS: { - struct bcm_link_state link_state; - - /* Copy Ioctl Buffer structure */ - if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) { - BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n"); - return -EFAULT; - } - - if (IoBuffer.OutputLength != sizeof(link_state)) { - Status = -EINVAL; - break; - } - - memset(&link_state, 0, sizeof(link_state)); - link_state.bIdleMode = Adapter->IdleMode; - link_state.bShutdownMode = Adapter->bShutStatus; - link_state.ucLinkStatus = Adapter->LinkStatus; - - 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"); - return -EFAULT; - } - Status = STATUS_SUCCESS; - break; - } + case IOCTL_BCM_GET_CURRENT_STATUS: + Status = bcm_char_ioctl_get_current_status(argp, Adapter); + return Status; case IOCTL_BCM_SET_MAC_TRACING: { UINT tracing_flag; -- 2.7.4