Skip to content

Commit c5391c0

Browse files
elfringMikulas Patocka
authored andcommitted
dm-crypt: Use up_read() together with key_put() only once in crypt_set_keyring_key()
The combination of the calls “up_read(&key->sem)” and “key_put(key)” was immediately used after a return code check for a set_key() call in this function implementation. Thus use such a function call pair only once instead directly before the check. This issue was transformed by using the Coccinelle software. Signed-off-by: Markus Elfring <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]>
1 parent c8691cd commit c5391c0

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

drivers/md/dm-crypt.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,16 +2621,13 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string
26212621
down_read(&key->sem);
26222622

26232623
ret = set_key(cc, key);
2624+
up_read(&key->sem);
2625+
key_put(key);
26242626
if (ret < 0) {
2625-
up_read(&key->sem);
2626-
key_put(key);
26272627
kfree_sensitive(new_key_string);
26282628
return ret;
26292629
}
26302630

2631-
up_read(&key->sem);
2632-
key_put(key);
2633-
26342631
/* clear the flag since following operations may invalidate previously valid key */
26352632
clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
26362633

0 commit comments

Comments
 (0)