aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2009-02-24 23:25:02 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-04-03 17:54:23 -0400
commit0f386e2b4c6109164e82277513a9570fc9ec644c (patch)
tree305e6c16568022518a445a93050345786448aeb3 /drivers/staging
parent77dc1139f4a125d46e03fdbb3ac8ab8737ab67d6 (diff)
Staging: p9auth: fix up sparse warnings
Everything needs to be static, as sparse complains and you don't want to polute the global kernel symbol namespace. So mark everything as such and move one function around to prevent a forward declaration from being needed. Cc: Ashwin Ganti <ashwin.ganti@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/p9auth/p9auth.c133
1 files changed, 64 insertions, 69 deletions
diff --git a/drivers/staging/p9auth/p9auth.c b/drivers/staging/p9auth/p9auth.c
index c1e5bc4f30a..a6078bb813c 100644
--- a/drivers/staging/p9auth/p9auth.c
+++ b/drivers/staging/p9auth/p9auth.c
@@ -61,13 +61,10 @@ struct cap_dev {
61 struct cdev cdev; 61 struct cdev cdev;
62}; 62};
63 63
64char *cap_hash(char *plain_text, unsigned int plain_text_size, char *key, 64static int cap_major = CAP_MAJOR;
65 unsigned int key_size); 65static int cap_minor;
66 66static int cap_nr_devs = CAP_NR_DEVS;
67int cap_major = CAP_MAJOR; 67static int cap_node_size = CAP_NODE_SIZE;
68int cap_minor;
69int cap_nr_devs = CAP_NR_DEVS;
70int cap_node_size = CAP_NODE_SIZE;
71 68
72module_param(cap_major, int, S_IRUGO); 69module_param(cap_major, int, S_IRUGO);
73module_param(cap_minor, int, S_IRUGO); 70module_param(cap_minor, int, S_IRUGO);
@@ -76,16 +73,65 @@ module_param(cap_nr_devs, int, S_IRUGO);
76MODULE_AUTHOR("Ashwin Ganti"); 73MODULE_AUTHOR("Ashwin Ganti");
77MODULE_LICENSE("GPL"); 74MODULE_LICENSE("GPL");
78 75
79struct cap_dev *cap_devices; 76static struct cap_dev *cap_devices;
80 77
81void hexdump(unsigned char *buf, unsigned int len) 78static void hexdump(unsigned char *buf, unsigned int len)
82{ 79{
83 while (len--) 80 while (len--)
84 printk("%02x", *buf++); 81 printk("%02x", *buf++);
85 printk("\n"); 82 printk("\n");
86} 83}
87 84
88int cap_trim(struct cap_dev *dev) 85static char *cap_hash(char *plain_text, unsigned int plain_text_size,
86 char *key, unsigned int key_size)
87{
88 struct scatterlist sg;
89 char *result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
90 struct crypto_hash *tfm;
91 struct hash_desc desc;
92 int ret;
93
94 tfm = crypto_alloc_hash("hmac(sha1)", 0, CRYPTO_ALG_ASYNC);
95 if (IS_ERR(tfm)) {
96 printk(KERN_ERR
97 "failed to load transform for hmac(sha1): %ld\n",
98 PTR_ERR(tfm));
99 kfree(result);
100 return NULL;
101 }
102
103 desc.tfm = tfm;
104 desc.flags = 0;
105
106 memset(result, 0, MAX_DIGEST_SIZE);
107 sg_set_buf(&sg, plain_text, plain_text_size);
108
109 ret = crypto_hash_setkey(tfm, key, key_size);
110 if (ret) {
111 printk(KERN_ERR "setkey() failed ret=%d\n", ret);
112 kfree(result);
113 result = NULL;
114 goto out;
115 }
116
117 ret = crypto_hash_digest(&desc, &sg, plain_text_size, result);
118 if (ret) {
119 printk(KERN_ERR "digest () failed ret=%d\n", ret);
120 kfree(result);
121 result = NULL;
122 goto out;
123 }
124
125 printk(KERN_DEBUG "crypto hash digest size %d\n",
126 crypto_hash_digestsize(tfm));
127 hexdump(result, MAX_DIGEST_SIZE);
128
129out:
130 crypto_free_hash(tfm);
131 return result;
132}
133
134static int cap_trim(struct cap_dev *dev)
89{ 135{
90 struct cap_node *tmp; 136 struct cap_node *tmp;
91 struct list_head *pos, *q; 137 struct list_head *pos, *q;
@@ -99,7 +145,7 @@ int cap_trim(struct cap_dev *dev)
99 return 0; 145 return 0;
100} 146}
101 147
102int cap_open(struct inode *inode, struct file *filp) 148static int cap_open(struct inode *inode, struct file *filp)
103{ 149{
104 struct cap_dev *dev; 150 struct cap_dev *dev;
105 dev = container_of(inode->i_cdev, struct cap_dev, cdev); 151 dev = container_of(inode->i_cdev, struct cap_dev, cdev);
@@ -120,13 +166,13 @@ int cap_open(struct inode *inode, struct file *filp)
120 return 0; 166 return 0;
121} 167}
122 168
123int cap_release(struct inode *inode, struct file *filp) 169static int cap_release(struct inode *inode, struct file *filp)
124{ 170{
125 return 0; 171 return 0;
126} 172}
127 173
128ssize_t cap_write(struct file *filp, const char __user *buf, size_t count, 174static ssize_t cap_write(struct file *filp, const char __user *buf,
129 loff_t *f_pos) 175 size_t count, loff_t *f_pos)
130{ 176{
131 struct cap_node *node_ptr, *tmp; 177 struct cap_node *node_ptr, *tmp;
132 struct list_head *pos; 178 struct list_head *pos;
@@ -181,8 +227,7 @@ ssize_t cap_write(struct file *filp, const char __user *buf, size_t count,
181 printk(KERN_ALERT "the source user is %s \n", source_user); 227 printk(KERN_ALERT "the source user is %s \n", source_user);
182 printk(KERN_ALERT "the target user is %s \n", target_user); 228 printk(KERN_ALERT "the target user is %s \n", target_user);
183 229
184 result = 230 result = cap_hash(hash_str, len, rand_str, strlen(rand_str));
185 cap_hash(hash_str, len, rand_str, strlen(rand_str));
186 if (NULL == result) { 231 if (NULL == result) {
187 retval = -EFAULT; 232 retval = -EFAULT;
188 goto out; 233 goto out;
@@ -266,15 +311,14 @@ out:
266 return retval; 311 return retval;
267} 312}
268 313
269const struct file_operations cap_fops = { 314static const struct file_operations cap_fops = {
270 .owner = THIS_MODULE, 315 .owner = THIS_MODULE,
271 .write = cap_write, 316 .write = cap_write,
272 .open = cap_open, 317 .open = cap_open,
273 .release = cap_release, 318 .release = cap_release,
274}; 319};
275 320
276 321static void cap_cleanup_module(void)
277void cap_cleanup_module(void)
278{ 322{
279 int i; 323 int i;
280 dev_t devno = MKDEV(cap_major, cap_minor); 324 dev_t devno = MKDEV(cap_major, cap_minor);
@@ -289,7 +333,6 @@ void cap_cleanup_module(void)
289 333
290} 334}
291 335
292
293static void cap_setup_cdev(struct cap_dev *dev, int index) 336static void cap_setup_cdev(struct cap_dev *dev, int index)
294{ 337{
295 int err, devno = MKDEV(cap_major, cap_minor + index); 338 int err, devno = MKDEV(cap_major, cap_minor + index);
@@ -301,8 +344,7 @@ static void cap_setup_cdev(struct cap_dev *dev, int index)
301 printk(KERN_NOTICE "Error %d adding cap%d", err, index); 344 printk(KERN_NOTICE "Error %d adding cap%d", err, index);
302} 345}
303 346
304 347static int cap_init_module(void)
305int cap_init_module(void)
306{ 348{
307 int result, i; 349 int result, i;
308 dev_t dev = 0; 350 dev_t dev = 0;
@@ -347,51 +389,4 @@ fail:
347module_init(cap_init_module); 389module_init(cap_init_module);
348module_exit(cap_cleanup_module); 390module_exit(cap_cleanup_module);
349 391
350char *cap_hash(char *plain_text, unsigned int plain_text_size,
351 char *key, unsigned int key_size)
352{
353 struct scatterlist sg;
354 char *result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
355 struct crypto_hash *tfm;
356 struct hash_desc desc;
357 int ret;
358
359 tfm = crypto_alloc_hash("hmac(sha1)", 0, CRYPTO_ALG_ASYNC);
360 if (IS_ERR(tfm)) {
361 printk(KERN_ERR
362 "failed to load transform for hmac(sha1): %ld\n",
363 PTR_ERR(tfm));
364 kfree(result);
365 return NULL;
366 }
367
368 desc.tfm = tfm;
369 desc.flags = 0;
370
371 memset(result, 0, MAX_DIGEST_SIZE);
372 sg_set_buf(&sg, plain_text, plain_text_size);
373
374 ret = crypto_hash_setkey(tfm, key, key_size);
375 if (ret) {
376 printk(KERN_ERR "setkey() failed ret=%d\n", ret);
377 kfree(result);
378 result = NULL;
379 goto out;
380 }
381
382 ret = crypto_hash_digest(&desc, &sg, plain_text_size, result);
383 if (ret) {
384 printk(KERN_ERR "digest () failed ret=%d\n", ret);
385 kfree(result);
386 result = NULL;
387 goto out;
388 }
389
390 printk(KERN_DEBUG "crypto hash digest size %d\n",
391 crypto_hash_digestsize(tfm));
392 hexdump(result, MAX_DIGEST_SIZE);
393 392
394out:
395 crypto_free_hash(tfm);
396 return result;
397}