Skip to contentSkip to conversation

smb: use crypto_shash_digest() in symlink_hash()

PATCH In review Eric Biggers 3 participants 3 messages Oct 29, 2023 – Oct 31, 2023

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

PATCH 1/1 smb: use crypto_shash_digest() in symlink_hash()

From: Eric Biggers <[email protected]>

Simplify symlink_hash() by using crypto_shash_digest() instead of an init+update+final sequence. This should also improve performance.

---
 fs/smb/client/link.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
fs/smb/client/link.c +2 -14
index c66be4904e1f..a1da50e66fbb 100644
@@ -35,37 +35,25 @@
 #define CIFS_MF_SYMLINK_MD5_ARGS(md5_hash) md5_hash
 
 static int
 symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
 {
 	int rc;
 	struct shash_desc *md5 = NULL;
 
 	rc = cifs_alloc_hash("md5", &md5);
 	if (rc)
-		goto symlink_hash_err;
+		return rc;
 
-	rc = crypto_shash_init(md5);
-	if (rc) {
-		cifs_dbg(VFS, "%s: Could not init md5 shash\n", __func__);
-		goto symlink_hash_err;
-	}
-	rc = crypto_shash_update(md5, link_str, link_len);
-	if (rc) {
-		cifs_dbg(VFS, "%s: Could not update with link_str\n", __func__);
-		goto symlink_hash_err;
-	}
-	rc = crypto_shash_final(md5, md5_hash);
+	rc = crypto_shash_digest(md5, link_str, link_len, md5_hash);
 	if (rc)
 		cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
-
-symlink_hash_err:
 	cifs_free_hash(&md5);
 	return rc;
 }
 
 static int
 parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len,
 		 char **_link_str)
 {
 	int rc;
 	unsigned int link_len;

base-commit: 2af9b20dbb39f6ebf9b9b6c090271594627d818e

Signature · 1 line
2.42.0
#1 lore raw

tentatively merged into cifs-2.6.git for-next pending additional testing

Quoted 60 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Simplify symlink_hash() by using crypto_shash_digest() instead of an init+update+final sequence. This should also improve performance.

---
 fs/smb/client/link.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
fs/smb/client/link.c +2 -14
index c66be4904e1f..a1da50e66fbb 100644
@@ -35,37 +35,25 @@
 #define CIFS_MF_SYMLINK_MD5_ARGS(md5_hash) md5_hash
 
 static int
 symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
 {
        int rc;
        struct shash_desc *md5 = NULL;
 
        rc = cifs_alloc_hash("md5", &md5);
        if (rc)
-               goto symlink_hash_err;
+               return rc;
 
-       rc = crypto_shash_init(md5);
-       if (rc) {
-               cifs_dbg(VFS, "%s: Could not init md5 shash\n", __func__);
-               goto symlink_hash_err;
-       }
-       rc = crypto_shash_update(md5, link_str, link_len);
-       if (rc) {
-               cifs_dbg(VFS, "%s: Could not update with link_str\n", __func__);
-               goto symlink_hash_err;
-       }
-       rc = crypto_shash_final(md5, md5_hash);
+       rc = crypto_shash_digest(md5, link_str, link_len, md5_hash);
        if (rc)
                cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
-
-symlink_hash_err:
        cifs_free_hash(&md5);
        return rc;
 }
 
 static int
 parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len,
                 char **_link_str)
 {
        int rc;
        unsigned int link_len;

base-commit: 2af9b20dbb39f6ebf9b9b6c090271594627d818e --
2.42.0

Signature · 3 lines
Thanks,

Steve
Reviewed-by on v1 1/1
#2 lore raw
In reply to Eric Biggers

fs/smb/client/link.c

Quoted 14 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Simplify symlink_hash() by using crypto_shash_digest() instead of an init+update+final sequence. This should also improve performance.

---
 fs/smb/client/link.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
fs/smb/client/link.c +0 -0
index c66be4904e1f..a1da50e66fbb 100644