net: dql: Avoid calling BUG() when WARN() is enough
authorBreno Leitao <leitao@debian.org>
Thu, 11 Apr 2024 19:22:29 +0000 (12:22 -0700)
committerJakub Kicinski <kuba@kernel.org>
Mon, 15 Apr 2024 18:19:52 +0000 (11:19 -0700)
If the dql_queued() function receives an invalid argument, WARN about it
and continue, instead of crashing the kernel.

This was raised by checkpatch, when I am refactoring this code (see
following patch/commit)

WARNING: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants

Signed-off-by: Breno Leitao <leitao@debian.org>
Link: https://lore.kernel.org/r/20240411192241.2498631-2-leitao@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/dynamic_queue_limits.h

index 5693a4be0d9a9950ffe0cc1813838173cb41e3d5..ff9c65841ae8d7b435d1d7aed177f8e8be154169 100644 (file)
@@ -91,7 +91,8 @@ static inline void dql_queued(struct dql *dql, unsigned int count)
 {
        unsigned long map, now, now_hi, i;
 
-       BUG_ON(count > DQL_MAX_OBJECT);
+       if (WARN_ON_ONCE(count > DQL_MAX_OBJECT))
+               return;
 
        dql->last_obj_cnt = count;