mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
Staging: p9auth: use kzalloc
It's nicer than doing kmalloc/memset. Also check the return value of all allocations, one was previously not being checked properly. Cc: Ashwin Ganti <ashwin.ganti@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
0f386e2b4c
commit
6d0d63bd7a
@ -86,7 +86,7 @@ static char *cap_hash(char *plain_text, unsigned int plain_text_size,
|
|||||||
char *key, unsigned int key_size)
|
char *key, unsigned int key_size)
|
||||||
{
|
{
|
||||||
struct scatterlist sg;
|
struct scatterlist sg;
|
||||||
char *result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
|
char *result;
|
||||||
struct crypto_hash *tfm;
|
struct crypto_hash *tfm;
|
||||||
struct hash_desc desc;
|
struct hash_desc desc;
|
||||||
int ret;
|
int ret;
|
||||||
@ -96,14 +96,18 @@ static char *cap_hash(char *plain_text, unsigned int plain_text_size,
|
|||||||
printk(KERN_ERR
|
printk(KERN_ERR
|
||||||
"failed to load transform for hmac(sha1): %ld\n",
|
"failed to load transform for hmac(sha1): %ld\n",
|
||||||
PTR_ERR(tfm));
|
PTR_ERR(tfm));
|
||||||
kfree(result);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
desc.tfm = tfm;
|
desc.tfm = tfm;
|
||||||
desc.flags = 0;
|
desc.flags = 0;
|
||||||
|
|
||||||
memset(result, 0, MAX_DIGEST_SIZE);
|
result = kzalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
|
||||||
|
if (!result) {
|
||||||
|
printk(KERN_ERR "out of memory!\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
sg_set_buf(&sg, plain_text, plain_text_size);
|
sg_set_buf(&sg, plain_text, plain_text_size);
|
||||||
|
|
||||||
ret = crypto_hash_setkey(tfm, key, key_size);
|
ret = crypto_hash_setkey(tfm, key, key_size);
|
||||||
@ -187,8 +191,7 @@ static ssize_t cap_write(struct file *filp, const char __user *buf,
|
|||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
node_ptr = kmalloc(sizeof(struct cap_node), GFP_KERNEL);
|
node_ptr = kmalloc(sizeof(struct cap_node), GFP_KERNEL);
|
||||||
user_buf = kmalloc(count, GFP_KERNEL);
|
user_buf = kzalloc(count, GFP_KERNEL);
|
||||||
memset(user_buf, 0, count);
|
|
||||||
|
|
||||||
if (copy_from_user(user_buf, buf, count)) {
|
if (copy_from_user(user_buf, buf, count)) {
|
||||||
retval = -EFAULT;
|
retval = -EFAULT;
|
||||||
@ -218,8 +221,7 @@ static ssize_t cap_write(struct file *filp, const char __user *buf,
|
|||||||
|
|
||||||
/* hash the string user1@user2 with rand_str as the key */
|
/* hash the string user1@user2 with rand_str as the key */
|
||||||
len = strlen(source_user) + strlen(target_user) + 1;
|
len = strlen(source_user) + strlen(target_user) + 1;
|
||||||
hash_str = kmalloc(len, GFP_KERNEL);
|
hash_str = kzalloc(len, GFP_KERNEL);
|
||||||
memset(hash_str, 0, len);
|
|
||||||
strcat(hash_str, source_user);
|
strcat(hash_str, source_user);
|
||||||
strcat(hash_str, "@");
|
strcat(hash_str, "@");
|
||||||
strcat(hash_str, target_user);
|
strcat(hash_str, target_user);
|
||||||
@ -364,13 +366,12 @@ static int cap_init_module(void)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
cap_devices =
|
cap_devices = kzalloc(cap_nr_devs * sizeof(struct cap_dev),
|
||||||
kmalloc(cap_nr_devs * sizeof(struct cap_dev), GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!cap_devices) {
|
if (!cap_devices) {
|
||||||
result = -ENOMEM;
|
result = -ENOMEM;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
memset(cap_devices, 0, cap_nr_devs * sizeof(struct cap_dev));
|
|
||||||
|
|
||||||
/* Initialize each device. */
|
/* Initialize each device. */
|
||||||
for (i = 0; i < cap_nr_devs; i++) {
|
for (i = 0; i < cap_nr_devs; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user