From 91b613f8985c607cecc834c7c9f56b8dcde197ca Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Sun, 14 Jul 2013 17:01:03 +0400 Subject: [PATCH] [STYLE] Code-style fix --- buffer/swap_buffer_module.c | 3 + driver_new/device_driver.c | 7 - driver_new/device_driver.h | 24 +++ driver_new/driver_to_buffer.c | 354 +++++++++++++++++++++------------------- driver_new/driver_to_buffer.h | 24 +++ driver_new/swap_driver_module.c | 30 +++- driver_new/swap_ioctl.h | 26 ++- sampler/kernel_operations.h | 30 ++++ sampler/swap_sampler_module.c | 25 +++ 9 files changed, 346 insertions(+), 177 deletions(-) diff --git a/buffer/swap_buffer_module.c b/buffer/swap_buffer_module.c index 3e72af4..ec474e0 100644 --- a/buffer/swap_buffer_module.c +++ b/buffer/swap_buffer_module.c @@ -268,3 +268,6 @@ static void __exit swap_buffer_module_exit(void) module_init(swap_buffer_module_init); module_exit(swap_buffer_module_exit); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("SWAP buffer module"); +MODULE_AUTHOR("Aksenov A.S."); diff --git a/driver_new/device_driver.c b/driver_new/device_driver.c index 188919a..de3007a 100644 --- a/driver_new/device_driver.c +++ b/driver_new/device_driver.c @@ -124,8 +124,6 @@ int swap_device_init(void) goto init_fail; } - print_debug("Device with major num %d allocated\n", MAJOR(swap_device_no)); - /* Creating device class. Using IS_ERR, because class_create returns ERR_PTR * on error. */ swap_device_class = class_create(THIS_MODULE, SWAP_DEVICE_NAME); @@ -203,7 +201,6 @@ void swap_device_exit(void) cdev_del(swap_device_cdev); class_destroy(swap_device_class); unregister_chrdev_region(swap_device_no, 1); - print_debug("Device unregistered\n"); } static int swap_device_open(struct inode *inode, struct file *filp) @@ -303,7 +300,6 @@ static long swap_device_ioctl(struct file *filp, unsigned int cmd, switch(cmd) { case SWAP_DRIVER_BUFFER_INITIALIZE: { - print_debug("SWAP_DRIVER_BUFFER_INITIALIZE\n"); struct buffer_initialize initialize_struct; result = copy_from_user(&initialize_struct, (void*)arg, @@ -324,7 +320,6 @@ static long swap_device_ioctl(struct file *filp, unsigned int cmd, } case SWAP_DRIVER_BUFFER_UNINITIALIZE: { - print_debug("SWAP_DRIVER_BUFFER_UNINITIALIZE\n"); result = driver_to_buffer_uninitialize(); if (result < 0) print_err("Buffer uninitialization failed %d\n", result); @@ -333,7 +328,6 @@ static long swap_device_ioctl(struct file *filp, unsigned int cmd, } case SWAP_DRIVER_NEXT_BUFFER_TO_READ: { - print_debug("SWAP_DRIVER_NEXT_BUFFER_TO_READ\n"); /* Use this carefully */ result = driver_to_buffer_next_buffer_to_read(); if (result == E_SD_NO_DATA_TO_READ) { @@ -344,7 +338,6 @@ static long swap_device_ioctl(struct file *filp, unsigned int cmd, } case SWAP_DRIVER_FLUSH_BUFFER: { - print_debug("SWAP_DRIVER_FLUSH_BUFFER\n"); result = driver_to_buffer_flush(); break; } diff --git a/driver_new/device_driver.h b/driver_new/device_driver.h index d809e1b..09a254d 100644 --- a/driver_new/device_driver.h +++ b/driver_new/device_driver.h @@ -1,3 +1,27 @@ +/* + * SWAP driver + * modules/driver_new/device_driver.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2013 + * + * 2013 Alexander Aksenov : SWAP device driver implement + * + */ + #ifndef __SWAP_DRIVER_DEVICE_DRIVER_H__ #define __SWAP_DRIVER_DEVICE_DRIVER_H__ diff --git a/driver_new/driver_to_buffer.c b/driver_new/driver_to_buffer.c index 7ae7e42..bc4b5ed 100644 --- a/driver_new/driver_to_buffer.c +++ b/driver_new/driver_to_buffer.c @@ -1,3 +1,27 @@ +/* + * SWAP driver + * modules/driver_new/driver_to_buffer.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2013 + * + * 2013 Alexander Aksenov : SWAP device driver implement + * + */ + #include #include #include @@ -25,129 +49,127 @@ static int pages_per_buffer = 0; /* TODO Get subbuffer for reading */ static size_t driver_to_buffer_get(void) { - int result; - - /* If there is no readable buffers, return error */ - result = swap_buffer_get(&busy_buffer); - if (result == -E_SB_NO_READABLE_BUFFERS) { - busy_buffer = NULL; - return -E_SD_NO_DATA_TO_READ; - } else if (result < 0) { - print_err("swap_buffer_get unhandle error %d\n", result); - return -E_SD_BUFFER_ERROR; - } - - return busy_buffer->full_buffer_part; + int result; + + /* If there is no readable buffers, return error */ + result = swap_buffer_get(&busy_buffer); + if (result == -E_SB_NO_READABLE_BUFFERS) { + busy_buffer = NULL; + return -E_SD_NO_DATA_TO_READ; + } else if (result < 0) { + print_err("swap_buffer_get unhandle error %d\n", result); + return -E_SD_BUFFER_ERROR; + } + + return busy_buffer->full_buffer_part; } /* TODO Release subbuffer */ static int driver_to_buffer_release(void) { - int result; + int result; - if (!busy_buffer) - return -E_SD_NO_BUSY_SUBBUFFER; + if (!busy_buffer) + return -E_SD_NO_BUSY_SUBBUFFER; - result = swap_buffer_release(&busy_buffer); - if (result == -E_SB_NO_SUBBUFFER_IN_BUSY) { - return -E_SD_WRONG_SUBBUFFER_PTR; - } else if (result < 0) { - print_err("swap_buffer_release unhandle error %d\n", result); - return -E_SD_BUFFER_ERROR; - } + result = swap_buffer_release(&busy_buffer); + if (result == -E_SB_NO_SUBBUFFER_IN_BUSY) { + return -E_SD_WRONG_SUBBUFFER_PTR; + } else if (result < 0) { + print_err("swap_buffer_release unhandle error %d\n", result); + return -E_SD_BUFFER_ERROR; + } - busy_buffer = NULL; + busy_buffer = NULL; - return E_SD_SUCCESS; + return E_SD_SUCCESS; } /* Buffers callback function */ int driver_to_buffer_callback(void) { //XXX: Think of sync with get next - int result; + int result; - /* Increment buffers_to_read counter */ - buffers_to_read++; - swap_device_wake_up_process(); + /* Increment buffers_to_read counter */ + buffers_to_read++; + swap_device_wake_up_process(); - return E_SD_SUCCESS; + return E_SD_SUCCESS; } /* Write to buffers */ ssize_t driver_to_buffer_write(size_t size, void* data) { - ssize_t result; - - result = us_msg(data); -// result = swap_buffer_write(data, size); - if (result == -E_SB_IS_STOPPED) { - print_err("Buffer is not run! Initialize it before writing\n"); - return -E_SD_WRITE_ERROR; - } else if (result < 0) { - print_err("swap_buffer_write error %d\n", result); - return -E_SD_WRITE_ERROR; - } - print_debug("swap_buffer writed %d\n", result); - - return result; + ssize_t result; + + result = us_msg(data); + if (result == -E_SB_IS_STOPPED) { + print_err("Buffer is not run! Initialize it before writing\n"); + return -E_SD_WRITE_ERROR; + } else if (result < 0) { + print_err("swap_buffer_write error %d\n", result); + return -E_SD_WRITE_ERROR; + } + + return result; } /* Read buffers */ ssize_t driver_to_buffer_read(char __user *buf, size_t count) { - size_t bytes_to_copy; - size_t bytes_to_read = 0; - int page_counter = 0; - - /* Reading from swap_device means reading only current busy_buffer. So, if - * there is no busy_buffer, we don't get next to read, we just read nothing. - * In this case, or if there is nothing to read from busy_buffer - return - * -E_SD_NO_DATA_TO_READ. It should be correctly handled in device_driver */ - if (!busy_buffer || !busy_buffer->full_buffer_part) - return -E_SD_NO_DATA_TO_READ; - - /* Bytes count that we're going to copy to user buffer is equal to user - * buffer size or to subbuffer readable size whichever is less */ - bytes_to_copy = (count > busy_buffer->full_buffer_part) ? - busy_buffer->full_buffer_part : count; - - /* Copy data from each page to buffer */ - while(bytes_to_copy > 0) { - /* Get size that should be copied from current page */ - size_t read_from_this_page = (bytes_to_copy > PAGE_SIZE) ? PAGE_SIZE - : bytes_to_copy; - - /* Copy and add size to copied bytes count */ - - // TODO Check with more than one page - bytes_to_read += read_from_this_page - - copy_to_user(buf, page_address(busy_buffer->data_buffer) + - (sizeof(struct page*) * - page_counter), - read_from_this_page); - bytes_to_copy -= read_from_this_page; - page_counter++; - } - - return bytes_to_read; + size_t bytes_to_copy; + size_t bytes_to_read = 0; + int page_counter = 0; + + /* Reading from swap_device means reading only current busy_buffer. So, if + * there is no busy_buffer, we don't get next to read, we just read nothing. + * In this case, or if there is nothing to read from busy_buffer - return + * -E_SD_NO_DATA_TO_READ. It should be correctly handled in device_driver */ + if (!busy_buffer || !busy_buffer->full_buffer_part) + return -E_SD_NO_DATA_TO_READ; + + /* Bytes count that we're going to copy to user buffer is equal to user + * buffer size or to subbuffer readable size whichever is less */ + bytes_to_copy = (count > busy_buffer->full_buffer_part) ? + busy_buffer->full_buffer_part : count; + + /* Copy data from each page to buffer */ + while(bytes_to_copy > 0) { + /* Get size that should be copied from current page */ + size_t read_from_this_page = (bytes_to_copy > PAGE_SIZE) ? PAGE_SIZE + : bytes_to_copy; + + /* Copy and add size to copied bytes count */ + + // TODO Check with more than one page + bytes_to_read += read_from_this_page - + copy_to_user(buf, page_address(busy_buffer->data_buffer) + + (sizeof(struct page*) * + page_counter), + read_from_this_page); + bytes_to_copy -= read_from_this_page; + page_counter++; + } + + return bytes_to_read; } /* Flush swap_buffer */ int driver_to_buffer_flush(void) { - int result; + int result; - result = swap_buffer_flush(); + result = swap_buffer_flush(); - if (result >= 0) - buffers_to_read = result; - else if (result < 0) - return -E_SD_BUFFER_ERROR; + if (result >= 0) + buffers_to_read = result; + else if (result < 0) + return -E_SD_BUFFER_ERROR; - swap_device_wake_up_process(); + swap_device_wake_up_process(); - return E_SD_SUCCESS; + return E_SD_SUCCESS; } /* Fills spd structure */ @@ -168,8 +190,8 @@ int driver_to_buffer_fill_spd(struct splice_pipe_desc *spd) /* FIXME: maybe there is more efficient way */ memcpy(page_address(pages[spd->nr_pages]), - page_address(&busy_buffer->data_buffer[spd->nr_pages]), - read_from_current_page); + page_address(&busy_buffer->data_buffer[spd->nr_pages]), + read_from_current_page); /* Always beginning of the page */ partial[spd->nr_pages].offset = 0; @@ -185,103 +207,103 @@ int driver_to_buffer_fill_spd(struct splice_pipe_desc *spd) /* if (spd->nr_pages == pipe->buffers) { */ /* break; */ /* } */ - } - return 0; + } + return 0; } /* Check for subbuffers ready to be read */ int driver_to_buffer_buffer_to_read(void) { - return busy_buffer ? 1 : 0; + return busy_buffer ? 1 : 0; } /* Set buffers size and count */ int driver_to_buffer_initialize(size_t size, unsigned int count) { - int result; - - if (size == 0 && count == 0) { - return -E_SD_WRONG_ARGS; - } - - result = swap_buffer_init(size, count, (void*)&driver_to_buffer_callback); - if (result == -E_SB_NO_MEM_QUEUE_BUSY - || result == -E_SB_NO_MEM_BUFFER_STRUCT) { - return -E_SD_NO_MEMORY; - } - - // TODO Race condition: buffer can be used in other thread till we're in - // this func - /* Initialize driver_to_buffer variables */ - pages_per_buffer = result; - busy_buffer = NULL; - buffers_to_read = 0; - - return E_SD_SUCCESS; + int result; + + if (size == 0 && count == 0) { + return -E_SD_WRONG_ARGS; + } + + result = swap_buffer_init(size, count, (void*)&driver_to_buffer_callback); + if (result == -E_SB_NO_MEM_QUEUE_BUSY + || result == -E_SB_NO_MEM_BUFFER_STRUCT) { + return -E_SD_NO_MEMORY; + } + + // TODO Race condition: buffer can be used in other thread till we're in + // this func + /* Initialize driver_to_buffer variables */ + pages_per_buffer = result; + busy_buffer = NULL; + buffers_to_read = 0; + + return E_SD_SUCCESS; } /* Uninitialize buffer */ int driver_to_buffer_uninitialize(void) { - int result; - - /* Release occupied buffer */ - if (busy_buffer) { - result = driver_to_buffer_release(); - // TODO Maybe release anyway - if (result < 0) { - return result; - } - busy_buffer = NULL; - } - - result = swap_buffer_uninit(); - if (result == -E_SB_UNRELEASED_BUFFERS) { - print_err("Can't uninit buffer! There are busy subbuffers!\n"); - result = -E_SD_BUFFER_ERROR; - } else if (result < 0) { - print_err("swap_buffer_uninit error %d\n", result); - result = -E_SD_BUFFER_ERROR; - } else { - result = E_SD_SUCCESS; - } - - /* Reinit driver_to_buffer vars */ - buffers_to_read = 0; - pages_per_buffer = 0; - - return result; + int result; + + /* Release occupied buffer */ + if (busy_buffer) { + result = driver_to_buffer_release(); + // TODO Maybe release anyway + if (result < 0) { + return result; + } + busy_buffer = NULL; + } + + result = swap_buffer_uninit(); + if (result == -E_SB_UNRELEASED_BUFFERS) { + print_err("Can't uninit buffer! There are busy subbuffers!\n"); + result = -E_SD_BUFFER_ERROR; + } else if (result < 0) { + print_err("swap_buffer_uninit error %d\n", result); + result = -E_SD_BUFFER_ERROR; + } else { + result = E_SD_SUCCESS; + } + + /* Reinit driver_to_buffer vars */ + buffers_to_read = 0; + pages_per_buffer = 0; + + return result; } /* Get next buffer to read */ int driver_to_buffer_next_buffer_to_read(void) { //XXX: Think of sync with callback - int result; - - /* If there is busy_buffer first release it */ - if (busy_buffer) { - result = driver_to_buffer_release(); - if (result) - return result; - } - - /* If there is no buffers to read, return E_SD_NO_DATA_TO_READ. - * SHOULD BE POSITIVE, cause there is no real error. */ - if (!buffers_to_read) { - return E_SD_NO_DATA_TO_READ; - } - - /* Get next buffer to read */ - result = driver_to_buffer_get(); - if (result < 0) { - print_err("buffer_to_reads > 0, but there are no buffers to read\n"); - return result; - } - - /* Decrement buffers_to_read counter */ - buffers_to_read--; - - return E_SD_SUCCESS; + int result; + + /* If there is busy_buffer first release it */ + if (busy_buffer) { + result = driver_to_buffer_release(); + if (result) + return result; + } + + /* If there is no buffers to read, return E_SD_NO_DATA_TO_READ. + * SHOULD BE POSITIVE, cause there is no real error. */ + if (!buffers_to_read) { + return E_SD_NO_DATA_TO_READ; + } + + /* Get next buffer to read */ + result = driver_to_buffer_get(); + if (result < 0) { + print_err("buffer_to_reads > 0, but there are no buffers to read\n"); + return result; + } + + /* Decrement buffers_to_read counter */ + buffers_to_read--; + + return E_SD_SUCCESS; } diff --git a/driver_new/driver_to_buffer.h b/driver_new/driver_to_buffer.h index 337791b..b566230 100644 --- a/driver_new/driver_to_buffer.h +++ b/driver_new/driver_to_buffer.h @@ -1,3 +1,27 @@ +/* + * SWAP driver + * modules/driver_new/driver_to_buffer.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2013 + * + * 2013 Alexander Aksenov : SWAP device driver implement + * + */ + #ifndef __SWAP_DRIVER_DRIVER_TO_BUFFER__ #define __SWAP_DRIVER_DRIVER_TO_BUFFER__ diff --git a/driver_new/swap_driver_module.c b/driver_new/swap_driver_module.c index 9581128..d0ef7fe 100644 --- a/driver_new/swap_driver_module.c +++ b/driver_new/swap_driver_module.c @@ -1,3 +1,27 @@ +/* + * SWAP driver + * modules/driver_new/swap_driver_module.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2013 + * + * 2013 Alexander Aksenov : SWAP device driver implement + * + */ + #include #include "driver_defs.h" @@ -6,7 +30,7 @@ static int __init swap_driver_init(void) { swap_device_init(); - print_msg("Driver module initialized\n"); + print_msg("Driver module initialized\n"); return 0; } @@ -14,10 +38,12 @@ static int __init swap_driver_init(void) static void __exit swap_driver_exit(void) { swap_device_exit(); - print_msg("Driver module uninitialized\n"); + print_msg("Driver module uninitialized\n"); } module_init(swap_driver_init); module_exit(swap_driver_exit); MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("SWAP device driver"); +MODULE_AUTHOR("Aksenov A.S."); diff --git a/driver_new/swap_ioctl.h b/driver_new/swap_ioctl.h index fe313f2..a478d43 100644 --- a/driver_new/swap_ioctl.h +++ b/driver_new/swap_ioctl.h @@ -1,3 +1,27 @@ +/* + * SWAP driver + * modules/driver_new/swap_ioctl.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2013 + * + * 2013 Alexander Aksenov : SWAP device driver implement + * + */ + #ifndef __SWAP_IOCTL_H__ #define __SWAP_IOCTL_H__ @@ -5,8 +29,6 @@ #define SWAP_DRIVER_IOC_MAGIC 0xAF -/* TODO: Think about magic num */ - struct buffer_initialize { size_t size; unsigned int count; diff --git a/sampler/kernel_operations.h b/sampler/kernel_operations.h index 5170d36..859e893 100644 --- a/sampler/kernel_operations.h +++ b/sampler/kernel_operations.h @@ -1,3 +1,31 @@ +/* + * SWAP sampler + * modules/sampler/kernel_operations.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2013 + * + * 2013 Alexander Aksenov : SWAP samler kernel + * operations implement + * + */ + +#ifndef __KERNEL_OPERATIONS_H__ +#define __KERNEL_OPERATIONS_H__ + #include #define print_debug(msg, args...) \ @@ -10,3 +38,5 @@ printk(KERN_ERR "SWAP_SAMPLER ERROR : " msg, ##args) #define print_crit(msg, args...) \ printk(KERN_CRIT "SWAP_SAMPLER CRITICAL : " msg, ##args) + +#endif /* __KERNEL_OPERATIONS_H__ */ diff --git a/sampler/swap_sampler_module.c b/sampler/swap_sampler_module.c index 2bcd8cf..d2c9413 100644 --- a/sampler/swap_sampler_module.c +++ b/sampler/swap_sampler_module.c @@ -1,3 +1,28 @@ +/* + * SWAP sampler + * modules/sampler/swap_sampler_module.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2013 + * + * 2012 Andreev S.V.: SWAP Sampler implementation + * 2013 Alexander Aksenov : SWAP sampler porting + * + */ + #include #include #include -- 2.7.4