[PATCH 00/61] treewide: Use IS_ERR_OR_NULL over manual NULL check - refactor

Philipp Hahn
2026-03-10T11:55:28Z

While doing some static code analysis I stumbled over a common pattern,
where IS_ERR() is combined with a NULL check. For that there is
IS_ERR_OR_NULL().

I've written a Coccinelle patch to find and patch those instances.
The patches follow grouped by subsystem.

Patches 55-58 may be dropped as they have a (minor?) semantic change:
They use WARN_ON() or WARN_ON_ONCE(), but only in the IS_ERR() path, not
for the NULL check. Iff it is okay to print the warning also for NULL,
then the patches can be applied.

While generating the patch set `checkpatch` complained about mixing
[un]likely() with IS_ERR_OR_NULL(), which already uses likely()
internally. I found and fixed several locations, where that combination
has been used.

Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
---
Philipp Hahn (61):
Coccinelle: Prefer IS_ERR_OR_NULL over manual NULL check
btrfs: Prefer IS_ERR_OR_NULL over manual NULL check
ceph: Prefer IS_ERR_OR_NULL over manual NULL check
ext4: Prefer IS_ERR_OR_NULL over manual NULL check
smb: Prefer IS_ERR_OR_NULL over manual NULl check
9p: Prefer IS_ERR_OR_NULL over manual NULL check
erofs: Prefer IS_ERR_OR_NULL over manual NULL check
fuse: Prefer IS_ERR_OR_NULL over manual NULL check
ntfs3: Prefer IS_ERR_OR_NULL over manual NULL check
gfs2: Prefer IS_ERR_OR_NULL over manual NULL check
pstore: Prefer IS_ERR_OR_NULL over manual NULL check
quota: Prefer IS_ERR_OR_NULL over manual NULL check
squashfs: Prefer IS_ERR_OR_NULL over manual NULL check
seq_file: Prefer IS_ERR_OR_NULL over manual NULL check
trace: Prefer IS_ERR_OR_NULL over manual NULL check
sched: Prefer IS_ERR_OR_NULL over manual NULL check
module: Prefer IS_ERR_OR_NULL over manual NULL check
sound: Prefer IS_ERR_OR_NULL over manual NULL check
kvm: Prefer IS_ERR_OR_NULL over manual NULL check
apparmor: Prefer IS_ERR_OR_NULL over manual NULL check
lib/test: Prefer IS_ERR_OR_NULL over manual NULL check
md: Prefer IS_ERR_OR_NULL over manual NULL check
net/ipv6: Prefer IS_ERR_OR_NULL over manual NULL check
net/9p: Prefer IS_ERR_OR_NULL over manual NULL check
net/bluetooth: Prefer IS_ERR_OR_NULL over manual NULL check
net/core: Prefer IS_ERR_OR_NULL over manual NULL check
net/netlink: Prefer IS_ERR_OR_NULL over manual NULL check
net/sched: Prefer IS_ERR_OR_NULL over manual NULL check
net/sctp: Prefer IS_ERR_OR_NULL over manual NULL check
net/sunrpc: Prefer IS_ERR_OR_NULL over manual NULL check
net/tipc: Prefer IS_ERR_OR_NULL over manual NULL check
net/wireless: Prefer IS_ERR_OR_NULL over manual NULL check
mm: Prefer IS_ERR_OR_NULL over manual NULL check
arch/arm: Prefer IS_ERR_OR_NULL over manual NULL check
arch/mips: Prefer IS_ERR_OR_NULL over manual NULL check
arch/sh: Prefer IS_ERR_OR_NULL over manual NULL check
drm: Prefer IS_ERR_OR_NULL over manual NULL check
net: Prefer IS_ERR_OR_NULL over manual NULL check
irqchip: Prefer IS_ERR_OR_NULL over manual NULL check
phy: Prefer IS_ERR_OR_NULL over manual NULL check
pinctrl: Prefer IS_ERR_OR_NULL over manual NULL check
pmdomain: Prefer IS_ERR_OR_NULL over manual NULL check
s390: Prefer IS_ERR_OR_NULL over manual NULL check
target: Prefer IS_ERR_OR_NULL over manual NULL check
thermal: Prefer IS_ERR_OR_NULL over manual NULL check
vfio: Prefer IS_ERR_OR_NULL over manual NULL check
nfc: Prefer IS_ERR_OR_NULL over manual NULL check
mtd: Prefer IS_ERR_OR_NULL over manual NULL check
media: Prefer IS_ERR_OR_NULL over manual NULL check
iommu: Prefer IS_ERR_OR_NULL over manual NULL check
leds: Prefer IS_ERR_OR_NULL over manual NULL check
gpib: Prefer IS_ERR_OR_NULL over manual NULL check
hyperv: Prefer IS_ERR_OR_NULL over manual NULL check
aoe: Prefer IS_ERR_OR_NULL over manual NULL check
interconnect: Prefer IS_ERR_OR_NULL over manual NULL check
clk: Prefer IS_ERR_OR_NULL over manual NULL check
reset: Prefer IS_ERR_OR_NULL over manual NULL check
arch/x86: Prefer IS_ERR_OR_NULL over manual NULL check
debugobjects: Drop likely() around !IS_ERR_OR_NULL()
Input alps: Drop unlikely() around IS_ERR_OR_NULL()
file: Drop unlikely() around IS_ERR_OR_NULL()

