ecryptfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ecryptfs: Simplify ecryptfs_crypto_api_algify_cipher_name()
@ 2023-10-30 13:27 Christophe JAILLET
  2023-10-30 14:07 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2023-10-30 13:27 UTC (permalink / raw)
  To: Tyler Hicks; +Cc: linux-kernel, kernel-janitors, Christophe JAILLET, ecryptfs

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(-)

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;
 }
 
 /**
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ecryptfs: Simplify ecryptfs_crypto_api_algify_cipher_name()
  2023-10-30 13:27 [PATCH] ecryptfs: Simplify ecryptfs_crypto_api_algify_cipher_name() Christophe JAILLET
@ 2023-10-30 14:07 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2023-10-30 14:07 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: Tyler Hicks, linux-kernel, kernel-janitors, ecryptfs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-30 14:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30 13:27 [PATCH] ecryptfs: Simplify ecryptfs_crypto_api_algify_cipher_name() Christophe JAILLET
2023-10-30 14:07 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).