Skip to contentSkip to conversation

ASoC: cs-amp-lib-test: Fix some NULL vs IS_ERR() bugs

PATCH In review Dan Carpenter 2 participants 4 messages Apr 23

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: cs-amp-lib-test: Fix some NULL vs IS_ERR() bugs

The cs_amp_devm_get_vendor_specific_variant_id() function doesn't return NULL, it returns error pointers. Update the checking to match.

Fixes d70fa6b569a9 ("ASoC: cs-amp-lib-test: Tests for reading SSIDExV2")
---
 sound/soc/codecs/cs-amp-lib-test.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sound/soc/codecs/cs-amp-lib-test.c +4 -4
index 636d0f3198b8..bb0cfd9d5db2 100644
@@ -2360,7 +2360,7 @@ static void cs_amp_lib_test_ssidexv2_fetch_invalid(struct kunit *test)
 				   cs_amp_lib_test_get_efi_vendor_sysid);
 
 	got = cs_amp_devm_get_vendor_specific_variant_id(dev, PCI_VENDOR_ID_DELL, 0xabcd);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
 	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
 }
 
@@ -2376,7 +2376,7 @@ static void cs_amp_lib_test_ssidexv2_not_dell(struct kunit *test)
 
 	/* Not returned if SSID vendor is not Dell */
 	got = cs_amp_devm_get_vendor_specific_variant_id(dev, PCI_VENDOR_ID_CIRRUS, 0xabcd);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
 	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
 }
 
@@ -2391,11 +2391,11 @@ static void cs_amp_lib_test_vendor_variant_id_not_found(struct kunit *test)
 				   cs_amp_lib_test_get_efi_variable_none);
 
 	got = cs_amp_devm_get_vendor_specific_variant_id(dev, PCI_VENDOR_ID_DELL, 0xabcd);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
 	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
 
 	got = cs_amp_devm_get_vendor_specific_variant_id(dev, -1, -1);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
 	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
 }
 
Signature · 1 line
2.53.0
#1 lore raw
Quoted 14 lines · Dan Carpenter

The cs_amp_devm_get_vendor_specific_variant_id() function doesn't return NULL, it returns error pointers. Update the checking to match.

Fixes d70fa6b569a9 ("ASoC: cs-amp-lib-test: Tests for reading SSIDExV2")
---
  sound/soc/codecs/cs-amp-lib-test.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
sound/soc/codecs/cs-amp-lib-test.c +0 -0
index 636d0f3198b8..bb0cfd9d5db2 100644

sound/soc/codecs/cs-amp-lib-test.c static void cs_amp_lib_test_ssidexv2_fetch_invalid(struct kunit *test) · line 2365

Quoted 7 lines
sound/soc/codecs/cs-amp-lib-test.c +1 -1
@@ -2360,7 +2360,7 @@ static void cs_amp_lib_test_ssidexv2_fetch_invalid(struct kunit *test)
  				   cs_amp_lib_test_get_efi_vendor_sysid);
 
  	got = cs_amp_devm_get_vendor_specific_variant_id(dev, PCI_VENDOR_ID_DELL, 0xabcd);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
  	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
  }

No, this is incorrect because we are expecting to get -ENOENT but now it will fail the KUNIT_EXPECT_NOT_ERR_OR_NULL() and not proceed to the next line where we assert that we got the expected error.

The asserts are:
1. It should never return NULL (because it returns ERR_PTRs)
2. It should return ERR_PTR(-ENOENT)

The same for the cases below.

Quoted 24 lines
sound/soc/codecs/cs-amp-lib-test.c +3 -3
@@ -2376,7 +2376,7 @@ static void cs_amp_lib_test_ssidexv2_not_dell(struct kunit *test)
 
  	/* Not returned if SSID vendor is not Dell */
  	got = cs_amp_devm_get_vendor_specific_variant_id(dev, PCI_VENDOR_ID_CIRRUS, 0xabcd);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
  	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
  }
 