arch/arm/common/bL_switcher.c | 2 +-
arch/mips/lantiq/clk.c | 2 +-
arch/sh/mm/ioremap.c | 2 +-
arch/x86/kernel/callthunks.c | 2 +-
arch/x86/kernel/irq.c | 2 +-
drivers/block/aoe/aoecmd.c | 2 +-
drivers/clk/clk.c | 4 +-
drivers/clocksource/timer-pxa.c | 2 +-
drivers/gpib/common/iblib.c | 2 +-
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 2 +-
drivers/gpu/drm/drm_sysfs.c | 2 +-
drivers/gpu/drm/i915/gvt/scheduler.c | 4 +-
drivers/gpu/drm/radeon/radeon_test.c | 2 +-
drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c | 2 +-
drivers/hv/mshv_eventfd.c | 4 +-
drivers/input/mouse/alps.c | 2 +-
drivers/interconnect/core.c | 2 +-
drivers/iommu/omap-iommu.c | 2 +-
drivers/irqchip/irq-gic-v3.c | 2 +-
drivers/irqchip/irq-mvebu-odmi.c | 2 +-
drivers/leds/trigger/ledtrig-tty.c | 2 +-
drivers/md/dm-cache-metadata.c | 2 +-
drivers/md/dm-crypt.c | 4 +-
drivers/media/test-drivers/vimc/vimc-streamer.c | 2 +-
drivers/mtd/nand/raw/gpio.c | 10 +-
drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 2 +-
drivers/net/ethernet/broadcom/tg3.c | 2 +-
.../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 3 +-
drivers/net/ethernet/intel/ice/devlink/devlink.c | 2 +-
.../ethernet/marvell/prestera/prestera_router.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
drivers/net/mdio/mdio-xgene.c | 2 +-
drivers/net/usb/r8152.c | 2 +-
drivers/nfc/trf7970a.c | 2 +-
drivers/phy/phy-core.c | 2 +-
drivers/pinctrl/core.c | 2 +-
drivers/pmdomain/rockchip/pm-domains.c | 2 +-
drivers/reset/core.c | 2 +-
drivers/s390/char/tape_class.c | 2 +-
drivers/target/target_core_fabric_configfs.c | 6 +-
drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +-
drivers/vfio/vfio_main.c | 2 +-
fs/9p/fid.h | 2 +-
fs/btrfs/inode.c | 2 +-
fs/btrfs/transaction.c | 2 +-
fs/btrfs/tree-log.c | 2 +-
fs/btrfs/uuid-tree.c | 2 +-
fs/ceph/dir.c | 2 +-
fs/ceph/snap.c | 2 +-
fs/erofs/zdata.c | 2 +-
fs/ext4/fast_commit.c | 2 +-
fs/ext4/mballoc.c | 2 +-
fs/ext4/namei.c | 2 +-
fs/ext4/symlink.c | 2 +-
fs/fuse/dir.c | 2 +-
fs/gfs2/glock.c | 2 +-
fs/ntfs3/fsntfs.c | 8 +-
fs/pstore/zone.c | 2 +-
fs/quota/quota.c | 2 +-
fs/seq_file.c | 4 +-
fs/smb/client/cifsglob.h | 2 +-
fs/smb/client/connect.c | 2 +-
fs/smb/client/readdir.c | 2 +-
fs/squashfs/cache.c | 2 +-
include/linux/file.h | 2 +-
include/net/9p/client.h | 2 +-
kernel/module/main.c | 2 +-
kernel/sched/ext.c | 2 +-
kernel/trace/fprobe.c | 2 +-
kernel/trace/kprobe_event_gen_test.c | 2 +-
kernel/trace/trace_events_hist.c | 2 +-
lib/debugobjects.c | 2 +-
lib/test_firmware.c | 2 +-
lib/test_kmod.c | 4 +-
mm/kmemleak.c | 16 +--
net/9p/trans_rdma.c | 8 +-
net/bluetooth/mgmt.c | 6 +-
net/core/xdp.c | 2 +-
net/ipv6/ila/ila_xlat.c | 2 +-
net/ipv6/ndisc.c | 2 +-
net/netlink/af_netlink.c | 2 +-
net/sched/cls_api.c | 6 +-
net/sctp/socket.c | 2 +-
net/sunrpc/xprtrdma/svc_rdma_transport.c | 12 +-
net/tipc/socket.c | 2 +-
net/wireless/reg.c | 2 +-
scripts/coccinelle/api/is_err_or_null.cocci | 125 +++++++++++++++++++++
security/apparmor/apparmorfs.c | 2 +-
sound/soc/samsung/i2s.c | 4 +-
sound/soc/xtensa/xtfpga-i2s.c | 2 +-
virt/kvm/eventfd.c | 4 +-
91 files changed, 251 insertions(+), 127 deletions(-)
---
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
change-id: 20260305-b4-is_err_or_null-59998a7d03c4

Best regards,
--
Philipp Hahn <phahn-oss@avm.de>