From 5dda6992a3138f3839dcaecbcd2fbea4dd514c7c Mon Sep 17 00:00:00 2001 From: Michael Halcrow Date: Tue, 16 Oct 2007 01:28:06 -0700 Subject: eCryptfs: remove assignments in if-statements Remove assignments in if-statements. Signed-off-by: Michael Halcrow Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/ecryptfs/crypto.c | 17 ++++++++------- fs/ecryptfs/file.c | 8 ++++--- fs/ecryptfs/inode.c | 35 ++++++++++++++++++------------- fs/ecryptfs/keystore.c | 55 +++++++++++++++++++++++++++---------------------- fs/ecryptfs/main.c | 28 +++++++++++++++---------- fs/ecryptfs/messaging.c | 5 +++-- fs/ecryptfs/mmap.c | 5 +++-- 7 files changed, 89 insertions(+), 64 deletions(-) (limited to 'fs') diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 9127b809044d..e3d2118fafad 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -1277,8 +1277,8 @@ static int ecryptfs_read_header_region(char *data, struct dentry *dentry, mm_segment_t oldfs; int rc; - if ((rc = ecryptfs_open_lower_file(&lower_file, dentry, mnt, - O_RDONLY))) { + rc = ecryptfs_open_lower_file(&lower_file, dentry, mnt, O_RDONLY); + if (rc) { printk(KERN_ERR "Error opening lower_file to read header region\n"); goto out; @@ -1289,7 +1289,8 @@ static int ecryptfs_read_header_region(char *data, struct dentry *dentry, rc = lower_file->f_op->read(lower_file, (char __user *)data, ECRYPTFS_DEFAULT_EXTENT_SIZE, &lower_file->f_pos); set_fs(oldfs); - if ((rc = ecryptfs_close_lower_file(lower_file))) { + rc = ecryptfs_close_lower_file(lower_file); + if (rc) { printk(KERN_ERR "Error closing lower_file\n"); goto out; } @@ -1951,9 +1952,10 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name, strncpy(tmp_tfm->cipher_name, cipher_name, ECRYPTFS_MAX_CIPHER_NAME_SIZE); tmp_tfm->key_size = key_size; - if ((rc = ecryptfs_process_key_cipher(&tmp_tfm->key_tfm, - tmp_tfm->cipher_name, - &tmp_tfm->key_size))) { + rc = ecryptfs_process_key_cipher(&tmp_tfm->key_tfm, + tmp_tfm->cipher_name, + &tmp_tfm->key_size); + if (rc) { printk(KERN_ERR "Error attempting to initialize key TFM " "cipher with name = [%s]; rc = [%d]\n", tmp_tfm->cipher_name, rc); @@ -1988,7 +1990,8 @@ int ecryptfs_get_tfm_and_mutex_for_cipher_name(struct crypto_blkcipher **tfm, } } mutex_unlock(&key_tfm_list_mutex); - if ((rc = ecryptfs_add_new_key_tfm(&key_tfm, cipher_name, 0))) { + rc = ecryptfs_add_new_key_tfm(&key_tfm, cipher_name, 0); + if (rc) { printk(KERN_ERR "Error adding new key_tfm to list; rc = [%d]\n", rc); goto out; diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 12ba7e3a69f9..59c846d29a8e 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c @@ -230,8 +230,9 @@ static int ecryptfs_open(struct inode *inode, struct file *file) lower_flags &= ~O_APPEND; lower_mnt = ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry); /* Corresponding fput() in ecryptfs_release() */ - if ((rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt, - lower_flags))) { + rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt, + lower_flags); + if (rc) { ecryptfs_printk(KERN_ERR, "Error opening lower file\n"); goto out_puts; } @@ -300,7 +301,8 @@ static int ecryptfs_release(struct inode *inode, struct file *file) struct inode *lower_inode = ecryptfs_inode_to_lower(inode); int rc; - if ((rc = ecryptfs_close_lower_file(lower_file))) { + rc = ecryptfs_close_lower_file(lower_file); + if (rc) { printk(KERN_ERR "Error closing lower_file\n"); goto out; } diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index abac91c58bfb..d70f5994ba51 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c @@ -202,8 +202,9 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) lower_flags = ((O_CREAT | O_TRUNC) & O_ACCMODE) | O_RDWR; lower_mnt = ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry); /* Corresponding fput() at end of this function */ - if ((rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt, - lower_flags))) { + rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt, + lower_flags); + if (rc) { ecryptfs_printk(KERN_ERR, "Error opening dentry; rc = [%i]\n", rc); goto out; @@ -229,7 +230,8 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) } rc = grow_file(ecryptfs_dentry, lower_file, inode, lower_inode); out_fput: - if ((rc = ecryptfs_close_lower_file(lower_file))) + rc = ecryptfs_close_lower_file(lower_file); + if (rc) printk(KERN_ERR "Error closing lower_file\n"); out: return rc; @@ -779,8 +781,9 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) lower_dentry = ecryptfs_dentry_to_lower(dentry); /* This dget & mntget is released through fput at out_fput: */ lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); - if ((rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt, - O_RDWR))) { + rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt, + O_RDWR); + if (rc) { ecryptfs_printk(KERN_ERR, "Error opening dentry; rc = [%i]\n", rc); goto out_free; @@ -813,11 +816,12 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) end_pos_in_page = ((new_length - 1) & ~PAGE_CACHE_MASK); } if (end_pos_in_page != (PAGE_CACHE_SIZE - 1)) { - if ((rc = ecryptfs_write_zeros(&fake_ecryptfs_file, - index, - (end_pos_in_page + 1), - ((PAGE_CACHE_SIZE - 1) - - end_pos_in_page)))) { + rc = ecryptfs_write_zeros(&fake_ecryptfs_file, + index, + (end_pos_in_page + 1), + ((PAGE_CACHE_SIZE - 1) + - end_pos_in_page)); + if (rc) { printk(KERN_ERR "Error attempting to zero out " "the remainder of the end page on " "reducing truncate; rc = [%d]\n", rc); @@ -849,7 +853,8 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) = CURRENT_TIME; mark_inode_dirty_sync(inode); out_fput: - if ((rc = ecryptfs_close_lower_file(lower_file))) + rc = ecryptfs_close_lower_file(lower_file); + if (rc) printk(KERN_ERR "Error closing lower_file\n"); out_free: if (ecryptfs_file_to_private(&fake_ecryptfs_file)) @@ -917,8 +922,9 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); lower_flags = O_RDONLY; - if ((rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, - lower_mnt, lower_flags))) { + rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, + lower_mnt, lower_flags); + if (rc) { printk(KERN_ERR "Error opening lower file; rc = [%d]\n", rc); mutex_unlock(&crypt_stat->cs_mutex); @@ -926,7 +932,8 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) } mount_crypt_stat = &ecryptfs_superblock_to_private( dentry->d_sb)->mount_crypt_stat; - if ((rc = ecryptfs_read_metadata(dentry, lower_file))) { + rc = ecryptfs_read_metadata(dentry, lower_file); + if (rc) { if (!(mount_crypt_stat->flags & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { rc = -EIO; diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c index 09e2340ab783..89d9710dd63d 100644 --- a/fs/ecryptfs/keystore.c +++ b/fs/ecryptfs/keystore.c @@ -436,7 +436,8 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok, size_t netlink_message_length; int rc; - if ((rc = ecryptfs_get_auth_tok_sig(&auth_tok_sig, auth_tok))) { + rc = ecryptfs_get_auth_tok_sig(&auth_tok_sig, auth_tok); + if (rc) { printk(KERN_ERR "Unrecognized auth tok type: [%d]\n", auth_tok->token_type); goto out; @@ -569,8 +570,9 @@ parse_tag_1_packet(struct ecryptfs_crypt_stat *crypt_stat, goto out; } (*new_auth_tok) = &auth_tok_list_item->auth_tok; - if ((rc = parse_packet_length(&data[(*packet_size)], &body_size, - &length_size))) { + rc = parse_packet_length(&data[(*packet_size)], &body_size, + &length_size); + if (rc) { printk(KERN_WARNING "Error parsing packet length; " "rc = [%d]\n", rc); goto out_free; @@ -702,8 +704,9 @@ parse_tag_3_packet(struct ecryptfs_crypt_stat *crypt_stat, goto out; } (*new_auth_tok) = &auth_tok_list_item->auth_tok; - if ((rc = parse_packet_length(&data[(*packet_size)], &body_size, - &length_size))) { + rc = parse_packet_length(&data[(*packet_size)], &body_size, + &length_size); + if (rc) { printk(KERN_WARNING "Error parsing packet length; rc = [%d]\n", rc); goto out_free; @@ -849,8 +852,9 @@ parse_tag_11_packet(unsigned char *data, unsigned char *contents, rc = -EINVAL; goto out; } - if ((rc = parse_packet_length(&data[(*packet_size)], &body_size, - &length_size))) { + rc = parse_packet_length(&data[(*packet_size)], &body_size, + &length_size); + if (rc) { printk(KERN_WARNING "Invalid tag 11 packet format\n"); goto out; } @@ -1052,9 +1056,10 @@ decrypt_passphrase_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok, crypt_stat->cipher, rc); goto out; } - if ((rc = virt_to_scatterlist(auth_tok->session_key.encrypted_key, - auth_tok->session_key.encrypted_key_size, - &src_sg, 1)) != 1) { + rc = virt_to_scatterlist(auth_tok->session_key.encrypted_key, + auth_tok->session_key.encrypted_key_size, + &src_sg, 1); + if (rc != 1) { printk(KERN_ERR "Internal error whilst attempting to convert " "auth_tok->session_key.encrypted_key to scatterlist; " "expected rc = 1; got rc = [%d]. " @@ -1064,9 +1069,10 @@ decrypt_passphrase_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok, } auth_tok->session_key.decrypted_key_size = auth_tok->session_key.encrypted_key_size; - if ((rc = virt_to_scatterlist(auth_tok->session_key.decrypted_key, - auth_tok->session_key.decrypted_key_size, - &dst_sg, 1)) != 1) { + rc = virt_to_scatterlist(auth_tok->session_key.decrypted_key, + auth_tok->session_key.decrypted_key_size, + &dst_sg, 1); + if (rc != 1) { printk(KERN_ERR "Internal error whilst attempting to convert " "auth_tok->session_key.decrypted_key to scatterlist; " "expected rc = 1; got rc = [%d]\n", rc); @@ -1236,18 +1242,17 @@ find_next_matching_auth_tok: "Considering cadidate auth tok:\n"); ecryptfs_dump_auth_tok(candidate_auth_tok); } - if ((rc = ecryptfs_get_auth_tok_sig(&candidate_auth_tok_sig, - candidate_auth_tok))) { + rc = ecryptfs_get_auth_tok_sig(&candidate_auth_tok_sig, + candidate_auth_tok); + if (rc) { printk(KERN_ERR "Unrecognized candidate auth tok type: [%d]\n", candidate_auth_tok->token_type); rc = -EINVAL; goto out_wipe_list; } - if ((rc = ecryptfs_find_auth_tok_for_sig( - &matching_auth_tok, crypt_stat, - candidate_auth_tok_sig))) - rc = 0; + ecryptfs_find_auth_tok_for_sig(&matching_auth_tok, crypt_stat, + candidate_auth_tok_sig); if (matching_auth_tok) { found_auth_tok = 1; goto found_matching_auth_tok; @@ -1605,9 +1610,9 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes, ecryptfs_printk(KERN_DEBUG, "Session key encryption key:\n"); ecryptfs_dump_hex(session_key_encryption_key, 16); } - if ((rc = virt_to_scatterlist(crypt_stat->key, - key_rec->enc_key_size, &src_sg, 1)) - != 1) { + rc = virt_to_scatterlist(crypt_stat->key, key_rec->enc_key_size, + &src_sg, 1); + if (rc != 1) { ecryptfs_printk(KERN_ERR, "Error generating scatterlist " "for crypt_stat session key; expected rc = 1; " "got rc = [%d]. key_rec->enc_key_size = [%d]\n", @@ -1615,9 +1620,9 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes, rc = -ENOMEM; goto out; } - if ((rc = virt_to_scatterlist(key_rec->enc_key, - key_rec->enc_key_size, &dst_sg, 1)) - != 1) { + rc = virt_to_scatterlist(key_rec->enc_key, key_rec->enc_key_size, + &dst_sg, 1); + if (rc != 1) { ecryptfs_printk(KERN_ERR, "Error generating scatterlist " "for crypt_stat encrypted session key; " "expected rc = 1; got rc = [%d]. " diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index d4f00bbbcdc5..00686f1c5997 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c @@ -188,10 +188,11 @@ static int ecryptfs_init_global_auth_toks( list_for_each_entry(global_auth_tok, &mount_crypt_stat->global_auth_tok_list, mount_crypt_stat_list) { - if ((rc = ecryptfs_keyring_auth_tok_for_sig( - &global_auth_tok->global_auth_tok_key, - &global_auth_tok->global_auth_tok, - global_auth_tok->sig))) { + rc = ecryptfs_keyring_auth_tok_for_sig( + &global_auth_tok->global_auth_tok_key, + &global_auth_tok->global_auth_tok, + global_auth_tok->sig); + if (rc) { printk(KERN_ERR "Could not find valid key in user " "session keyring for sig specified in mount " "option: [%s]\n", global_auth_tok->sig); @@ -355,9 +356,10 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options) if (!cipher_key_bytes_set) { mount_crypt_stat->global_default_cipher_key_size = 0; } - if ((rc = ecryptfs_add_new_key_tfm( - NULL, mount_crypt_stat->global_default_cipher_name, - mount_crypt_stat->global_default_cipher_key_size))) { + rc = ecryptfs_add_new_key_tfm( + NULL, mount_crypt_stat->global_default_cipher_name, + mount_crypt_stat->global_default_cipher_key_size); + if (rc) { printk(KERN_ERR "Error attempting to initialize cipher with " "name = [%s] and key size = [%td]; rc = [%d]\n", mount_crypt_stat->global_default_cipher_name, @@ -365,7 +367,8 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options) rc = -EINVAL; goto out; } - if ((rc = ecryptfs_init_global_auth_toks(mount_crypt_stat))) { + rc = ecryptfs_init_global_auth_toks(mount_crypt_stat); + if (rc) { printk(KERN_WARNING "One or more global auth toks could not " "properly register; rc = [%d]\n", rc); } @@ -458,7 +461,8 @@ static int ecryptfs_read_super(struct super_block *sb, const char *dev_name) sb->s_maxbytes = lower_root->d_sb->s_maxbytes; ecryptfs_set_dentry_lower(sb->s_root, lower_root); ecryptfs_set_dentry_lower_mnt(sb->s_root, lower_mnt); - if ((rc = ecryptfs_interpose(lower_root, sb->s_root, sb, 0))) + rc = ecryptfs_interpose(lower_root, sb->s_root, sb, 0); + if (rc) goto out_free; rc = 0; goto out; @@ -765,7 +769,8 @@ static int do_sysfs_registration(void) { int rc; - if ((rc = subsystem_register(&ecryptfs_subsys))) { + rc = subsystem_register(&ecryptfs_subsys); + if (rc) { printk(KERN_ERR "Unable to register ecryptfs sysfs subsystem\n"); goto out; @@ -796,7 +801,8 @@ static void do_sysfs_unregistration(void) { int rc; - if ((rc = ecryptfs_destroy_crypto())) { + rc = ecryptfs_destroy_crypto(); + if (rc) { printk(KERN_ERR "Failure whilst attempting to destroy crypto; " "rc = [%d]\n", rc); } diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c index a9d87c47f72d..a96d341d154d 100644 --- a/fs/ecryptfs/messaging.c +++ b/fs/ecryptfs/messaging.c @@ -419,8 +419,9 @@ int ecryptfs_init_messaging(unsigned int transport) } mutex_init(&ecryptfs_daemon_id_hash_mux); mutex_lock(&ecryptfs_daemon_id_hash_mux); - ecryptfs_hash_buckets = 0; - while (ecryptfs_number_of_users >> ++ecryptfs_hash_buckets); + ecryptfs_hash_buckets = 1; + while (ecryptfs_number_of_users >> ecryptfs_hash_buckets) + ecryptfs_hash_buckets++; ecryptfs_daemon_id_hash = kmalloc(sizeof(struct hlist_head) * ecryptfs_hash_buckets, GFP_KERNEL); if (!ecryptfs_daemon_id_hash) { diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c index 89dbbbbcce07..307f7ee77420 100644 --- a/fs/ecryptfs/mmap.c +++ b/fs/ecryptfs/mmap.c @@ -762,8 +762,9 @@ ecryptfs_write_zeros(struct file *file, pgoff_t index, int start, int num_zeros) rc = PTR_ERR(tmp_page); goto out; } - if ((rc = ecryptfs_prepare_write_no_truncate(file, tmp_page, start, - (start + num_zeros)))) { + rc = ecryptfs_prepare_write_no_truncate(file, tmp_page, start, + (start + num_zeros)); + if (rc) { ecryptfs_printk(KERN_ERR, "Error preparing to write zero's " "to page at index [0x%.16x]\n", index); -- cgit v1.2.3