This continues from this commit: 52f5684c8e1e ("kernel: use macros from compiler.h instead of __attribute__((...))")
PATCH 1/1 This continues from this commit: 52f5684c8e1e ("kernel: use macros from compiler.h instead of __attribute__((...))")
From: Gideon Israel Dsouza <[email protected]>
Very sorry about the previous broken patch. Here is an updated one.
I submitted 4 total patches. They are part of task I've taken up to increase compiler portability in the kernel. I've cleaned up the subsystems under /kernel /mm /block and /security, this patch targets /crypto.
There is <linux/compiler.h> which provides macros for various gcc specific constructs. Eg: __weak for __attribute__((weak)). I've cleaned all instances of gcc specific attributes with the right macros for the crypto subsystem.
I had to make one additional change into compiler-gcc.h for the case when one wants to use this: __attribute__((aligned) and not specify an alignment factor. From the gcc docs, this will result in the largest alignment for that data type on the target machine so I've named the macro __aligned_largest. Please advise if another name is more appropriate.
RFC: There are many places where __attribute((unused)) is used. There are two macros for the exact same macro inside compiler-gcc.h:__always_unused and __maybe_unused. I'm not sure which to have used to replace instances inside /crypto. Should there perhaps be just an unused macro. There are 1830 instances of __maybe_unused inside the kernel code and 110 uses of__always_unused excluding my changes.
--- crypto/ablkcipher.c | 5 +++-- crypto/acompress.c | 3 ++- crypto/aead.c | 3 ++- crypto/ahash.c | 3 ++- crypto/akcipher.c | 3 ++- crypto/blkcipher.c | 7 ++++--- crypto/cts.c | 5 +++-- crypto/kpp.c | 3 ++- crypto/pcbc.c | 3 ++- crypto/rng.c | 3 ++- crypto/scompress.c | 3 ++- crypto/shash.c | 9 +++++---- crypto/skcipher.c | 3 ++- include/linux/compiler-gcc.h | 1 + 14 files changed, 34 insertions(+), 20 deletions(-)
crypto/ablkcipher.c +3 -2
@@ -19,6 +19,7 @@#include <linux/slab.h> #include <linux/seq_file.h> #include <linux/cryptouser.h> +#include <linux/compiler.h> #include <net/netlink.h> #include <crypto/scatterwalk.h>
@@ -394,7 +395,7 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_ablkcipher_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_ablkcipher_show (struct seq_file *m,struct crypto_alg *alg) {struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
@@ -468,7 +469,7 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_givcipher_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_givcipher_show (struct seq_file *m,struct crypto_alg *alg) {struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
crypto/acompress.c +2 -1
@@ -20,6 +20,7 @@#include <linux/crypto.h> #include <crypto/algapi.h> #include <linux/cryptouser.h> +#include <linux/compiler.h> #include <net/netlink.h> #include <crypto/internal/acompress.h> #include <crypto/internal/scompress.h>
@@ -50,7 +51,7 @@ static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_acomp_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_acomp_show (struct seq_file *m,struct crypto_alg *alg) {
crypto/aead.c +2 -1
@@ -24,6 +24,7 @@#include <linux/slab.h> #include <linux/seq_file.h> #include <linux/cryptouser.h> +#include <linux/compiler.h> #include <net/netlink.h> #include "internal.h"
@@ -132,7 +133,7 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_aead_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_aead_show (struct seq_file *m,struct crypto_alg *alg) { struct aead_alg *aead = container_of(alg, struct aead_alg, base);
crypto/ahash.c +2 -1
@@ -23,6 +23,7 @@#include <linux/slab.h> #include <linux/seq_file.h> #include <linux/cryptouser.h> +#include <linux/compiler.h> #include <net/netlink.h> #include "internal.h"
@@ -493,7 +494,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_ahash_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_ahash_show (struct seq_file *m,struct crypto_alg *alg) {seq_printf (m,"type : ahash\n" );
crypto/akcipher.c +2 -1
@@ -17,6 +17,7 @@#include <linux/slab.h> #include <linux/string.h> #include <linux/crypto.h> +#include <linux/compiler.h> #include <crypto/algapi.h> #include <linux/cryptouser.h> #include <net/netlink.h>
@@ -47,7 +48,7 @@ static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_akcipher_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_akcipher_show (struct seq_file *m,struct crypto_alg *alg) {
crypto/blkcipher.c +4 -3
@@ -1,6 +1,6 @@/* * Block chaining cipher operations. -* +* * Generic encrypt/decrypt wrapper for ciphers, handles operations across * multiple page boundaries by using temporary blocks. In user context, * the kernel is given a chance to schedule us once per page.
@@ -9,7 +9,7 @@* * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free -* Software Foundation; either version 2 of the License, or (at your option) +* Software Foundation; either version 2 of the License, or (at your option) * any later version. * */
@@ -25,6 +25,7 @@#include <linux/slab.h> #include <linux/string.h> #include <linux/cryptouser.h> +#include <linux/compiler.h> #include <net/netlink.h> #include "internal.h"
@@ -534,7 +535,7 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_blkcipher_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_blkcipher_show (struct seq_file *m,struct crypto_alg *alg) {seq_printf (m,"type : blkcipher\n" );
crypto/cts.c +3 -2
@@ -49,6 +49,7 @@#include <linux/scatterlist.h> #include <crypto/scatterwalk.h> #include <linux/slab.h> +#include <linux/compiler.h> struct crypto_cts_ctx {struct crypto_skcipher *child;
@@ -103,7 +104,7 @@ static int cts_cbc_encrypt(struct skcipher_request *req)struct crypto_skcipher *tfm =crypto_skcipher_reqtfm (req);struct skcipher_request *subreq = &rctx->subreq;int bsize =crypto_skcipher_blocksize (tfm); - u8 d[bsize * 2] __attribute__ ((aligned(__alignof__(u32)))); +u8 d[bsize *2 ]__aligned(__alignof__(u32)) ;struct scatterlist *sg;unsigned int offset;int lastn;
@@ -183,7 +184,7 @@ static int cts_cbc_decrypt(struct skcipher_request *req)struct crypto_skcipher *tfm =crypto_skcipher_reqtfm (req);struct skcipher_request *subreq = &rctx->subreq;int bsize =crypto_skcipher_blocksize (tfm); - u8 d[bsize * 2] __attribute__ ((aligned(__alignof__(u32)))); +u8 d[bsize *2 ]__aligned(__alignof__(u32)) ;struct scatterlist *sg;unsigned int offset;u8 *space;
crypto/kpp.c +2 -1
@@ -19,6 +19,7 @@#include <linux/crypto.h> #include <crypto/algapi.h> #include <linux/cryptouser.h> +#include <linux/compiler.h> #include <net/netlink.h> #include <crypto/kpp.h> #include <crypto/internal/kpp.h>
@@ -47,7 +48,7 @@ static int crypto_kpp_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_kpp_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_kpp_show (struct seq_file *m,struct crypto_alg *alg) {
crypto/pcbc.c +2 -1
@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/compiler.h> struct crypto_pcbc_ctx {struct crypto_cipher *child;
@@ -146,7 +147,7 @@ static int crypto_pcbc_decrypt_inplace(struct skcipher_request *req,unsigned int nbytes = walk->nbytes;u8 *src = walk->src.virt.addr;u8 *iv = walk->iv; - u8 tmpbuf[bsize] __attribute__ ((aligned(__alignof__(u32)))); +u8 tmpbuf[bsize]__aligned(__alignof__(u32)) ; do { memcpy(tmpbuf, src, bsize);
crypto/rng.c +2 -1
@@ -23,6 +23,7 @@#include <linux/slab.h> #include <linux/string.h> #include <linux/cryptouser.h> +#include <linux/compiler.h> #include <net/netlink.h> #include "internal.h"
@@ -95,7 +96,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_rng_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_rng_show (struct seq_file *m,struct crypto_alg *alg) {seq_printf (m,"type : rng\n" );
crypto/scompress.c +2 -1
@@ -18,6 +18,7 @@#include <linux/slab.h> #include <linux/string.h> #include <linux/crypto.h> +#include <linux/compiler.h> #include <linux/vmalloc.h> #include <crypto/algapi.h> #include <linux/cryptouser.h>
@@ -57,7 +58,7 @@ static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_scomp_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_scomp_show (struct seq_file *m,struct crypto_alg *alg) {
crypto/shash.c +5 -4
@@ -19,6 +19,7 @@#include <linux/seq_file.h> #include <linux/cryptouser.h> #include <net/netlink.h> +#include <linux/compiler.h> #include "internal.h"
@@ -67,7 +68,7 @@ EXPORT_SYMBOL_GPL(crypto_shash_setkey);static inline unsigned int shash_align_buffer_size (unsigned len,unsigned long mask) { - typedef u8 __attribute__ ((aligned)) u8_aligned; + typedef u8 __aligned_largest u8_aligned;return len + (mask & ~(__alignof__(u8_aligned ) -1 )); }
@@ -80,7 +81,7 @@ static int shash_update_unaligned(struct shash_desc *desc, const u8 *data,unsigned int unaligned_len = alignmask +1 - ((unsigned long )data & alignmask); u8 ubuf[shash_align_buffer_size(unaligned_len, alignmask)] - __attribute__ ((aligned)); + __aligned_largest;u8 *buf =PTR_ALIGN (&ubuf[0 ], alignmask +1 );int err;
@@ -116,7 +117,7 @@ static int shash_final_unaligned(struct shash_desc *desc, u8 *out)struct shash_alg *shash =crypto_shash_alg (tfm);unsigned int ds =crypto_shash_digestsize (tfm); u8 ubuf[shash_align_buffer_size(ds, alignmask)] - __attribute__ ((aligned)); + __aligned_largest;u8 *buf =PTR_ALIGN (&ubuf[0 ], alignmask +1 );int err;
@@ -403,7 +404,7 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_shash_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_shash_show (struct seq_file *m,struct crypto_alg *alg) {struct shash_alg *salg =__crypto_shash_alg (alg);
crypto/skcipher.c +2 -1
@@ -19,6 +19,7 @@#include <crypto/scatterwalk.h> #include <linux/bug.h> #include <linux/cryptouser.h> +#include <linux/compiler.h> #include <linux/list.h> #include <linux/module.h> #include <linux/rtnetlink.h>
@@ -807,7 +808,7 @@ static void crypto_skcipher_free_instance(struct crypto_instance *inst) }static void crypto_skcipher_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_skcipher_show (struct seq_file *m,struct crypto_alg *alg) { struct skcipher_alg *skcipher = container_of(alg, struct skcipher_alg,
include/linux/compiler-gcc.h +1 -0
@@ -116,6 +116,7 @@*/ #define __pure __attribute__((pure))#define __aligned (x) __attribute__((aligned(x))) +#define __aligned_largest __attribute__((aligned))#define __printf (a, b) __attribute__((format(printf, a, b)))#define __scanf (a, b) __attribute__((format(scanf, a, b)))#define __attribute_const__ __attribute__((__const__))
Signature · 1 line
2.7.4
Quoted 4 lines · On Sat, 2016-12-31 at 06:11 +0530, [email protected] wrote:
There is <
linux/compiler.h> which provides macros for various gcc specific constructs. Eg:__weakfor __attribute__((weak)). I've cleaned all instances of gcc specific attributes with the right macros for the crypto subsystem.
[]
crypto/ablkcipher.c
Quoted 1 line
crypto/ablkcipher.c +0
-0
[]
Quoted 10 lines
crypto/ablkcipher.c +1
-1@@ -394,7 +395,7 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_ablkcipher_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_ablkcipher_show (struct seq_file *m,struct crypto_alg *alg) {struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
crypto/ablkcipher.c static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg) · line 475
Quoted 8 lines
crypto/ablkcipher.c +1
-1@@ -468,7 +469,7 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_givcipher_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;static void crypto_givcipher_show (struct seq_file *m,struct crypto_alg *alg) {struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
Perhaps it'd be better to remove the declaration/prototype of crypto_ablkcipher_show and surround the definition of crypto_ablkcipher_show with #ifdef CONFIG_PROC_FS / #endif
[]
crypto/acompress.c
Quoted 1 line
crypto/acompress.c +0
-0
[]
crypto/acompress.c static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg) · line 54
Quoted 6 lines
crypto/acompress.c +1
-1@@ -50,7 +51,7 @@ static int crypto_acomp_report(struct sk_buff *skb, struct crypto_alg *alg)#endif static void crypto_acomp_show (struct seq_file *m,struct crypto_alg *alg) - __attribute__ ((unused)); +__always_unused ;
likewise and for others too.
Herbert Xu
maintainerQuoted 4 lines · Joe Perches
Perhaps it'd be better to remove the declaration/prototype of
crypto_ablkcipher_showand surround the definition ofcrypto_ablkcipher_showwith #ifdefCONFIG_PROC_FS/ #endif
No that's stupid. We want to maximise the compiler coverage.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 7 lines · Herbert Xu
Quoted 4 lines · Joe Perches
Perhaps it'd be better to remove the declaration/prototype of
crypto_ablkcipher_showand surround the definition ofcrypto_ablkcipher_showwith #ifdefCONFIG_PROC_FS/ #endifNo that's stupid. We want to maximise the compiler coverage.
stupid is rather a strong word for the most
common technique used in the kernel to avoid
compiler warnings.
Herbert Xu
maintainerQuoted 20 lines · On Sat, Dec 31, 2016 at 06:11:13AM +0530, [email protected] wrote:
From: Gideon Israel Dsouza <[email protected]>
Very sorry about the previous broken patch. Here is an updated one.
I submitted 4 total patches. They are part of task I've taken up to increase compiler portability in the kernel. I've cleaned up the subsystems under /kernel /mm /block and /security, this patch targets /crypto.
There is <
linux/compiler.h> which provides macros for various gcc specific constructs. Eg:__weakfor __attribute__((weak)). I've cleaned all instances of gcc specific attributes with the right macros for the crypto subsystem.I had to make one additional change into
compiler-gcc.hfor the case when one wants to use this: __attribute__((aligned) and not specify an alignment factor. From the gcc docs, this will result in the largest alignment for that data type on the target machine so I've named the macro__aligned_largest. Please advise if another name is more appropriate.
Quoted 8 lines
RFC: There are many places where __attribute((unused)) is used. There are two macros for the exact same macro inside
compiler-gcc.h:__always_unusedand__maybe_unused. I'm not sure which to have used to replace instances inside /crypto. Should there perhaps be just an unused macro. There are 1830 instances of__maybe_unusedinside the kernel code and 110 usesof__always_unusedexcluding my changes.Signed-off-by Gideon Israel Dsouza <[email protected]>
Please send crypto patches to [email protected].
Review
Quoted 3 lines
static void
crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)(quoted diff) +1
-1- __attribute__ ((unused)); + __always_unused;
You should use __maybe_unused.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt