diff --git a/security/security.c b/security/security.c
index 6e149d0ffe333934c9efb628183df7f40082990d..b49ee810371bee5891f9ebe5fc2f091f1fe2e442 100644
--- a/security/security.c
+++ b/security/security.c
@@ -118,6 +118,8 @@ static int lsm_append(char *new, char **result)
 
 	if (*result == NULL) {
 		*result = kstrdup(new, GFP_KERNEL);
+		if (*result == NULL)
+			return -ENOMEM;
 	} else {
 		/* Check if it is the last registered name */
 		if (match_last_lsm(*result, new))