dm-crypt: Use up_read() together with key_put() only once in crypt_set_keyring_key()
authorMarkus Elfring <elfring@users.sourceforge.net>
Wed, 18 Sep 2024 13:05:29 +0000 (15:05 +0200)
committerMikulas Patocka <mpatocka@redhat.com>
Wed, 18 Sep 2024 16:10:40 +0000 (18:10 +0200)
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>
drivers/md/dm-crypt.c

index d5533b43054edb97f50c73c06a484c5902eacd0f..dae2fe3cb182d855fce981223ed4b4bfb950031e 100644 (file)
@@ -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);