diff --git a/drivers/klist/klist.c b/drivers/klist/klist.c index 3f17b33ea1443bd241f7be3268792c03128f9883..91ca78cd61f28c0648268175b38286e9313a521d 100644 --- a/drivers/klist/klist.c +++ b/drivers/klist/klist.c @@ -33,8 +33,10 @@ /* consts */ #define MAX_SIZE 0x400 -static long k_list[MAX_SIZE]; -static unsigned long list_size; +static struct k_list { + long values[MAX_SIZE]; + unsigned long size; +} list; struct index_val_t { unsigned long index; @@ -43,10 +45,10 @@ struct index_val_t { long add_item(long arg) { - if (list_size >= MAX_SIZE) + if (list.size >= MAX_SIZE) return -EINVAL; - k_list[list_size] = arg; - list_size++; + list.values[list.size] = arg; + list.size++; return 0; } @@ -58,17 +60,17 @@ long insert_item(long arg) if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t))) return -EINVAL; - if (list_size >= MAX_SIZE) + if (list.size >= MAX_SIZE) return -EINVAL; - if (io.index > list_size) + if (io.index > list.size) 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_size++; + list.values[io.index] = io.value; + list.size++; return 0; } @@ -79,10 +81,10 @@ long set_item(long arg) if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t))) return -EINVAL; - if (io.index >= list_size) + if (io.index >= list.size) return -EINVAL; - k_list[io.index] = io.value; + list.values[io.index] = io.value; return 0; } @@ -93,10 +95,10 @@ long get_item(long arg) if (copy_from_user((void *)&io, (void __user *)arg, sizeof(struct index_val_t))) return -EINVAL; - if (io.index >= list_size) + if (io.index >= list.size) 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))) return -EINVAL; @@ -107,14 +109,14 @@ long delete_item(long arg) { unsigned long index = arg; - if (index >= list_size) + if (index >= list.size) 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; } @@ -180,7 +182,7 @@ static int __init init_list(void) ret = misc_register(&klist); LOG("register device: %d\n", ret); - list_size = 0; + list.size = 0; return ret; }