Skip to content
Snippets Groups Projects
Commit e35436dc authored by Werner Sembach's avatar Werner Sembach
Browse files

Pack k_list and list_size into a struct to prevent variable reordering

parent 1df03d1a
Branches
No related tags found
No related merge requests found
...@@ -33,8 +33,10 @@ ...@@ -33,8 +33,10 @@
/* consts */ /* consts */
#define MAX_SIZE 0x400 #define MAX_SIZE 0x400
static long k_list[MAX_SIZE]; static struct k_list {
static unsigned long list_size; long values[MAX_SIZE];
unsigned long size;
} list;
struct index_val_t { struct index_val_t {
unsigned long index; unsigned long index;
...@@ -43,10 +45,10 @@ struct index_val_t { ...@@ -43,10 +45,10 @@ struct index_val_t {
long add_item(long arg) long add_item(long arg)
{ {
if (list_size >= MAX_SIZE) if (list.size >= MAX_SIZE)
return -EINVAL; return -EINVAL;
k_list[list_size] = arg; list.values[list.size] = arg;
list_size++; list.size++;
return 0; return 0;
} }
...@@ -58,17 +60,17 @@ long insert_item(long arg) ...@@ -58,17 +60,17 @@ long insert_item(long arg)
if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t))) if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t)))
return -EINVAL; return -EINVAL;
if (list_size >= MAX_SIZE) if (list.size >= MAX_SIZE)
return -EINVAL; return -EINVAL;
if (io.index > list_size) if (io.index > list.size)
return -EINVAL; return -EINVAL;
for(i = list_size; i > io.index; i--) for(i = list.size; i > io.index; i--)
{ {
k_list[i] = k_list[i-1]; list.values[i] = list.values[i-1];
} }
k_list[io.index] = io.value; list.values[io.index] = io.value;
list_size++; list.size++;
return 0; return 0;
} }
...@@ -79,10 +81,10 @@ long set_item(long arg) ...@@ -79,10 +81,10 @@ long set_item(long arg)
if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t))) if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t)))
return -EINVAL; return -EINVAL;
if (io.index >= list_size) if (io.index >= list.size)
return -EINVAL; return -EINVAL;
k_list[io.index] = io.value; list.values[io.index] = io.value;
return 0; return 0;
} }
...@@ -93,10 +95,10 @@ long get_item(long arg) ...@@ -93,10 +95,10 @@ long get_item(long arg)
if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t))) if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t)))
return -EINVAL; return -EINVAL;
if (io.index >= list_size) if (io.index >= list.size)
return -EINVAL; return -EINVAL;
io.value = k_list[io.index]; io.value = list.values[io.index];
if (copy_to_user((void __user *)arg, (void *)&io, sizeof(struct index_val_t))) if (copy_to_user((void __user *)arg, (void *)&io, sizeof(struct index_val_t)))
return -EINVAL; return -EINVAL;
...@@ -107,14 +109,14 @@ long delete_item(long arg) ...@@ -107,14 +109,14 @@ long delete_item(long arg)
{ {
unsigned long index = arg; unsigned long index = arg;
if (index >= list_size) if (index >= list.size)
return -EINVAL; return -EINVAL;
for(; index < list_size-1; index++) for(; index < list.size-1; index++)
{ {
k_list[index] = k_list[index+1]; list.values[index] = list.values[index+1];
} }
list_size--; list.size--;
return 0; return 0;
} }
...@@ -180,7 +182,7 @@ static int __init init_list(void) ...@@ -180,7 +182,7 @@ static int __init init_list(void)
ret = misc_register(&klist); ret = misc_register(&klist);
LOG("register device: %d\n", ret); LOG("register device: %d\n", ret);
list_size = 0; list.size = 0;
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment