aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorDan Carpenter <error27@gmail.com>2010-06-04 06:38:40 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-06-04 16:38:58 -0400
commit640f7dcfe047aa5859df5f5d41e7f6455a442b89 (patch)
treeabfef4749d8b51e770862d87b6ea7efd14ed5dfe /drivers/staging
parent2d98bb22c33b033182edd3a3c6b4c4e1d091db4d (diff)
Staging: sep: return -EFAULT on copy_to_user errors
copy_to_user() returns the number of bytes remaining but we want to return a negative error code here. These functions are used in the ioctl handler and the error code gets returned to userspace. Signed-off-by: Dan Carpenter <error27@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/sep/sep_driver.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/drivers/staging/sep/sep_driver.c b/drivers/staging/sep/sep_driver.c
index 0332c370fd82..ecbde3467b1b 100644
--- a/drivers/staging/sep/sep_driver.c
+++ b/drivers/staging/sep/sep_driver.c
@@ -594,8 +594,10 @@ static int sep_allocate_data_pool_memory_handler(struct sep_device *sep,
594 dbg("SEP Driver:--------> sep_allocate_data_pool_memory_handler start\n"); 594 dbg("SEP Driver:--------> sep_allocate_data_pool_memory_handler start\n");
595 595
596 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_alloc_t)); 596 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_alloc_t));
597 if (error) 597 if (error) {
598 error = -EFAULT;
598 goto end_function; 599 goto end_function;
600 }
599 601
600 /* allocate memory */ 602 /* allocate memory */
601 if ((sep->data_pool_bytes_allocated + command_args.num_bytes) > SEP_DRIVER_DATA_POOL_SHARED_AREA_SIZE_IN_BYTES) { 603 if ((sep->data_pool_bytes_allocated + command_args.num_bytes) > SEP_DRIVER_DATA_POOL_SHARED_AREA_SIZE_IN_BYTES) {
@@ -609,8 +611,10 @@ static int sep_allocate_data_pool_memory_handler(struct sep_device *sep,
609 611
610 /* write the memory back to the user space */ 612 /* write the memory back to the user space */
611 error = copy_to_user((void *) arg, (void *) &command_args, sizeof(struct sep_driver_alloc_t)); 613 error = copy_to_user((void *) arg, (void *) &command_args, sizeof(struct sep_driver_alloc_t));
612 if (error) 614 if (error) {
615 error = -EFAULT;
613 goto end_function; 616 goto end_function;
617 }
614 618
615 /* set the allocation */ 619 /* set the allocation */
616 sep->data_pool_bytes_allocated += command_args.num_bytes; 620 sep->data_pool_bytes_allocated += command_args.num_bytes;
@@ -661,6 +665,8 @@ static int sep_write_into_data_pool_handler(struct sep_device *sep, unsigned lon
661 } 665 }
662 /* copy the application data */ 666 /* copy the application data */
663 error = copy_from_user(virt_address, (void *) app_in_address, num_bytes); 667 error = copy_from_user(virt_address, (void *) app_in_address, num_bytes);
668 if (error)
669 error = -EFAULT;
664end_function: 670end_function:
665 dbg("SEP Driver:<-------- sep_write_into_data_pool_handler end\n"); 671 dbg("SEP Driver:<-------- sep_write_into_data_pool_handler end\n");
666 return error; 672 return error;
@@ -711,6 +717,8 @@ static int sep_read_from_data_pool_handler(struct sep_device *sep, unsigned long
711 717
712 /* copy the application data */ 718 /* copy the application data */
713 error = copy_to_user((void *) app_out_address, virt_address, num_bytes); 719 error = copy_to_user((void *) app_out_address, virt_address, num_bytes);
720 if (error)
721 error = -EFAULT;
714end_function: 722end_function:
715 dbg("SEP Driver:<-------- sep_read_from_data_pool_handler end\n"); 723 dbg("SEP Driver:<-------- sep_read_from_data_pool_handler end\n");
716 return error; 724 return error;
@@ -1448,8 +1456,10 @@ static int sep_create_sync_dma_tables_handler(struct sep_device *sep,
1448 dbg("SEP Driver:--------> sep_create_sync_dma_tables_handler start\n"); 1456 dbg("SEP Driver:--------> sep_create_sync_dma_tables_handler start\n");
1449 1457
1450 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_build_sync_table_t)); 1458 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_build_sync_table_t));
1451 if (error) 1459 if (error) {
1460 error = -EFAULT;
1452 goto end_function; 1461 goto end_function;
1462 }
1453 1463
1454 edbg("app_in_address is %08lx\n", command_args.app_in_address); 1464 edbg("app_in_address is %08lx\n", command_args.app_in_address);
1455 edbg("app_out_address is %08lx\n", command_args.app_out_address); 1465 edbg("app_out_address is %08lx\n", command_args.app_out_address);
@@ -1799,8 +1809,10 @@ static int sep_create_flow_dma_tables_handler(struct sep_device *sep,
1799 goto end_function; 1809 goto end_function;
1800 1810
1801 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_build_flow_table_t)); 1811 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_build_flow_table_t));
1802 if (error) 1812 if (error) {
1813 error = -EFAULT;
1803 goto end_function; 1814 goto end_function;
1815 }
1804 1816
1805 /* create flow tables */ 1817 /* create flow tables */
1806 error = sep_prepare_flow_dma_tables(sep, command_args.num_virtual_buffers, command_args.virt_buff_data_addr, flow_context_ptr, &first_table_data, &last_table_data, command_args.isKernelVirtualAddress); 1818 error = sep_prepare_flow_dma_tables(sep, command_args.num_virtual_buffers, command_args.virt_buff_data_addr, flow_context_ptr, &first_table_data, &last_table_data, command_args.isKernelVirtualAddress);
@@ -1819,8 +1831,10 @@ static int sep_create_flow_dma_tables_handler(struct sep_device *sep,
1819 1831
1820 /* send the parameters to user application */ 1832 /* send the parameters to user application */
1821 error = copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_build_flow_table_t)); 1833 error = copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_build_flow_table_t));
1822 if (error) 1834 if (error) {
1835 error = -EFAULT;
1823 goto end_function_with_error; 1836 goto end_function_with_error;
1837 }
1824 1838
1825 /* all the flow created - update the flow entry with temp id */ 1839 /* all the flow created - update the flow entry with temp id */
1826 flow_context_ptr->flow_id = SEP_TEMP_FLOW_ID; 1840 flow_context_ptr->flow_id = SEP_TEMP_FLOW_ID;
@@ -1861,8 +1875,10 @@ static int sep_add_flow_tables_handler(struct sep_device *sep, unsigned long arg
1861 1875
1862 /* get input parameters */ 1876 /* get input parameters */
1863 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_add_flow_table_t)); 1877 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_add_flow_table_t));
1864 if (error) 1878 if (error) {
1879 error = -EFAULT;
1865 goto end_function; 1880 goto end_function;
1881 }
1866 1882
1867 /* find the flow structure for the flow id */ 1883 /* find the flow structure for the flow id */
1868 flow_context_ptr = sep_find_flow_context(sep, command_args.flow_id); 1884 flow_context_ptr = sep_find_flow_context(sep, command_args.flow_id);
@@ -1933,6 +1949,8 @@ static int sep_add_flow_tables_handler(struct sep_device *sep, unsigned long arg
1933 1949
1934 /* send the parameters to user application */ 1950 /* send the parameters to user application */
1935 error = copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_add_flow_table_t)); 1951 error = copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_add_flow_table_t));
1952 if (error)
1953 error = -EFAULT;
1936end_function_with_error: 1954end_function_with_error:
1937 /* free the allocated tables */ 1955 /* free the allocated tables */
1938 sep_deallocated_flow_tables(&first_table_data); 1956 sep_deallocated_flow_tables(&first_table_data);
@@ -1953,8 +1971,10 @@ static int sep_add_flow_tables_message_handler(struct sep_device *sep, unsigned
1953 dbg("SEP Driver:--------> sep_add_flow_tables_message_handler start\n"); 1971 dbg("SEP Driver:--------> sep_add_flow_tables_message_handler start\n");
1954 1972
1955 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_add_message_t)); 1973 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_add_message_t));
1956 if (error) 1974 if (error) {
1975 error = -EFAULT;
1957 goto end_function; 1976 goto end_function;
1977 }
1958 1978
1959 /* check input */ 1979 /* check input */
1960 if (command_args.message_size_in_bytes > SEP_MAX_ADD_MESSAGE_LENGTH_IN_BYTES) { 1980 if (command_args.message_size_in_bytes > SEP_MAX_ADD_MESSAGE_LENGTH_IN_BYTES) {
@@ -1970,6 +1990,8 @@ static int sep_add_flow_tables_message_handler(struct sep_device *sep, unsigned
1970 /* copy the message into context */ 1990 /* copy the message into context */
1971 flow_context_ptr->message_size_in_bytes = command_args.message_size_in_bytes; 1991 flow_context_ptr->message_size_in_bytes = command_args.message_size_in_bytes;
1972 error = copy_from_user(flow_context_ptr->message, (void *) command_args.message_address, command_args.message_size_in_bytes); 1992 error = copy_from_user(flow_context_ptr->message, (void *) command_args.message_address, command_args.message_size_in_bytes);
1993 if (error)
1994 error = -EFAULT;
1973end_function: 1995end_function:
1974 dbg("SEP Driver:<-------- sep_add_flow_tables_message_handler end\n"); 1996 dbg("SEP Driver:<-------- sep_add_flow_tables_message_handler end\n");
1975 return error; 1997 return error;
@@ -1994,6 +2016,8 @@ static int sep_get_static_pool_addr_handler(struct sep_device *sep, unsigned lon
1994 2016
1995 /* send the parameters to user application */ 2017 /* send the parameters to user application */
1996 error = copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_static_pool_addr_t)); 2018 error = copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_static_pool_addr_t));
2019 if (error)
2020 error = -EFAULT;
1997 dbg("SEP Driver:<-------- sep_get_static_pool_addr_handler end\n"); 2021 dbg("SEP Driver:<-------- sep_get_static_pool_addr_handler end\n");
1998 return error; 2022 return error;
1999} 2023}
@@ -2010,8 +2034,10 @@ static int sep_get_physical_mapped_offset_handler(struct sep_device *sep, unsign
2010 dbg("SEP Driver:--------> sep_get_physical_mapped_offset_handler start\n"); 2034 dbg("SEP Driver:--------> sep_get_physical_mapped_offset_handler start\n");
2011 2035
2012 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_get_mapped_offset_t)); 2036 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_get_mapped_offset_t));
2013 if (error) 2037 if (error) {
2038 error = -EFAULT;
2014 goto end_function; 2039 goto end_function;
2040 }
2015 2041
2016 if (command_args.physical_address < sep->shared_bus) { 2042 if (command_args.physical_address < sep->shared_bus) {
2017 error = -EINVAL; 2043 error = -EINVAL;
@@ -2025,6 +2051,8 @@ static int sep_get_physical_mapped_offset_handler(struct sep_device *sep, unsign
2025 2051
2026 /* send the parameters to user application */ 2052 /* send the parameters to user application */
2027 error = copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_get_mapped_offset_t)); 2053 error = copy_to_user((void *) arg, &command_args, sizeof(struct sep_driver_get_mapped_offset_t));
2054 if (error)
2055 error = -EFAULT;
2028end_function: 2056end_function:
2029 dbg("SEP Driver:<-------- sep_get_physical_mapped_offset_handler end\n"); 2057 dbg("SEP Driver:<-------- sep_get_physical_mapped_offset_handler end\n");
2030 return error; 2058 return error;
@@ -2070,11 +2098,11 @@ static int sep_init_handler(struct sep_device *sep, unsigned long arg)
2070 error = 0; 2098 error = 0;
2071 2099
2072 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_init_t)); 2100 error = copy_from_user(&command_args, (void *) arg, sizeof(struct sep_driver_init_t));
2073 2101 if (error) {
2074 dbg("SEP Driver:--------> sep_init_handler - finished copy_from_user \n"); 2102 error = -EFAULT;
2075
2076 if (error)
2077 goto end_function; 2103 goto end_function;
2104 }
2105 dbg("SEP Driver:--------> sep_init_handler - finished copy_from_user\n");
2078 2106
2079 /* PATCH - configure the DMA to single -burst instead of multi-burst */ 2107 /* PATCH - configure the DMA to single -burst instead of multi-burst */
2080 /*sep_configure_dma_burst(); */ 2108 /*sep_configure_dma_burst(); */