aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-11-10 08:53:45 -0500
committerMarcel Holtmann <marcel@holtmann.org>2014-11-10 18:07:29 -0500
commit252670c421c785127cb55db03c48df5feb57ce12 (patch)
tree6f00bac494584482810edd02d18cc29ec2b8ab30 /net
parentf7cb96f105fb406e8db5e68e0cdd5067e2556d34 (diff)
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: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/amp.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c
index 2640d78f30b8..ee016f039100 100644
--- a/net/bluetooth/amp.c
+++ b/net/bluetooth/amp.c
@@ -134,6 +134,7 @@ struct hci_conn *phylink_add(struct hci_dev *hdev, struct amp_mgr *mgr,
134static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output) 134static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
135{ 135{
136 struct crypto_shash *tfm; 136 struct crypto_shash *tfm;
137 struct shash_desc *shash;
137 int ret; 138 int ret;
138 139
139 if (!ksize) 140 if (!ksize)
@@ -148,18 +149,24 @@ static int hmac_sha256(u8 *key, u8 ksize, char *plaintext, u8 psize, u8 *output)
148 ret = crypto_shash_setkey(tfm, key, ksize); 149 ret = crypto_shash_setkey(tfm, key, ksize);
149 if (ret) { 150 if (ret) {
150 BT_DBG("crypto_ahash_setkey failed: err %d", ret); 151 BT_DBG("crypto_ahash_setkey failed: err %d", ret);
151 } else { 152 goto failed;
152 char desc[sizeof(struct shash_desc) + 153 }
153 crypto_shash_descsize(tfm)] CRYPTO_MINALIGN_ATTR;
154 struct shash_desc *shash = (struct shash_desc *)desc;
155
156 shash->tfm = tfm;
157 shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
158 154
159 ret = crypto_shash_digest(shash, plaintext, psize, 155 shash = kzalloc(sizeof(*shash) + crypto_shash_descsize(tfm),
160 output); 156 GFP_KERNEL);
157 if (!shash) {
158 ret = -ENOMEM;
159 goto failed;
161 } 160 }
162 161
162 shash->tfm = tfm;
163 shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
164
165 ret = crypto_shash_digest(shash, plaintext, psize, output);
166
167 kfree(shash);
168
169failed:
163 crypto_free_shash(tfm); 170 crypto_free_shash(tfm);
164 return ret; 171 return ret;
165} 172}