Skip to contentSkip to conversation

selftests: net: fix wrong boolean evaluation in __exit__

PATCH Applied Gal Pressman 2 participants 2 messages Jan 25 – Jan 27

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

PATCH v2 1/1 selftests: net: fix wrong boolean evaluation in __exit__

The __exit__ method receives ex_type as the exception class when an exception occurs. The previous code used implicit boolean evaluation:

terminate = self.terminate or (self._exit_wait and ex_type)
^^^^^^^^^^^

In Python, the and operator can be used with non-boolean values, but it does not always return a boolean result.

This is probably not what we want, because 'self._exit_wait and ex_type' could return the actual ex_type value (the exception class) rather than a boolean True when an exception occurs.

Use explicit ex_type is not None check to properly evaluate whether an exception occurred, returning a boolean result.

---
Changelog -
v1->v2: https://lore.kernel.org/all/[email protected]/
* Target net-next and remove Fixes (Jakub).

---
 tools/testing/selftests/net/lib/py/utils.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/lib/py/utils.py +1 -1
index 106ee1f2df86..dc1db78b5304 100644
@@ -137,7 +137,7 @@ class bkg(cmd):
 
     def __exit__(self, ex_type, ex_value, ex_tb):
         # Force termination on exception
-        terminate = self.terminate or (self._exit_wait and ex_type)
+        terminate = self.terminate or (self._exit_wait and ex_type is not None)
         return self.process(terminate=terminate, fail=self.check_fail)
 
 
Signature · 1 line
2.40.1
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Sun, 25 Jan 2026 12:55:24 +0200 you wrote:

The __exit__ method receives ex_type as the exception class when an exception occurs. The previous code used implicit boolean evaluation:

terminate = self.terminate or (self._exit_wait and ex_type)
^^^^^^^^^^^

In Python, the and operator can be used with non-boolean values, but it does not always return a boolean result.

[...]

Here is the summary with links:
- [net-next,v2] selftests: net: fix wrong boolean evaluation in __exit__

    https://git.kernel.org/netdev/net-next/c/a84a1fe0fb2e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html