Skip to content

Commit 1a0bba4

Browse files
elfringtyhicks
authored andcommitted
ecryptfs: Delete 21 error messages for a failed memory allocation
Omit extra messages for a memory allocation failure in these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
1 parent db86be3 commit 1a0bba4

6 files changed

Lines changed: 7 additions & 59 deletions

File tree

‎fs/ecryptfs/crypto.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,6 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry)
14191419
page_virt = kmem_cache_alloc(ecryptfs_header_cache, GFP_USER);
14201420
if (!page_virt) {
14211421
rc = -ENOMEM;
1422-
printk(KERN_ERR "%s: Unable to allocate page_virt\n",
1423-
__func__);
14241422
goto out;
14251423
}
14261424
rc = ecryptfs_read_lower(page_virt, 0, crypt_stat->extent_size,
@@ -1507,9 +1505,6 @@ ecryptfs_encrypt_filename(struct ecryptfs_filename *filename,
15071505
filename->encrypted_filename =
15081506
kmalloc(filename->encrypted_filename_size, GFP_KERNEL);
15091507
if (!filename->encrypted_filename) {
1510-
printk(KERN_ERR "%s: Out of memory whilst attempting "
1511-
"to kmalloc [%zd] bytes\n", __func__,
1512-
filename->encrypted_filename_size);
15131508
rc = -ENOMEM;
15141509
goto out;
15151510
}
@@ -1658,8 +1653,6 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name,
16581653
(*key_tfm) = tmp_tfm;
16591654
if (!tmp_tfm) {
16601655
rc = -ENOMEM;
1661-
printk(KERN_ERR "Error attempting to allocate from "
1662-
"ecryptfs_key_tfm_cache\n");
16631656
goto out;
16641657
}
16651658
mutex_init(&tmp_tfm->key_tfm_mutex);
@@ -1934,9 +1927,6 @@ int ecryptfs_encrypt_and_encode_filename(
19341927

19351928
filename = kzalloc(sizeof(*filename), GFP_KERNEL);
19361929
if (!filename) {
1937-
printk(KERN_ERR "%s: Out of memory whilst attempting "
1938-
"to kzalloc [%zd] bytes\n", __func__,
1939-
sizeof(*filename));
19401930
rc = -ENOMEM;
19411931
goto out;
19421932
}
@@ -1965,9 +1955,6 @@ int ecryptfs_encrypt_and_encode_filename(
19651955
+ encoded_name_no_prefix_size);
19661956
(*encoded_name) = kmalloc((*encoded_name_size) + 1, GFP_KERNEL);
19671957
if (!(*encoded_name)) {
1968-
printk(KERN_ERR "%s: Out of memory whilst attempting "
1969-
"to kzalloc [%zd] bytes\n", __func__,
1970-
(*encoded_name_size));
19711958
rc = -ENOMEM;
19721959
kfree(filename->encrypted_filename);
19731960
kfree(filename);
@@ -2049,9 +2036,6 @@ int ecryptfs_decode_and_decrypt_filename(char **plaintext_name,
20492036
name, name_size);
20502037
decoded_name = kmalloc(decoded_name_size, GFP_KERNEL);
20512038
if (!decoded_name) {
2052-
printk(KERN_ERR "%s: Out of memory whilst attempting "
2053-
"to kmalloc [%zd] bytes\n", __func__,
2054-
decoded_name_size);
20552039
rc = -ENOMEM;
20562040
goto out;
20572041
}

‎fs/ecryptfs/inode.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,6 @@ static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
334334

335335
dentry_info = kmem_cache_alloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
336336
if (!dentry_info) {
337-
printk(KERN_ERR "%s: Out of memory whilst attempting "
338-
"to allocate ecryptfs_dentry_info struct\n",
339-
__func__);
340337
dput(lower_dentry);
341338
return ERR_PTR(-ENOMEM);
342339
}

‎fs/ecryptfs/keystore.c‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,9 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
639639
int rc = 0;
640640

641641
s = kzalloc(sizeof(*s), GFP_KERNEL);
642-
if (!s) {
643-
printk(KERN_ERR "%s: Out of memory whilst trying to kmalloc "
644-
"[%zd] bytes of kernel memory\n", __func__, sizeof(*s));
642+
if (!s)
645643
return -ENOMEM;
646-
}
644+
647645
(*packet_size) = 0;
648646
rc = ecryptfs_find_auth_tok_for_sig(
649647
&auth_tok_key,
@@ -714,9 +712,6 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
714712
s->block_aligned_filename = kzalloc(s->block_aligned_filename_size,
715713
GFP_KERNEL);
716714
if (!s->block_aligned_filename) {
717-
printk(KERN_ERR "%s: Out of kernel memory whilst attempting to "
718-
"kzalloc [%zd] bytes\n", __func__,
719-
s->block_aligned_filename_size);
720715
rc = -ENOMEM;
721716
goto out_unlock;
722717
}
@@ -769,10 +764,6 @@ ecryptfs_write_tag_70_packet(char *dest, size_t *remaining_bytes,
769764
s->hash_desc = kmalloc(sizeof(*s->hash_desc) +
770765
crypto_shash_descsize(s->hash_tfm), GFP_KERNEL);
771766
if (!s->hash_desc) {
772-
printk(KERN_ERR "%s: Out of kernel memory whilst attempting to "
773-
"kmalloc [%zd] bytes\n", __func__,
774-
sizeof(*s->hash_desc) +
775-
crypto_shash_descsize(s->hash_tfm));
776767
rc = -ENOMEM;
777768
goto out_release_free_unlock;
778769
}
@@ -925,11 +916,9 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
925916
(*filename_size) = 0;
926917
(*filename) = NULL;
927918
s = kzalloc(sizeof(*s), GFP_KERNEL);
928-
if (!s) {
929-
printk(KERN_ERR "%s: Out of memory whilst trying to kmalloc "
930-
"[%zd] bytes of kernel memory\n", __func__, sizeof(*s));
919+
if (!s)
931920
return -ENOMEM;
932-
}
921+
933922
if (max_packet_size < ECRYPTFS_TAG_70_MIN_METADATA_SIZE) {
934923
printk(KERN_WARNING "%s: max_packet_size is [%zd]; it must be "
935924
"at least [%d]\n", __func__, max_packet_size,
@@ -1015,9 +1004,6 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
10151004
s->decrypted_filename = kmalloc(s->block_aligned_filename_size,
10161005
GFP_KERNEL);
10171006
if (!s->decrypted_filename) {
1018-
printk(KERN_ERR "%s: Out of memory whilst attempting to "
1019-
"kmalloc [%zd] bytes\n", __func__,
1020-
s->block_aligned_filename_size);
10211007
rc = -ENOMEM;
10221008
goto out_unlock;
10231009
}
@@ -1097,9 +1083,6 @@ ecryptfs_parse_tag_70_packet(char **filename, size_t *filename_size,
10971083
}
10981084
(*filename) = kmalloc(((*filename_size) + 1), GFP_KERNEL);
10991085
if (!(*filename)) {
1100-
printk(KERN_ERR "%s: Out of memory whilst attempting to "
1101-
"kmalloc [%zd] bytes\n", __func__,
1102-
((*filename_size) + 1));
11031086
rc = -ENOMEM;
11041087
goto out_free_unlock;
11051088
}
@@ -2525,11 +2508,9 @@ int ecryptfs_add_keysig(struct ecryptfs_crypt_stat *crypt_stat, char *sig)
25252508
struct ecryptfs_key_sig *new_key_sig;
25262509

25272510
new_key_sig = kmem_cache_alloc(ecryptfs_key_sig_cache, GFP_KERNEL);
2528-
if (!new_key_sig) {
2529-
printk(KERN_ERR
2530-
"Error allocating from ecryptfs_key_sig_cache\n");
2511+
if (!new_key_sig)
25312512
return -ENOMEM;
2532-
}
2513+
25332514
memcpy(new_key_sig->keysig, sig, ECRYPTFS_SIG_SIZE_HEX);
25342515
new_key_sig->keysig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
25352516
/* Caller must hold keysig_list_mutex */
@@ -2551,8 +2532,6 @@ ecryptfs_add_global_auth_tok(struct ecryptfs_mount_crypt_stat *mount_crypt_stat,
25512532
GFP_KERNEL);
25522533
if (!new_auth_tok) {
25532534
rc = -ENOMEM;
2554-
printk(KERN_ERR "Error allocating from "
2555-
"ecryptfs_global_auth_tok_cache\n");
25562535
goto out;
25572536
}
25582537
memcpy(new_auth_tok->sig, sig, ECRYPTFS_SIG_SIZE_HEX);

‎fs/ecryptfs/messaging.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ ecryptfs_spawn_daemon(struct ecryptfs_daemon **daemon, struct file *file)
147147
(*daemon) = kzalloc(sizeof(**daemon), GFP_KERNEL);
148148
if (!(*daemon)) {
149149
rc = -ENOMEM;
150-
printk(KERN_ERR "%s: Failed to allocate [%zd] bytes of "
151-
"GFP_KERNEL memory\n", __func__, sizeof(**daemon));
152150
goto out;
153151
}
154152
(*daemon)->file = file;
@@ -250,8 +248,6 @@ int ecryptfs_process_response(struct ecryptfs_daemon *daemon,
250248
msg_ctx->msg = kmemdup(msg, msg_size, GFP_KERNEL);
251249
if (!msg_ctx->msg) {
252250
rc = -ENOMEM;
253-
printk(KERN_ERR "%s: Failed to allocate [%zd] bytes of "
254-
"GFP_KERNEL memory\n", __func__, msg_size);
255251
goto unlock;
256252
}
257253
msg_ctx->state = ECRYPTFS_MSG_CTX_STATE_DONE;
@@ -386,7 +382,6 @@ int __init ecryptfs_init_messaging(void)
386382
GFP_KERNEL);
387383
if (!ecryptfs_daemon_hash) {
388384
rc = -ENOMEM;
389-
printk(KERN_ERR "%s: Failed to allocate memory\n", __func__);
390385
mutex_unlock(&ecryptfs_daemon_hash_mux);
391386
goto out;
392387
}
@@ -398,7 +393,6 @@ int __init ecryptfs_init_messaging(void)
398393
GFP_KERNEL);
399394
if (!ecryptfs_msg_ctx_arr) {
400395
rc = -ENOMEM;
401-
printk(KERN_ERR "%s: Failed to allocate memory\n", __func__);
402396
goto out;
403397
}
404398
mutex_init(&ecryptfs_msg_ctx_lists_mux);

‎fs/ecryptfs/miscdev.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,8 @@ int ecryptfs_send_miscdev(char *data, size_t data_size,
163163
struct ecryptfs_message *msg;
164164

165165
msg = kmalloc((sizeof(*msg) + data_size), GFP_KERNEL);
166-
if (!msg) {
167-
printk(KERN_ERR "%s: Out of memory whilst attempting "
168-
"to kmalloc(%zd, GFP_KERNEL)\n", __func__,
169-
(sizeof(*msg) + data_size));
166+
if (!msg)
170167
return -ENOMEM;
171-
}
172168

173169
mutex_lock(&msg_ctx->mux);
174170
msg_ctx->msg = msg;

‎fs/ecryptfs/mmap.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ static int ecryptfs_write_inode_size_to_xattr(struct inode *ecryptfs_inode)
431431
}
432432
xattr_virt = kmem_cache_alloc(ecryptfs_xattr_cache, GFP_KERNEL);
433433
if (!xattr_virt) {
434-
printk(KERN_ERR "Out of memory whilst attempting to write "
435-
"inode size to xattr\n");
436434
rc = -ENOMEM;
437435
goto out;
438436
}

0 commit comments

Comments
 (0)