Skip to content

Commit

Permalink
dm-crypt: Use up_read() together with key_put() only once in crypt_se…
Browse files Browse the repository at this point in the history
…t_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 <elfring@users.sourceforge.net>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
  • Loading branch information
Markus Elfring authored and Mikulas Patocka committed Sep 18, 2024
1 parent c8691cd commit c5391c0
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions drivers/md/dm-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2621,16 +2621,13 @@ static int crypt_set_keyring_key(struct crypt_config *cc, const char *key_string
down_read(&key->sem);

ret = set_key(cc, key);
up_read(&key->sem);
key_put(key);
if (ret < 0) {
up_read(&key->sem);
key_put(key);
kfree_sensitive(new_key_string);
return ret;
}

up_read(&key->sem);
key_put(key);

/* clear the flag since following operations may invalidate previously valid key */
clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);

Expand Down

0 comments on commit c5391c0

Please sign in to comment.