Skip to content

Commit 7b6092e

Browse files
nathanchanceherbertx
authored andcommitted
crypto: qce - revert "use __free() for a buffer that's always freed"
Commit ce8fd05 ("crypto: qce - use __free() for a buffer that's always freed") introduced a buggy use of __free(), which clang rightfully points out: drivers/crypto/qce/sha.c:365:3: error: cannot jump from this goto statement to its label 365 | goto err_free_ahash; | ^ drivers/crypto/qce/sha.c:373:6: note: jump bypasses initialization of variable with __attribute__((cleanup)) 373 | u8 *buf __free(kfree) = kzalloc(keylen + QCE_MAX_ALIGN_SIZE, | ^ Jumping over a variable declared with the cleanup attribute does not prevent the cleanup function from running; instead, the cleanup function is called with an uninitialized value. Moving the declaration back to the top function with __free() and a NULL initialization would resolve the bug but that is really not much different from the original code. Since the function is so simple and there is no functional reason to use __free() here, just revert the original change to resolve the issue. Fixes: ce8fd05 ("crypto: qce - use __free() for a buffer that's always freed") Reported-by: Linux Kernel Functional Testing <[email protected]> Closes: https://lore.kernel.org/CA+G9fYtpAwXa5mUQ5O7vDLK2xN4t-kJoxgUe1ZFRT=AGqmLSRA@mail.gmail.com/ Signed-off-by: Nathan Chancellor <[email protected]> Acked-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 472a989 commit 7b6092e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/crypto/qce/sha.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
44
*/
55

6-
#include <linux/cleanup.h>
76
#include <linux/device.h>
87
#include <linux/dma-mapping.h>
98
#include <linux/interrupt.h>
@@ -337,6 +336,7 @@ static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key,
337336
struct scatterlist sg;
338337
unsigned int blocksize;
339338
struct crypto_ahash *ahash_tfm;
339+
u8 *buf;
340340
int ret;
341341
const char *alg_name;
342342

@@ -370,8 +370,7 @@ static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key,
370370
crypto_req_done, &wait);
371371
crypto_ahash_clear_flags(ahash_tfm, ~0);
372372

373-
u8 *buf __free(kfree) = kzalloc(keylen + QCE_MAX_ALIGN_SIZE,
374-
GFP_KERNEL);
373+
buf = kzalloc(keylen + QCE_MAX_ALIGN_SIZE, GFP_KERNEL);
375374
if (!buf) {
376375
ret = -ENOMEM;
377376
goto err_free_req;
@@ -383,6 +382,7 @@ static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key,
383382

384383
ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
385384

385+
kfree(buf);
386386
err_free_req:
387387
ahash_request_free(req);
388388
err_free_ahash:

0 commit comments

Comments
 (0)