Skip to content

Commit

Permalink
gcc-10: avoid shadowing standard library 'free()' in crypto commit 1a…
Browse files Browse the repository at this point in the history
…263ae60b04de959d9ce9caea4889385eefcc7b upstream.

gcc-10 has started warning about conflicting types for a few new
built-in functions, particularly 'free()'.

This results in warnings like:

   crypto/xts.c:325:13: warning: conflicting types for built-in function �free�; expected �void(void *)� [-Wbuiltin-declaration-mismatch]

because the crypto layer had its local freeing functions called
'free()'.

Gcc-10 is in the wrong here, since that function is marked 'static', and
thus there is no chance of confusion with any standard library function
namespace.

But the simplest thing to do is to just use a different name here, and
avoid this gcc mis-feature.

[ Side note: gcc knowing about 'free()' is in itself not the
  mis-feature: the semantics of 'free()' are special enough that a
  compiler can validly do special things when seeing it.

  So the mis-feature here is that gcc thinks that 'free()' is some
  restricted name, and you can't shadow it as a local static function.

  Making the special 'free()' semantics be a function attribute rather
  than tied to the name would be the much better model ]

Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: engstk <[email protected]>
  • Loading branch information
torvalds authored and engstk committed Jun 18, 2020
1 parent 58b8728 commit e9b37b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crypto/lrw.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ static void exit_tfm(struct crypto_skcipher *tfm)
crypto_free_skcipher(ctx->child);
}

static void free(struct skcipher_instance *inst)
static void free_inst(struct skcipher_instance *inst)
{
crypto_drop_skcipher(skcipher_instance_ctx(inst));
kfree(inst);
Expand Down Expand Up @@ -565,7 +565,7 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.encrypt = encrypt;
inst->alg.decrypt = decrypt;

inst->free = free;
inst->free = free_inst;

err = skcipher_register_instance(tmpl, inst);
if (err)
Expand Down
4 changes: 2 additions & 2 deletions crypto/xts.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static void exit_tfm(struct crypto_skcipher *tfm)
crypto_free_cipher(ctx->tweak);
}

static void free(struct skcipher_instance *inst)
static void free_inst(struct skcipher_instance *inst)
{
crypto_drop_skcipher(skcipher_instance_ctx(inst));
kfree(inst);
Expand Down Expand Up @@ -504,7 +504,7 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.encrypt = encrypt;
inst->alg.decrypt = decrypt;

inst->free = free;
inst->free = free_inst;

err = skcipher_register_instance(tmpl, inst);
if (err)
Expand Down

0 comments on commit e9b37b0

Please sign in to comment.