Skip to content

clean up the code related to ASSERT()

Chunguang Xu linux-arch lkml oe-kbuild-all 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest23 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/23include/asm-generic/bug.h: add ASSERT_FAIL() and ASSERT_WARN() wrapperinclude/asm-generic/bug.h+33 -00 replies
2/23ia64: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codearch/ia64/hp/common/sba_iommu.c+1 -50 replies
3/23KVM: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codearch/x86/kvm/ioapic.h+1 -80 replies
4/23fore200e: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/atm/fore200e.c+1 -50 replies
5/23scsi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/scsi/megaraid/mega_common.h+2 -80 replies
6/23rxrpc: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codenet/rxrpc/ar-internal.h+1 -70 replies
7/23lib/mpi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codelib/mpi/mpi-internal.h+1 -60 replies
8/23jfs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codefs/jfs/jfs_debug.h+1 -120 replies
9/23cachefiles: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codefs/cachefiles/internal.h+1 -80 replies
10/23btrfs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codefs/btrfs/ctree.h+1 -110 replies
11/23afs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codefs/afs/internal.h+1 -80 replies
12/23rivafb: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/video/fbdev/riva/fbdev.c+1 -60 replies
13/23nvidia: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/video/fbdev/nvidia/nvidia.c+1 -60 replies
14/23fbdev/cirrusfb:: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/video/fbdev/cirrusfb.c+1 -50 replies
15/23media/staging: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/staging/media/atomisp/pci/hive_isp_css_include/assert_support.h+1 -50 replies
16/23sym53c8xx: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/scsi/sym53c8xx_2/sym_hipd.h+1 -80 replies
17/238139too: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/net/ethernet/realtek/8139too.c+1 -50 replies
18/23net:hns: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/net/ethernet/hisilicon/hns/hnae.h+1 -70 replies
19/23block/sx8: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/block/sx8.c+1 -50 replies
20/23skb: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/block/skd_main.c+1 -70 replies
21/23ext4: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codefs/ext4/mballoc.c+1 -90 replies
22/23rbd: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codedrivers/block/rbd.c+1 -80 replies
23/23ALSA: asihpi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some codesound/pci/asihpi/hpidebug.h+1 -70 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 00/23] clean up the code related to ASSERT()

The kernel has not yet defined ASSERT(). Indeed, BUG() and WARN() are very clear and can cover most application scenarios. However, some applications require more debugging information and similar behavior to assert(), which cannot be directly provided by BUG() and WARN().

Therefore, many modules independently implement ASSERT(), and most of them are similar, but slightly different, such as:

 #define ASSERT(expr) \
         if(!(expr)) { \
                 printk( "\n" __FILE__ ":%d: Assertion " #expr " failed!\n",__LINE__); \
                 panic(#expr); \
         }
 #define ASSERT(x)                                                       \
 do {                                                                    \
         if (!(x)) {                                                     \
                 printk(KERN_EMERG "assertion failed %s: %d: %s\n",      \
                        __FILE__, __LINE__, #x);                         \
                 BUG();                                                  \
         }                                                               \

} while (0)

Some implementations are not optimal for instruction prediction, such as missing unlikely():

 #define assert(expr) \
         if(!(expr)) { \
         printk( "Assertion failed! %s,%s,%s,line=%d\n",\
         #expr,__FILE__,__func__,__LINE__); \
         BUG(); \
         }

Some implementations have too little log content information, such as:

#define ASSERT(X) \

 do {                                                            \
        if (unlikely(!(X))) {                                   \
                printk(KERN_ERR "\n");                          \
                printk(KERN_ERR "XXX: Assertion failed\n");     \
                BUG();                                          \
        }                                                       \

} while(0)

As we have seen, This makes the code redundant and inconvenient to troubleshoot the system. Therefore, perhaps we need to define two wrappers for BUG() and WARN_ON(), such as ASSERT_FAIL() and ASSERT_WARN(), provide the implementation of ASSERT(), simplify the code and facilitate problem analysis.

Maybe I missed some information, but I think there is a need to clean up the code, maybe in other ways, and more discussion is needed here. If this approach is reasonable, I will clean up these codes later and issue related patches.

Chunguang Xu (23):
include/asm-generic/bug.h: add ASSERT_FAIL() and ASSERT_WARN() wrapper
ia64: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
KVM: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
fore200e: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
scsi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
rxrpc: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code lib/mpi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
jfs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
cachefiles: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
btrfs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
afs: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
rivafb: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
nvidia: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code fbdev/cirrusfb:: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code media/staging: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
sym53c8xx: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code 8139too: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code net:hns: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code block/sx8: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
skb: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
ext4: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
rbd: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code
ALSA: asihpi: use ASSERT_FAIL()/ASSERT_WARN() to cleanup some code

 arch/ia64/hp/common/sba_iommu.c                    |  6 +---
 arch/x86/kvm/ioapic.h                              |  9 +-----
 drivers/atm/fore200e.c                             |  6 +---
 drivers/block/rbd.c                                |  9 +-----
 drivers/block/skd_main.c                           |  8 +-----
 drivers/block/sx8.c                                |  6 +---
 drivers/net/ethernet/hisilicon/hns/hnae.h          |  8 +-----
 drivers/net/ethernet/realtek/8139too.c             |  6 +---
 drivers/scsi/megaraid/mega_common.h                | 10 ++-----
 drivers/scsi/sym53c8xx_2/sym_hipd.h                |  9 +-----
 .../pci/hive_isp_css_include/assert_support.h      |  6 +---
 drivers/video/fbdev/cirrusfb.c                     |  6 +---
 drivers/video/fbdev/nvidia/nvidia.c                |  7 +----
 drivers/video/fbdev/riva/fbdev.c                   |  7 +----
 fs/afs/internal.h                                  |  9 +-----
 fs/btrfs/ctree.h                                   | 12 +-------
 fs/cachefiles/internal.h                           |  9 +-----
 fs/ext4/mballoc.c                                  | 10 +------
 fs/jfs/jfs_debug.h                                 | 13 +--------
 include/asm-generic/bug.h                          | 33 ++++++++++++++++++++++
 lib/mpi/mpi-internal.h                             |  7 +----
 net/rxrpc/ar-internal.h                            |  8 +-----
 sound/pci/asihpi/hpidebug.h                        |  8 +-----
 23 files changed, 56 insertions(+), 156 deletions(-)
Signature · 1 line
1.8.3.1