Skip to contentSkip to conversation

security: keyring: remove redundant NULL check

PATCH In review Davidlohr Bueso 2 participants 2 messages Jan 24, 2011 – Jan 25, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 security: keyring: remove redundant NULL check

From: Davidlohr Bueso <[email protected]>
Date: Sun, 23 Jan 2011 22:01:20 -0300

---
 security/keys/keyring.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
security/keys/keyring.c +4 -5
index d37f713..cb8110b 100644
@@ -866,11 +866,10 @@ void __key_link_end(struct key *keyring, struct key_type *type,
 	if (type == &key_type_keyring)
 		up_write(&keyring_serialise_link_sem);
 
-	if (prealloc) {
-		kfree(prealloc);
-		key_payload_reserve(keyring,
-				    keyring->datalen - KEYQUOTA_LINK_BYTES);
-	}
+	kfree(prealloc);
+	key_payload_reserve(keyring,
+			keyring->datalen - KEYQUOTA_LINK_BYTES);
+
 	up_write(&keyring->sem);
 }
 
Signature · 1 line
1.7.1
maintainer
#1 lore raw

security/keys/keyring.c void __key_link_end(struct key *keyring, struct key_type *type, · line 872

Quoted 9 lines · Davidlohr Bueso
security/keys/keyring.c +4 -5
-	if (prealloc) {
-		kfree(prealloc);
-		key_payload_reserve(keyring,
-				    keyring->datalen - KEYQUOTA_LINK_BYTES);
-	}
+	kfree(prealloc);
+	key_payload_reserve(keyring,
+			keyring->datalen - KEYQUOTA_LINK_BYTES);
+

This is not correct, since you'd be removing the quota allocation for the new link in the case that __key_link() was called (and cleared *_prealloc).

However, the upstream code isn't correct either, since the preallocation may not have extended the reservation at all (if it decided to displace a key rather than adding a key).

David