mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] FIT: compare key name hint with streq_ptr for clarity
@ 2025-10-10  5:49 Ahmad Fatoum
  2025-10-10  8:45 ` Marco Felsch
  2025-10-20 13:30 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-10-10  5:49 UTC (permalink / raw)
  To: barebox; +Cc: jre, Ahmad Fatoum

When given a key name hint, we first attempt verification using the key
it describes and fall through to verifying with all other keys.

The code implementing this is not necessarily intuitive and strcmp()
makes it harder to understand.

As we check for NULL pointer anyway, let's use streq_ptr, which returns
true instead of 0 on equality.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/image-fit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/image-fit.c b/common/image-fit.c
index 6b44a79e9d1c..3017ccb5048f 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -290,7 +290,8 @@ static int fit_check_signature(struct fit_handle *handle, struct device_node *si
 	for_each_public_key(key) {
 		fail_reason = "verification failed";
 
-		if (key_name && !strcmp(key->key_name_hint, key_name))
+		/* Don't recheck with same key as before */
+		if (streq_ptr(key->key_name_hint, key_name))
 			continue;
 
 		ret = public_key_verify(key, sig_value, sig_len, hash, algo);
-- 
2.47.3




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] FIT: compare key name hint with streq_ptr for clarity
  2025-10-10  5:49 [PATCH] FIT: compare key name hint with streq_ptr for clarity Ahmad Fatoum
@ 2025-10-10  8:45 ` Marco Felsch
  2025-10-20 13:30 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Marco Felsch @ 2025-10-10  8:45 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, jre

On 25-10-10, Ahmad Fatoum wrote:
> When given a key name hint, we first attempt verification using the key
> it describes and fall through to verifying with all other keys.
> 
> The code implementing this is not necessarily intuitive and strcmp()
> makes it harder to understand.
> 
> As we check for NULL pointer anyway, let's use streq_ptr, which returns
> true instead of 0 on equality.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>

Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>

> ---
>  common/image-fit.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/common/image-fit.c b/common/image-fit.c
> index 6b44a79e9d1c..3017ccb5048f 100644
> --- a/common/image-fit.c
> +++ b/common/image-fit.c
> @@ -290,7 +290,8 @@ static int fit_check_signature(struct fit_handle *handle, struct device_node *si
>  	for_each_public_key(key) {
>  		fail_reason = "verification failed";
>  
> -		if (key_name && !strcmp(key->key_name_hint, key_name))
> +		/* Don't recheck with same key as before */
> +		if (streq_ptr(key->key_name_hint, key_name))
>  			continue;
>  
>  		ret = public_key_verify(key, sig_value, sig_len, hash, algo);
> -- 
> 2.47.3
> 
> 
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] FIT: compare key name hint with streq_ptr for clarity
  2025-10-10  5:49 [PATCH] FIT: compare key name hint with streq_ptr for clarity Ahmad Fatoum
  2025-10-10  8:45 ` Marco Felsch
@ 2025-10-20 13:30 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-10-20 13:30 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: jre


On Fri, 10 Oct 2025 07:49:33 +0200, Ahmad Fatoum wrote:
> When given a key name hint, we first attempt verification using the key
> it describes and fall through to verifying with all other keys.
> 
> The code implementing this is not necessarily intuitive and strcmp()
> makes it harder to understand.
> 
> As we check for NULL pointer anyway, let's use streq_ptr, which returns
> true instead of 0 on equality.
> 
> [...]

Applied, thanks!

[1/1] FIT: compare key name hint with streq_ptr for clarity
      https://git.pengutronix.de/cgit/barebox/commit/?id=3138d4988d33 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-20 13:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-10  5:49 [PATCH] FIT: compare key name hint with streq_ptr for clarity Ahmad Fatoum
2025-10-10  8:45 ` Marco Felsch
2025-10-20 13:30 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox