Skip to contentSkip to conversation

FIT: compare key name hint with streq_ptr for clarity

PATCH Applied Ahmad Fatoum 3 participants 3 messages Oct 10, 2025 – Oct 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 FIT: compare key name hint with streq_ptr for clarity

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.

---
 common/image-fit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
common/image-fit.c +2 -1
index 6b44a79e9d1c..3017ccb5048f 100644
@@ -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);
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · 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.

Quoted 23 lines
---
 common/image-fit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
common/image-fit.c +2 -1
index 6b44a79e9d1c..3017ccb5048f 100644
@@ -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);
Signature · 1 line
2.47.3
Applied
#2 lore raw
In reply to Ahmad Fatoum
Quoted 10 lines · 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.

[...]

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,

Signature · 1 line
Sascha Hauer <[email protected]>