Skip to contentSkip to conversation

ecryptfs: use kasprintf in ecryptfs_crypto_api_algify_cipher_name

PATCH In review Thorsten Blum 2 participants 3 messages May 18 – Jun 4 Ecrypt file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ecryptfs: use kasprintf in ecryptfs_crypto_api_algify_cipher_name

Use kasprintf() to simplify ecryptfs_crypto_api_algify_cipher_name().

Use const char * for the read-only cipher name and chaining modifier while at it.

---
 fs/ecryptfs/crypto.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
fs/ecryptfs/crypto.c +7 -17
index 5ef67b2674ee..74b02b55e3f6 100644
@@ -49,25 +49,15 @@ void ecryptfs_from_hex(char *dst, char *src, int dst_size)
 }
 
 static int ecryptfs_crypto_api_algify_cipher_name(char **algified_name,
-						  char *cipher_name,
-						  char *chaining_modifier)
+						  const char *cipher_name,
+						  const char *chaining_modifier)
 {
-	int cipher_name_len = strlen(cipher_name);
-	int chaining_modifier_len = strlen(chaining_modifier);
-	int algified_name_len;
-	int rc;
+	(*algified_name) = kasprintf(GFP_KERNEL, "%s(%s)", chaining_modifier,
+				     cipher_name);
+	if (!(*algified_name))
+		return -ENOMEM;
 
-	algified_name_len = (chaining_modifier_len + cipher_name_len + 3);
-	(*algified_name) = kmalloc(algified_name_len, GFP_KERNEL);
-	if (!(*algified_name)) {
-		rc = -ENOMEM;
-		goto out;
-	}
-	snprintf((*algified_name), algified_name_len, "%s(%s)",
-		 chaining_modifier, cipher_name);
-	rc = 0;
-out:
-	return rc;
+	return 0;
 }
 
 /**
#1 lore raw

Gentle ping?

Quoted 47 lines · Thorsten Blum

Use kasprintf() to simplify ecryptfs_crypto_api_algify_cipher_name().

Use const char * for the read-only cipher name and chaining modifier while at it.

---
 fs/ecryptfs/crypto.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
fs/ecryptfs/crypto.c +7 -17
index 5ef67b2674ee..74b02b55e3f6 100644
@@ -49,25 +49,15 @@ void ecryptfs_from_hex(char *dst, char *src, int dst_size)
 }
 
 static int ecryptfs_crypto_api_algify_cipher_name(char **algified_name,
-						  char *cipher_name,
-						  char *chaining_modifier)
+						  const char *cipher_name,
+						  const char *chaining_modifier)
 {
-	int cipher_name_len = strlen(cipher_name);
-	int chaining_modifier_len = strlen(chaining_modifier);
-	int algified_name_len;
-	int rc;
+	(*algified_name) = kasprintf(GFP_KERNEL, "%s(%s)", chaining_modifier,
+				     cipher_name);
+	if (!(*algified_name))
+		return -ENOMEM;
 
-	algified_name_len = (chaining_modifier_len + cipher_name_len + 3);
-	(*algified_name) = kmalloc(algified_name_len, GFP_KERNEL);
-	if (!(*algified_name)) {
-		rc = -ENOMEM;
-		goto out;
-	}
-	snprintf((*algified_name), algified_name_len, "%s(%s)",
-		 chaining_modifier, cipher_name);
-	rc = 0;
-out:
-	return rc;
+	return 0;
 }
 
 /**
maintainer
#2 lore raw
In reply to Thorsten Blum
Quoted 4 lines · Thorsten Blum

Use kasprintf() to simplify ecryptfs_crypto_api_algify_cipher_name().

Use const char * for the read-only cipher name and chaining modifier while at it.

Thank you! This has been applied to the next branch of the tyhicks/ecryptfs.git tree.

You can find a direct link below but please be aware that the commit hash is unstable and, therefore, the URL may not be valid in the future.

[1/1] ecryptfs: use kasprintf in ecryptfs_crypto_api_algify_cipher_name

      https://git.kernel.org/tyhicks/ecryptfs/c/95ce5ffd54cf66098f91892f98606c3bd33846fe

Tyler