Skip to contentSkip to conversation

test: fix a couple NULL vs IS_ERR() checks

PATCH In review Dan Carpenter 3 participants 3 messages Jul 31, 2023 – Aug 9, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: fix a couple NULL vs IS_ERR() checks

The x509_cert_parse() and pkcs7_parse_message() functions return error pointers. They don't return NULL. Update the checks accordingly.

---
 test/lib/asn1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/lib/asn1.c +2 -2
index 8661fdd30687..a66cdd77df0a 100644
@@ -120,7 +120,7 @@ static int lib_asn1_x509(struct unit_test_state *uts)
 
 	cert = x509_cert_parse(cert_data, cert_data_len);
 
-	ut_assertf(cert != NULL, "decoding failed\n");
+	ut_assertf(!IS_ERR(cert), "decoding failed\n");
 	ut_assertf(!strcmp(cert->subject, "Linaro: Tester"),
 		   "subject doesn't match\n");
 	ut_assertf(!strcmp(cert->issuer, "Linaro: Tester"),
@@ -313,7 +313,7 @@ static int lib_asn1_pkcs7(struct unit_test_state *uts)
 
 	pkcs7 = pkcs7_parse_message(image_pk7, image_pk7_len);
 
-	ut_assertf(pkcs7 != NULL, "decoding failed\n");
+	ut_assertf(!IS_ERR(pkcs7), "decoding failed\n");
 	ut_assertf(pkcs7->data_len == 104, "signature size doesn't match\n");
 	ut_assertf(pkcs7->signed_infos != NULL, "sign-info doesn't exist\n");
 	ut_assertf(pkcs7->signed_infos->msgdigest_len == 32,
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw

Hi Dan,

Quoted 9 lines · Dan Carpenter

The x509_cert_parse() and pkcs7_parse_message() functions return error pointers. They don't return NULL. Update the checks accordingly.

---
 test/lib/asn1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

test/lib/asn1.c static int lib_asn1_x509(struct unit_test_state *uts) · line 123

Quoted 10 lines
test/lib/asn1.c +1 -1
index 8661fdd30687..a66cdd77df0a 100644
@@ -120,7 +120,7 @@ static int lib_asn1_x509(struct unit_test_state *uts)
 
        cert = x509_cert_parse(cert_data, cert_data_len);
 
-       ut_assertf(cert != NULL, "decoding failed\n");
+       ut_assertf(!IS_ERR(cert), "decoding failed\n");

But how about creating ut_assertnoerr() or something like that?

Quoted 13 lines
test/lib/asn1.c +1 -2
        ut_assertf(!strcmp(cert->subject, "Linaro: Tester"),
                   "subject doesn't match\n");
        ut_assertf(!strcmp(cert->issuer, "Linaro: Tester"),
@@ -313,7 +313,7 @@ static int lib_asn1_pkcs7(struct unit_test_state *uts)
 
        pkcs7 = pkcs7_parse_message(image_pk7, image_pk7_len);
 
-       ut_assertf(pkcs7 != NULL, "decoding failed\n");
+       ut_assertf(!IS_ERR(pkcs7), "decoding failed\n");
        ut_assertf(pkcs7->data_len == 104, "signature size doesn't match\n");
        ut_assertf(pkcs7->signed_infos != NULL, "sign-info doesn't exist\n");
        ut_assertf(pkcs7->signed_infos->msgdigest_len == 32,
--
Quoted 2 lines

2.39.2

Regards,
Simon