@@ -2391,11 +2391,11 @@ static void cs_amp_lib_test_vendor_variant_id_not_found(struct kunit *test)
  				   cs_amp_lib_test_get_efi_variable_none);
 
  	got = cs_amp_devm_get_vendor_specific_variant_id(dev, PCI_VENDOR_ID_DELL, 0xabcd);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
  	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
 
  	got = cs_amp_devm_get_vendor_specific_variant_id(dev, -1, -1);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
  	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
  }
 
#2 lore raw
Quoted 10 lines · Richard Fitzgerald
Quoted 9 lines · Dan Carpenter

The cs_amp_devm_get_vendor_specific_variant_id() function doesn't return NULL, it returns error pointers.  Update the checking to match.

Fixes d70fa6b569a9 ("ASoC: cs-amp-lib-test: Tests for reading SSIDExV2")

---
  sound/soc/codecs/cs-amp-lib-test.c | 8 ++++----

  1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 17 lines

sound/soc/codecs/cs-amp-lib-test.c static void · line 2365

Quoted 12 lines
sound/soc/codecs/cs-amp-lib-test.c +1 -1
index 636d0f3198b8..bb0cfd9d5db2 100644
@@ -2360,7 +2360,7 @@ static void 
 cs_amp_lib_test_ssidexv2_fetch_invalid(struct kunit *test)
                      cs_amp_lib_test_get_efi_vendor_sysid);
       got = cs_amp_devm_get_vendor_specific_variant_id(dev, PCI_VENDOR_ID_DELL, 0xabcd);
-    KUNIT_EXPECT_NOT_NULL(test, got);
+    KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
       KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
   }

No, this is incorrect because we are expecting to get -ENOENT but now it will fail the KUNIT_EXPECT_NOT_ERR_OR_NULL() and not proceed to the next line where we assert that we got the expected error.

Slight correction. It will proceed to the next line because it's an EXPECT not an ASSERT. But it had a false fail from the KUNIT_EXPECT_NOT_ERR_OR_NULL().

Quoted 5 lines

The asserts are:
1. It should never return NULL (because it returns ERR_PTRs)
2. It should return ERR_PTR(-ENOENT)

The same for the cases below.

#3 lore raw
In reply to Richard Fitzgerald
Quoted 26 lines · Richard Fitzgerald
Quoted 14 lines · Dan Carpenter

The cs_amp_devm_get_vendor_specific_variant_id() function doesn't return NULL, it returns error pointers. Update the checking to match.

Fixes d70fa6b569a9 ("ASoC: cs-amp-lib-test: Tests for reading SSIDExV2")
---
  sound/soc/codecs/cs-amp-lib-test.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
sound/soc/codecs/cs-amp-lib-test.c +0 -0
index 636d0f3198b8..bb0cfd9d5db2 100644

sound/soc/codecs/cs-amp-lib-test.c static void cs_amp_lib_test_ssidexv2_fetch_invalid(struct kunit *test) · line 2364

Quoted 6 lines
sound/soc/codecs/cs-amp-lib-test.c +1 -1
@@ -2360,7 +2360,7 @@ static void cs_amp_lib_test_ssidexv2_fetch_invalid(struct kunit *test)
  				   cs_amp_lib_test_get_efi_vendor_sysid);
  	got = cs_amp_devm_get_vendor_specific_variant_id(dev, PCI_VENDOR_ID_DELL, 0xabcd);
-	KUNIT_EXPECT_NOT_NULL(test, got);
+	KUNIT_EXPECT_NOT_ERR_OR_NULL(test, got);
  	KUNIT_EXPECT_EQ(test, PTR_ERR_OR_ZERO(got), -ENOENT);
  }

No, this is incorrect because we are expecting to get -ENOENT but now it will fail the KUNIT_EXPECT_NOT_ERR_OR_NULL() and not proceed to the next line where we assert that we got the expected error.

Quoted 4 lines

The asserts are:
1. It should never return NULL (because it returns ERR_PTRs)
2. It should return ERR_PTR(-ENOENT)

Ah... Ok. Thanks.

regards,
dan carpenter