Skip to contentSkip to conversation

zstd: Fix definition of assert()

PATCH In review Jonathan Neuschäfer 2 participants 3 messages Jan 29, 2023 – Mar 3, 2023 Zstd

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zstd: Fix definition of assert()

assert(x) should emit a warning if x is false. WARN_ON(x) emits a warning if x is true. Thus, assert(x) should be defined as WARN_ON(!x) rather than WARN_ON(x).

---

Commit e0c1b49f5b674 ("lib: zstd: Upgrade to latest upstream zstd version 1.4.10") mentions that the zstd code was generated from the upstream version of zstd, so perhaps the definition of assert based on WARN_ON should be fixed in the conversion script and/or upstream zstd source code.

---
 lib/zstd/common/zstd_deps.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/zstd/common/zstd_deps.h +1 -1
index 7a5bf44839c9c..f06df065dec01 100644
@@ -84,7 +84,7 @@ static uint64_t ZSTD_div64(uint64_t dividend, uint32_t divisor) {
 
 #include <linux/kernel.h>
 
-#define assert(x) WARN_ON((x))
+#define assert(x) WARN_ON(!(x))
 
 #endif /* ZSTD_DEPS_ASSERT */
 #endif /* ZSTD_DEPS_NEED_ASSERT */

--
2.39.0

#1 lore raw
Quoted 7 lines · Jonathan Neuschäfer

!-------------------------------------------------------------------|
This Message Is From an External Sender

Quoted 7 lines

|-------------------------------------------------------------------!

assert(x) should emit a warning if x is false. WARN_ON(x) emits a warning if x is true. Thus, assert(x) should be defined as WARN_ON(!x) rather than WARN_ON(x).

Hi Jonathan,

I have to apologize, I just submitted my branch for a PR and I realize that while I intended to take your patch, I took a different equivalent patch. So I wanted to say thanks for sending the patch!

Quoted 7 lines

---

Commit e0c1b49f5b674 ("lib: zstd: Upgrade to latest upstream zstd version 1.4.10") mentions that the zstd code was generated from the upstream version of zstd, so perhaps the definition of assert based on WARN_ON should be fixed in the conversion script and/or upstream zstd source code.

Yeah, we need to fix it upstream, so if you would like to submit the upstream PR the file is contrib/linux-kernel/zstd_deps.h [0]. Otherwise, I will update it before the next import.

Best,
Nick Terrell

[0] https://github.com/facebook/zstd/blob/dev/contrib/linux-kernel/zstd_deps.h

Quoted 20 lines

---
lib/zstd/common/zstd_deps.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
lib/zstd/common/zstd_deps.h +1 -2
index 7a5bf44839c9c..f06df065dec01 100644
@@ -84,7 +84,7 @@ static uint64_t ZSTD_div64(uint64_t dividend, uint32_t divisor) {
 
 #include <linux/kernel.h>
 
-#define assert(x) WARN_ON((x))
+#define assert(x) WARN_ON(!(x))
 
 #endif /* ZSTD_DEPS_ASSERT */
 #endif /* ZSTD_DEPS_NEED_ASSERT */
--

2.39.0

#2 lore raw
Quoted 6 lines · Nick Terrell
Quoted 5 lines · Jonathan Neuschäfer

assert(x) should emit a warning if x is false. WARN_ON(x) emits a warning if x is true. Thus, assert(x) should be defined as WARN_ON(!x) rather than WARN_ON(x).

Quoted 7 lines
Quoted 1 line

Hi Jonathan,

I have to apologize, I just submitted my branch for a PR and I realize that while I intended to take your patch, I took a different equivalent patch. So I wanted to say thanks for sending the patch!

No problem at all, and thanks for informing me!

Quoted 9 lines
Quoted 8 lines

---

Commit e0c1b49f5b674 ("lib: zstd: Upgrade to latest upstream zstd version 1.4.10") mentions that the zstd code was generated from the upstream version of zstd, so perhaps the definition of assert based on WARN_ON should be fixed in the conversion script and/or upstream zstd source code.

Quoted 3 lines

Yeah, we need to fix it upstream, so if you would like to submit the upstream PR the file is contrib/linux-kernel/zstd_deps.h [0]. Otherwise, I will update it before the next import.

Feel free to do it yourself, as I haven't been involed with zstd developement so far.

Thanks,
Jonathan