Fix indention and whitespaces
This commit is contained in:
parent
8968ffa2f4
commit
ced70a7433
107
amifldrv.c
107
amifldrv.c
|
@ -58,14 +58,12 @@ static int chardev_open_count = 0;
|
|||
/**
|
||||
* Character Device open action
|
||||
*/
|
||||
int
|
||||
AMI_chrdrv_open(struct inode* inode, struct file* file)
|
||||
int AMI_chrdrv_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
#if LINUX_PRE_2_6
|
||||
MOD_INC_USE_COUNT;
|
||||
#else
|
||||
if (chardev_open_count > 0)
|
||||
{
|
||||
if (chardev_open_count > 0) {
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
|
@ -76,8 +74,7 @@ AMI_chrdrv_open(struct inode* inode, struct file* file)
|
|||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
AMI_chrdrv_release(struct inode* inode, struct file* file)
|
||||
int AMI_chrdrv_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
#if LINUX_PRE_2_6
|
||||
MOD_DEC_USE_COUNT;
|
||||
|
@ -90,47 +87,42 @@ AMI_chrdrv_release(struct inode* inode, struct file* file)
|
|||
}
|
||||
|
||||
#if defined(HAVE_UNLOCKED_IOCTL)
|
||||
long
|
||||
AMI_chrdrv_ioctl(struct file* _unused_file, unsigned int cmd, unsigned long arg)
|
||||
long AMI_chrdrv_ioctl(struct file *_unused_file, unsigned int cmd, unsigned long arg)
|
||||
#else
|
||||
int
|
||||
AMI_chrdrv_ioctl(struct inode* _unused_inode, unsigned int cmd, unsigned long arg)
|
||||
int AMI_chrdrv_ioctl(struct inode *_unused_inode, unsigned int cmd, unsigned long arg)
|
||||
#endif
|
||||
{
|
||||
switch(cmd)
|
||||
{
|
||||
switch (cmd) {
|
||||
case CMD_ALLOC:
|
||||
{
|
||||
unsigned long virt_addr;
|
||||
AMIFL_alloc_params arg_kernel_space;
|
||||
|
||||
if (kcount >= 128)
|
||||
{
|
||||
if (kcount >= 128) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
kmalloc_ptr = NULL;
|
||||
|
||||
if (!arg || kmalloc_ptr)
|
||||
{
|
||||
if (!arg || kmalloc_ptr) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
copy_from_user((void*) &arg_kernel_space, (void*) arg, sizeof(AMIFL_alloc_params));
|
||||
copy_from_user((void *) &arg_kernel_space, (void *) arg,
|
||||
sizeof(AMIFL_alloc_params));
|
||||
|
||||
if (arg_kernel_space.size > 128 * 1024)
|
||||
{
|
||||
if (arg_kernel_space.size > 128 * 1024) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
kmalloc_len = ((arg_kernel_space.size + PAGE_SIZE - 1) & PAGE_MASK);
|
||||
kmalloc_ptr = kmalloc((kmalloc_len + 2 * PAGE_SIZE), GFP_DMA | GFP_KERNEL);
|
||||
kmalloc_area = (int *)(((unsigned long)kmalloc_ptr + PAGE_SIZE - 1) & PAGE_MASK);
|
||||
kmalloc_area =
|
||||
(int *) (((unsigned long) kmalloc_ptr + PAGE_SIZE - 1) & PAGE_MASK);
|
||||
|
||||
for (virt_addr = (unsigned long) kmalloc_area;
|
||||
virt_addr < (unsigned long) kmalloc_area + kmalloc_len;
|
||||
virt_addr += PAGE_SIZE)
|
||||
{
|
||||
virt_addr += PAGE_SIZE) {
|
||||
mem_map_reserve(virt_to_page(virt_addr));
|
||||
}
|
||||
|
||||
|
@ -145,13 +137,16 @@ AMI_chrdrv_ioctl(struct inode* _unused_inode, unsigned int cmd, unsigned long ar
|
|||
kmalloc_drv[kcount].kmallocptr = kmalloc_ptr;
|
||||
kmalloc_drv[kcount].kvirtlen = kmalloc_len;
|
||||
kmalloc_drv[kcount].kvirtadd = kmalloc_area;
|
||||
kmalloc_drv[kcount].kphysadd = (void *)((unsigned long)virt_to_phys(kmalloc_area));
|
||||
kmalloc_drv[kcount].kphysadd =
|
||||
(void *) ((unsigned long) virt_to_phys(kmalloc_area));
|
||||
++kcount;
|
||||
|
||||
arg_kernel_space.kvirtadd = kmalloc_area;
|
||||
arg_kernel_space.kphysadd = (void *)((unsigned long)virt_to_phys(kmalloc_area));
|
||||
arg_kernel_space.kphysadd =
|
||||
(void *) ((unsigned long) virt_to_phys(kmalloc_area));
|
||||
|
||||
copy_to_user((void*) arg, (void*) &arg_kernel_space, sizeof(AMIFL_alloc_params));
|
||||
copy_to_user((void *) arg, (void *) &arg_kernel_space,
|
||||
sizeof(AMIFL_alloc_params));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -161,13 +156,17 @@ AMI_chrdrv_ioctl(struct inode* _unused_inode, unsigned int cmd, unsigned long ar
|
|||
AMIFL_alloc_params arg_kernel_space;
|
||||
int isearch = 0;
|
||||
|
||||
copy_from_user((void*) &arg_kernel_space, (void*) arg, sizeof(AMIFL_alloc_params));
|
||||
copy_from_user((void *) &arg_kernel_space, (void *) arg,
|
||||
sizeof(AMIFL_alloc_params));
|
||||
|
||||
if (kcount > 0) {
|
||||
for (isearch = 0; isearch < kcount; isearch++) {
|
||||
if (kmalloc_drv[isearch].kphysadd == arg_kernel_space.kphysadd) break;
|
||||
if (kmalloc_drv[isearch].kphysadd ==
|
||||
arg_kernel_space.kphysadd)
|
||||
break;
|
||||
}
|
||||
if (isearch >= kcount) return 0;
|
||||
if (isearch >= kcount)
|
||||
return 0;
|
||||
kmalloc_ptr = kmalloc_drv[isearch].kmallocptr;
|
||||
kmalloc_area = kmalloc_drv[isearch].kvirtadd;
|
||||
kmalloc_len = kmalloc_drv[isearch].kvirtlen;
|
||||
|
@ -176,8 +175,7 @@ AMI_chrdrv_ioctl(struct inode* _unused_inode, unsigned int cmd, unsigned long ar
|
|||
if (kmalloc_ptr) {
|
||||
for (virt_addr = (unsigned long) kmalloc_area;
|
||||
virt_addr < (unsigned long) kmalloc_area + kmalloc_len;
|
||||
virt_addr += PAGE_SIZE)
|
||||
{
|
||||
virt_addr += PAGE_SIZE) {
|
||||
mem_map_unreserve(virt_to_page(virt_addr));
|
||||
}
|
||||
|
||||
|
@ -192,10 +190,14 @@ AMI_chrdrv_ioctl(struct inode* _unused_inode, unsigned int cmd, unsigned long ar
|
|||
|
||||
if (isearch != kcount) {
|
||||
kmalloc_drv[isearch].size = kmalloc_drv[kcount].size;
|
||||
kmalloc_drv[isearch].kmallocptr = kmalloc_drv[kcount].kmallocptr;
|
||||
kmalloc_drv[isearch].kvirtlen = kmalloc_drv[kcount].kvirtlen;
|
||||
kmalloc_drv[isearch].kvirtadd = kmalloc_drv[kcount].kvirtadd;
|
||||
kmalloc_drv[isearch].kphysadd = kmalloc_drv[kcount].kphysadd;
|
||||
kmalloc_drv[isearch].kmallocptr =
|
||||
kmalloc_drv[kcount].kmallocptr;
|
||||
kmalloc_drv[isearch].kvirtlen =
|
||||
kmalloc_drv[kcount].kvirtlen;
|
||||
kmalloc_drv[isearch].kvirtadd =
|
||||
kmalloc_drv[kcount].kvirtadd;
|
||||
kmalloc_drv[isearch].kphysadd =
|
||||
kmalloc_drv[kcount].kphysadd;
|
||||
}
|
||||
|
||||
kmalloc_drv[kcount].size = 0;
|
||||
|
@ -216,8 +218,7 @@ AMI_chrdrv_ioctl(struct inode* _unused_inode, unsigned int cmd, unsigned long ar
|
|||
return -ENOTTY;
|
||||
}
|
||||
|
||||
int
|
||||
AMI_chrdrv_mmap(struct file* file, struct vm_area_struct* vma)
|
||||
int AMI_chrdrv_mmap(struct file *file, struct vm_area_struct *vma)
|
||||
{
|
||||
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
|
||||
unsigned long size = vma->vm_end - vma->vm_start;
|
||||
|
@ -244,23 +245,20 @@ AMI_chrdrv_mmap(struct file* file, struct vm_area_struct* vma)
|
|||
unsigned long pfn = virt_to_phys((void *) ((unsigned long) kmalloc_area));
|
||||
|
||||
#if LINUX_POST_2_6
|
||||
int remap_result =
|
||||
remap_pfn_range(vma,
|
||||
int remap_result = remap_pfn_range(vma,
|
||||
vma->vm_start,
|
||||
pfn >> PAGE_SHIFT,
|
||||
size,
|
||||
PAGE_SHARED);
|
||||
#else
|
||||
int remap_result =
|
||||
remap_page_range(vma,
|
||||
int remap_result = remap_page_range(vma,
|
||||
vma->vm_start,
|
||||
pfn,
|
||||
size,
|
||||
PAGE_SHARED);
|
||||
#endif
|
||||
|
||||
if (remap_result)
|
||||
{
|
||||
if (remap_result) {
|
||||
return -ENXIO;
|
||||
}
|
||||
}
|
||||
|
@ -295,13 +293,11 @@ MODULE_LICENSE ("Proprietary");
|
|||
|
||||
#endif
|
||||
|
||||
static int /* module_init */
|
||||
amifldrv_init_module(void)
|
||||
static int /* module_init */ amifldrv_init_module(void)
|
||||
{
|
||||
major = register_chrdev(0, "amifldrv", &AMI_chrdrv_fops);
|
||||
|
||||
if (major < 0)
|
||||
{
|
||||
if (major < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -310,30 +306,24 @@ amifldrv_init_module(void)
|
|||
return (0);
|
||||
}
|
||||
|
||||
static void /* module_exit */
|
||||
amifldrv_cleanup_module(void)
|
||||
static void /* module_exit */ amifldrv_cleanup_module(void)
|
||||
{
|
||||
unsigned long virt_addr;
|
||||
if (kcount > 0)
|
||||
{
|
||||
if (kcount > 0) {
|
||||
{
|
||||
int iloop;
|
||||
for (iloop = 0; iloop < kcount; ++iloop)
|
||||
{
|
||||
for (iloop = 0; iloop < kcount; ++iloop) {
|
||||
kmalloc_ptr = kmalloc_drv[iloop].kmallocptr;
|
||||
kmalloc_area = kmalloc_drv[iloop].kvirtadd;
|
||||
kmalloc_len = kmalloc_drv[iloop].kvirtlen;
|
||||
if (kmalloc_ptr)
|
||||
{
|
||||
if (kmalloc_ptr) {
|
||||
for (virt_addr = (unsigned long) kmalloc_area;
|
||||
virt_addr < (unsigned long) kmalloc_area + kmalloc_len;
|
||||
virt_addr += PAGE_SIZE)
|
||||
{
|
||||
virt_addr += PAGE_SIZE) {
|
||||
mem_map_unreserve(virt_to_page(virt_addr));
|
||||
}
|
||||
|
||||
if (kmalloc_ptr)
|
||||
{
|
||||
if (kmalloc_ptr) {
|
||||
kfree(kmalloc_ptr);
|
||||
}
|
||||
}
|
||||
|
@ -349,4 +339,3 @@ amifldrv_cleanup_module(void)
|
|||
|
||||
module_init(amifldrv_init_module);
|
||||
module_exit(amifldrv_cleanup_module);
|
||||
|
||||
|
|
Loading…
Reference in New Issue