ecryptfs: Simplify ecryptfs_crypto_api_algify_cipher_name()

Message ID 2c4bd387e8036854d3338400038fdde8dce3806a.1698672391.git.christophe.jaillet@wanadoo.fr
State New
Headers
Series ecryptfs: Simplify ecryptfs_crypto_api_algify_cipher_name() |

Commit Message

Christophe JAILLET Oct. 30, 2023, 1:27 p.m. UTC
  Use kasprintf() instead of hand writing it.
It is much less verbose.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 fs/ecryptfs/crypto.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
  

Comments

Dan Carpenter Oct. 30, 2023, 2:07 p.m. UTC | #1
On Mon, Oct 30, 2023 at 02:27:32PM +0100, Christophe JAILLET wrote:
> Use kasprintf() instead of hand writing it.
> It is much less verbose.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>

regards,
dan carpenter
  

Patch

diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 044863c0d824..00d795658cf5 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -23,6 +23,7 @@ 
 #include <linux/slab.h>
 #include <asm/unaligned.h>
 #include <linux/kernel.h>
+#include <linux/sprintf.h>
 #include <linux/xattr.h>
 #include "ecryptfs_kernel.h"
 
@@ -78,22 +79,12 @@  static int ecryptfs_crypto_api_algify_cipher_name(char **algified_name,
 						  char *cipher_name,
 						  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;
 }
 
 /**