[PATCH 21/61] lib/test: Prefer IS_ERR_OR_NULL over manual NULL check

From: Philipp Hahn

Date: Tue Mar 10 2026 - 08:57:57 EST


Prefer using IS_ERR_OR_NULL() over using IS_ERR() and a manual NULL
check.

Change generated with coccinelle.

To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
To: Luis Chamberlain <mcgrof@xxxxxxxxxx>
To: Petr Pavlu <petr.pavlu@xxxxxxxx>
To: Daniel Gomez <da.gomez@xxxxxxxxxx>
To: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
To: Aaron Tomlin <atomlin@xxxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-modules@xxxxxxxxxxxxxxx
Signed-off-by: Philipp Hahn <phahn-oss@xxxxxx>
---
lib/test_firmware.c | 2 +-
lib/test_kmod.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/test_firmware.c b/lib/test_firmware.c
index b471d720879a70c0db82e605960abe69de28ab4b..fc3177927a02e2d7849915309048529395ece0f8 100644
--- a/lib/test_firmware.c
+++ b/lib/test_firmware.c
@@ -955,7 +955,7 @@ static ssize_t trigger_batched_requests_store(struct device *dev,
init_completion(&req->completion);
req->task = kthread_run(test_fw_run_batch_request, req,
"%s-%u", KBUILD_MODNAME, req->idx);
- if (!req->task || IS_ERR(req->task)) {
+ if (IS_ERR_OR_NULL(req->task)) {
pr_err("Setting up thread %u failed\n", req->idx);
req->task = NULL;
rc = -ENOMEM;
diff --git a/lib/test_kmod.c b/lib/test_kmod.c
index f0dd092860ea6f9c69a71e10cb1c8b071b1cd1b7..f44a181f6f1ab53cf95a0a0b598b88cb5f8f369d 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -327,7 +327,7 @@ static int try_one_request(struct kmod_test_device *test_dev, unsigned int idx)
info->task_sync = kthread_run(run_request, info, "%s-%u",
KBUILD_MODNAME, idx);

- if (!info->task_sync || IS_ERR(info->task_sync)) {
+ if (IS_ERR_OR_NULL(info->task_sync)) {
test_dev->test_is_oom = true;
dev_err(test_dev->dev, "Setting up thread %u failed\n", idx);
info->task_sync = NULL;
@@ -358,7 +358,7 @@ static void test_dev_kmod_stop_tests(struct kmod_test_device *test_dev)

for (i=0; i < config->num_threads; i++) {
info = &test_dev->info[i];
- if (info->task_sync && !IS_ERR(info->task_sync)) {
+ if (!IS_ERR_OR_NULL(info->task_sync)) {
dev_info(test_dev->dev,
"Stopping still-running thread %i\n", i);
kthread_stop(info->task_sync);

--
2.43.0