mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
cxl/test: Simplify fw_buf_checksum_show()
First, just use sha256() instead of a sequence of sha256_init(), sha256_update(), and sha256_final(). The result is the same. Second, use *phN instead of open-coding the conversion of bytes to hex. Acked-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20250630160645.3198-3-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
@@ -1828,27 +1828,10 @@ static ssize_t fw_buf_checksum_show(struct device *dev,
|
||||
{
|
||||
struct cxl_mockmem_data *mdata = dev_get_drvdata(dev);
|
||||
u8 hash[SHA256_DIGEST_SIZE];
|
||||
unsigned char *hstr, *hptr;
|
||||
struct sha256_state sctx;
|
||||
ssize_t written = 0;
|
||||
int i;
|
||||
|
||||
sha256_init(&sctx);
|
||||
sha256_update(&sctx, mdata->fw, mdata->fw_size);
|
||||
sha256_final(&sctx, hash);
|
||||
sha256(mdata->fw, mdata->fw_size, hash);
|
||||
|
||||
hstr = kzalloc((SHA256_DIGEST_SIZE * 2) + 1, GFP_KERNEL);
|
||||
if (!hstr)
|
||||
return -ENOMEM;
|
||||
|
||||
hptr = hstr;
|
||||
for (i = 0; i < SHA256_DIGEST_SIZE; i++)
|
||||
hptr += sprintf(hptr, "%02x", hash[i]);
|
||||
|
||||
written = sysfs_emit(buf, "%s\n", hstr);
|
||||
|
||||
kfree(hstr);
|
||||
return written;
|
||||
return sysfs_emit(buf, "%*phN\n", SHA256_DIGEST_SIZE, hash);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR_RO(fw_buf_checksum);
|
||||
|
||||
Reference in New Issue
Block a user