]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: generalize pidref_is_set() to `=~ _is_set()`
authorMichael Vogt <michael@amutable.com>
Fri, 27 Mar 2026 09:44:03 +0000 (10:44 +0100)
committerMichael Vogt <michael@amutable.com>
Fri, 27 Mar 2026 10:14:49 +0000 (11:14 +0100)
Our coccinelle/check-pointer-deref.cocci checker has a special
case for `assert(pidref_is_set(param))`. It turns out we can
generalize this and catch the following:
- iovec_is_set
- sd_dhcp_duid_is_set
- sd_dhcp_client_id_is_set

coccinelle/check-pointer-deref.cocci
src/boot/initrd.c

index e2376a314c5a1ab1e34956a6f476a39aec511ce5..dd058fae3bfcb0bb5c5e4e3fcce6119a5016baa2 100644 (file)
@@ -13,6 +13,7 @@
  */
 @@
 identifier fn, param;
+identifier is_set =~ "_is_set$";
 type T;
 position p;
 @@
@@ -25,10 +26,12 @@ fn(..., T *param, ...) {
       when != assert_return(param, ...)
       when != ASSERT_PTR(param)
       when != POINTER_MAY_BE_NULL(param)
-      /* NULL-safe helpers used commonly enough in assert() to warrant inclusion
-       * here. For less common cases, use POINTER_MAY_BE_NULL(param) instead of
-       * extending this list. */
-      when != assert(pidref_is_set(param))
+      /* Any foo_is_set(param) guard implies param != NULL, since all *_is_set()
+       * helpers in systemd return false for NULL input. Note the is_set regex
+       * in identifier. */
+      when != assert(is_set(param))
+      when != assert_return(is_set(param), ...)
+      when != \( is_set(param) \)
       when != \( param == NULL \| param != NULL \| !param \)
 * *param@p
   ...
index b8086ac633759f1184b1b53ba34b50b6d3cc32e6..d8cbe7deed425a52a65137bc44c0f79229513cf3 100644 (file)
@@ -74,7 +74,6 @@ EFI_STATUS initrd_register(
         EFI_HANDLE handle;
         struct initrd_loader *loader;
 
-        POINTER_MAY_BE_NULL(initrd);
         assert(ret_initrd_handle);
 
         /* If no initrd is specified we'll not install any. This avoids registration of the protocol for that