]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
smb: smbdirect: introduce SMBDIRECT_DEBUG_ERR_PTR() helper
authorStefan Metzmacher <metze@samba.org>
Tue, 25 Nov 2025 08:55:54 +0000 (09:55 +0100)
committerSteve French <stfrench@microsoft.com>
Mon, 1 Dec 2025 03:11:45 +0000 (21:11 -0600)
This can be used like this:

  int err = somefunc();
  pr_warn("err=%1pe\n", SMBDIRECT_DEBUG_ERR_PTR(err));

This will be used in the following fixes in order
to be prepared to identify real world problems
more easily.

Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/common/smbdirect/smbdirect_socket.h

index ee5a90d691c898ea03f9d44adbdd3d6dbb29c667..611986827a5e233920cd33e63a9e7b702265bf76 100644 (file)
@@ -74,6 +74,19 @@ const char *smbdirect_socket_status_string(enum smbdirect_socket_status status)
        return "<unknown>";
 }
 
+/*
+ * This can be used with %1pe to print errors as strings or '0'
+ * And it avoids warnings like: warn: passing zero to 'ERR_PTR'
+ * from smatch -p=kernel --pedantic
+ */
+static __always_inline
+const void * __must_check SMBDIRECT_DEBUG_ERR_PTR(long error)
+{
+       if (error == 0)
+               return NULL;
+       return ERR_PTR(error);
+}
+
 enum smbdirect_keepalive_status {
        SMBDIRECT_KEEPALIVE_NONE,
        SMBDIRECT_KEEPALIVE_PENDING,