Commit 252670c4 authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann

Bluetooth: Fix sparse warning in amp.c

This fixes the following sparse warning:

net/bluetooth/amp.c:152:53: warning: Variable length array is used.

The warning itself is probably harmless since this kind of usage of
shash_desc is present also in other places in the kernel (there's even a
convenience macro SHASH_DESC_ON_STACK available for defining such stack
variables). However, dynamically allocated versions are also used in
several places of the kernel (e.g. kernel/kexec.c and lib/digsig.c)
which have the benefit of not exhibiting the sparse warning.

Since there are no more sparse warnings in the Bluetooth subsystem after
fixing this one it is now easier to spot whenever new ones might get
introduced by future patches.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent f7cb96f1
...@@ -134,6 +134,7 @@ struct hci_conn *phylink_add(struct hci_dev *hdev, struct amp_mgr *mgr, ...@@ -134,6 +134,7 @@ struct hci_conn *phylink_add(struct hci_dev *hdev, struct amp_mgr *mgr,
static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output) static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
{ {
struct crypto_shash *tfm; struct crypto_shash *tfm;
struct shash_desc *shash;
int ret; int ret;
if (!ksize) if (!ksize)
...@@ -148,18 +149,24 @@ static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output) ...@@ -148,18 +149,24 @@ static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
ret = crypto_shash_setkey(tfm, key, ksize); ret = crypto_shash_setkey(tfm, key, ksize);
if (ret) { if (ret) {
BT_DBG("crypto_ahash_setkey failed: err %d", ret); BT_DBG("crypto_ahash_setkey failed: err %d", ret);
} else { goto failed;
char desc[sizeof(struct shash_desc) + }
crypto_shash_descsize(tfm)] CRYPTO_MINALIGN_ATTR;
struct shash_desc *shash = (struct shash_desc *)desc; shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(tfm),
GFP_KERNEL);
if (!shash) {
ret = -ENOMEM;
goto failed;
}
shash->tfm = tfm; shash->tfm = tfm;
shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP; shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
ret = crypto_shash_digest(shash, plaintext, psize, ret = crypto_shash_digest(shash, plaintext, psize, output);
output);
} kfree(shash);
failed:
crypto_free_shash(tfm); crypto_free_shash(tfm);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment