[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <A0C349D1-C7FA-40C6-971B-910122B1AAE1@linux.dev>
Date: Sun, 12 Oct 2025 15:23:02 +0200
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: Lukas Wunner <lukas@...ner.de>
Cc: David Howells <dhowells@...hat.com>,
Ignat Korchagin <ignat@...udflare.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
"David S. Miller" <davem@...emloft.net>,
keyrings@...r.kernel.org,
linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] crypto: asymmetric_keys - simplify
asymmetric_key_hex_to_key_id
On 12. Oct 2025, at 14:10, Lukas Wunner wrote:
> On Tue, Oct 07, 2025 at 08:52:21PM +0200, Thorsten Blum wrote:
>> Use struct_size() to calculate the number of bytes to allocate for the
>> asymmetric key id.
>
> Why? To what end? To guard against an overflow?
I find struct_size() to be more readable because it explicitly
communicates the relationship between the flexible array member 'data'
and 'asciihexlen / 2', which the open-coded version doesn't.
'sizeof(struct asymmetric_key_id) + asciihexlen / 2' works because the
flexible array 'data' is an unsigned char (1 byte). This will probably
never change, but struct_size() would still work even if it did change
to a data type that isn't exactly 1 byte.
Additionally, struct_size() has some extra compile-time checks (e.g.,
__must_be_array()).
>> - ret = __asymmetric_key_hex_to_key_id(id, match_id, asciihexlen / 2);
>> - if (ret < 0) {
>> + if (__asymmetric_key_hex_to_key_id(id, match_id, hexlen) < 0) {
>> kfree(match_id);
>> return ERR_PTR(-EINVAL);
>> }
>
> If anything, return ret instead of removing the ret variable.
> The only negative return value of __asymmetric_key_hex_to_key_id()
> is -EINVAL, hence that's returned directly here.
Ok, I'll change this in v2.
Thanks,
Thorsten
Powered by blists - more mailing lists