Commit 1769fd86 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Staging: dt3155: coding style cleanups for allocator code

This fixes up the worst of the coding style errors for the
allocator code.

Cc: Scott Smedley <ss@aao.gov.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 8125e2f6
......@@ -68,7 +68,7 @@
# define DUMP_LIST() dump_list()
# ifdef __KERNEL__
/* This one if debugging is on, and kernel space */
# define PDEBUG(fmt, args...) printk( KERN_DEBUG ALL_MSG fmt, ## args)
# define PDEBUG(fmt, args...) printk(KERN_DEBUG ALL_MSG fmt, ## args)
# else
/* This one for user space */
# define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
......@@ -88,8 +88,8 @@ int allocator_himem = 1; /* 0 = probe, pos. = megs, neg. = disable */
int allocator_step = 1; /* This is the step size in MB */
int allocator_probe = 1; /* This is a flag -- 1=probe, 0=don't probe */
static unsigned long allocator_buffer = 0; /* physical address */
static unsigned long allocator_buffer_size = 0; /* kilobytes */
static unsigned long allocator_buffer; /* physical address */
static unsigned long allocator_buffer_size; /* kilobytes */
/*
* The allocator keeps a list of DMA areas, so multiple devices
......@@ -102,7 +102,7 @@ struct allocator_struct {
struct allocator_struct *next;
};
struct allocator_struct *allocator_list = NULL;
struct allocator_struct *allocator_list;
#ifdef ALL_DEBUG
......@@ -111,9 +111,8 @@ static int dump_list(void)
struct allocator_struct *ptr;
PDEBUG("Current list:\n");
for (ptr = allocator_list; ptr; ptr = ptr->next) {
PDEBUG("0x%08lx (size %likB)\n",ptr->address,ptr->size>>10);
}
for (ptr = allocator_list; ptr; ptr = ptr->next)
PDEBUG("0x%08lx (size %likB)\n", ptr->address, ptr->size>>10);
return 0;
}
#endif
......@@ -126,7 +125,7 @@ static int dump_list(void)
* be used straight ahead for DMA, but needs remapping for program use).
*/
unsigned long allocator_allocate_dma (unsigned long kilobytes, int prio)
unsigned long allocator_allocate_dma(unsigned long kilobytes, int prio)
{
struct allocator_struct *ptr = allocator_list, *newptr;
unsigned long bytes = kilobytes << 10;
......@@ -149,7 +148,7 @@ unsigned long allocator_allocate_dma (unsigned long kilobytes, int prio)
PDEBUG("alloc failed\n");
return 0; /* end of list */
}
newptr = kmalloc(sizeof(struct allocator_struct),prio);
newptr = kmalloc(sizeof(struct allocator_struct), prio);
if (!newptr)
return 0;
......@@ -160,11 +159,11 @@ unsigned long allocator_allocate_dma (unsigned long kilobytes, int prio)
ptr->next = newptr;
DUMP_LIST();
PDEBUG("returning 0x%08lx\n",newptr->address);
PDEBUG("returning 0x%08lx\n", newptr->address);
return newptr->address;
}
int allocator_free_dma (unsigned long address)
int allocator_free_dma(unsigned long address)
{
struct allocator_struct *ptr = allocator_list, *prev;
......@@ -177,11 +176,12 @@ int allocator_free_dma (unsigned long address)
prev = ptr; ptr = ptr->next;
if (!ptr) {
printk(KERN_ERR ALL_MSG "free_dma(0x%08lx) but add. not allocated\n",
printk(KERN_ERR ALL_MSG
"free_dma(0x%08lx) but add. not allocated\n",
ptr->address);
return -EINVAL;
}
PDEBUGG("freeing: %08lx (%li) next %08lx\n",ptr->address,ptr->size,
PDEBUGG("freeing: %08lx (%li) next %08lx\n", ptr->address, ptr->size,
ptr->next->address);
prev->next = ptr->next;
kfree(ptr);
......@@ -199,32 +199,31 @@ int allocator_free_dma (unsigned long address)
int allocator_init(u_long *allocator_max)
{
/* check how much free memory is there */
volatile void *remapped;
void *remapped;
unsigned long max;
unsigned long trial_size = allocator_himem<<20;
unsigned long last_trial = 0;
unsigned long step = allocator_step<<20;
unsigned long i=0;
unsigned long i = 0;
struct allocator_struct *head, *tail;
char test_string[]="0123456789abcde"; /* 16 bytes */
char test_string[] = "0123456789abcde"; /* 16 bytes */
PDEBUGG("himem = %i\n",allocator_himem);
PDEBUGG("himem = %i\n", allocator_himem);
if (allocator_himem < 0) /* don't even try */
return -EINVAL;
if (!trial_size) trial_size = 1<<20; /* not specified: try one meg */
if (!trial_size)
trial_size = 1<<20; /* not specified: try one meg */
while (1) {
remapped = ioremap(__pa(high_memory), trial_size);
if (!remapped)
{
PDEBUGG("%li megs failed!\n",trial_size>>20);
if (!remapped) {
PDEBUGG("%li megs failed!\n", trial_size>>20);
break;
}
PDEBUGG("Trying %li megs (at %p, %p)\n",trial_size>>20,
PDEBUGG("Trying %li megs (at %p, %p)\n", trial_size>>20,
(void *)__pa(high_memory), remapped);
for (i=last_trial; i<trial_size; i+=16) {
for (i = last_trial; i < trial_size; i += 16) {
strcpy((char *)(remapped)+i, test_string);
if (strcmp((char *)(remapped)+i, test_string))
break;
......@@ -232,16 +231,16 @@ int allocator_init(u_long *allocator_max)
iounmap((void *)remapped);
schedule();
last_trial = trial_size;
if (i==trial_size)
if (i == trial_size)
trial_size += step; /* increment, if all went well */
else
{
PDEBUGG("%li megs copy test failed!\n",trial_size>>20);
else {
PDEBUGG("%li megs copy test failed!\n", trial_size>>20);
break;
}
if (!allocator_probe) break;
if (!allocator_probe)
break;
}
PDEBUG("%li megs (%li k, %li b)\n",i>>20,i>>10,i);
PDEBUG("%li megs (%li k, %li b)\n", i>>20, i>>10, i);
allocator_buffer_size = i>>10; /* kilobytes */
allocator_buffer = __pa(high_memory);
if (!allocator_buffer_size) {
......@@ -255,10 +254,10 @@ int allocator_init(u_long *allocator_max)
* extra code when allocating and deallocating: we only play
* in the middle of the list
*/
head = kmalloc(sizeof(struct allocator_struct),GFP_KERNEL);
head = kmalloc(sizeof(struct allocator_struct), GFP_KERNEL);
if (!head)
return -ENOMEM;
tail = kmalloc(sizeof(struct allocator_struct),GFP_KERNEL);
tail = kmalloc(sizeof(struct allocator_struct), GFP_KERNEL);
if (!tail) {
kfree(head);
return -ENOMEM;
......@@ -273,7 +272,8 @@ int allocator_init(u_long *allocator_max)
tail->next = NULL;
allocator_list = head;
*allocator_max = allocator_buffer_size; /* Back to the user code, in KB */
/* Back to the user code, in KB */
*allocator_max = allocator_buffer_size;
return 0; /* ok, ready */
}
......@@ -284,7 +284,7 @@ void allocator_cleanup(void)
for (ptr = allocator_list; ptr; ptr = next) {
next = ptr->next;
PDEBUG("freeing list: 0x%08lx\n",ptr->address);
PDEBUG("freeing list: 0x%08lx\n", ptr->address);
kfree(ptr);
}
......
......@@ -23,6 +23,6 @@
*/
void allocator_free_dma(unsigned long address);
unsigned long allocator_allocate_dma (unsigned long kilobytes, int priority);
unsigned long allocator_allocate_dma(unsigned long kilobytes, int priority);
int allocator_init(u_long *);
void allocator_cleanup(void);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment