]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
firmware_loader: use SHA-256 library API instead of crypto_shash API
authorEric Biggers <ebiggers@google.com>
Mon, 28 Apr 2025 19:09:09 +0000 (12:09 -0700)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 30 Apr 2025 19:55:54 +0000 (21:55 +0200)
This user of SHA-256 does not support any other algorithm, so the
crypto_shash abstraction provides no value.  Just use the SHA-256
library API instead, which is much simpler and easier to use.

Also take advantage of printk's built-in hex conversion using %*phN.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250428190909.852705-1-ebiggers@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/base/firmware_loader/Kconfig
drivers/base/firmware_loader/main.c

index a0370167426514222cd870865cf57c938333512a..752b9a9bea0388667e0cc1f20e2e2f6d5b388281 100644 (file)
@@ -3,8 +3,7 @@ menu "Firmware loader"
 
 config FW_LOADER
        tristate "Firmware loading facility" if EXPERT
-       select CRYPTO_HASH if FW_LOADER_DEBUG
-       select CRYPTO_SHA256 if FW_LOADER_DEBUG
+       select CRYPTO_LIB_SHA256 if FW_LOADER_DEBUG
        default y
        help
          This enables the firmware loading facility in the kernel. The kernel
@@ -28,7 +27,6 @@ config FW_LOADER
 
 config FW_LOADER_DEBUG
        bool "Log filenames and checksums for loaded firmware"
-       depends on CRYPTO = FW_LOADER || CRYPTO=y
        depends on DYNAMIC_DEBUG
        depends on FW_LOADER
        default FW_LOADER
index cb0912ea3e627e92f2009257314531981a279a92..44486b2c71728066dc263e1ecf3438ebbcb1d217 100644 (file)
@@ -806,41 +806,15 @@ static void fw_abort_batch_reqs(struct firmware *fw)
 }
 
 #if defined(CONFIG_FW_LOADER_DEBUG)
-#include <crypto/hash.h>
 #include <crypto/sha2.h>
 
 static void fw_log_firmware_info(const struct firmware *fw, const char *name, struct device *device)
 {
-       struct shash_desc *shash;
-       struct crypto_shash *alg;
-       u8 *sha256buf;
-       char *outbuf;
+       u8 digest[SHA256_DIGEST_SIZE];
 
-       alg = crypto_alloc_shash("sha256", 0, 0);
-       if (IS_ERR(alg))
-               return;
-
-       sha256buf = kmalloc(SHA256_DIGEST_SIZE, GFP_KERNEL);
-       outbuf = kmalloc(SHA256_BLOCK_SIZE + 1, GFP_KERNEL);
-       shash = kmalloc(sizeof(*shash) + crypto_shash_descsize(alg), GFP_KERNEL);
-       if (!sha256buf || !outbuf || !shash)
-               goto out_free;
-
-       shash->tfm = alg;
-
-       if (crypto_shash_digest(shash, fw->data, fw->size, sha256buf) < 0)
-               goto out_free;
-
-       for (int i = 0; i < SHA256_DIGEST_SIZE; i++)
-               sprintf(&outbuf[i * 2], "%02x", sha256buf[i]);
-       outbuf[SHA256_BLOCK_SIZE] = 0;
-       dev_dbg(device, "Loaded FW: %s, sha256: %s\n", name, outbuf);
-
-out_free:
-       kfree(shash);
-       kfree(outbuf);
-       kfree(sha256buf);
-       crypto_free_shash(alg);
+       sha256(fw->data, fw->size, digest);
+       dev_dbg(device, "Loaded FW: %s, sha256: %*phN\n",
+               name, SHA256_DIGEST_SIZE, digest);
 }
 #else
 static void fw_log_firmware_info(const struct firmware *fw, const char *name,