[PATCH v2 06/13] RDMA: Add ib_is_udata_in_empty()

Jason Gunthorpe
2026-02-27T01:11:28Z

If the driver doesn't yet support any request driver data it should check
that it is all zeroed. This is a common pattern, add a helper around
_ib_copy_validate_udata_in() to do this.

Tested-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Acked-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
include/rdma/uverbs_ioctl.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
index 720f173c2b3fc7..cf395fa8c36174 100644
--- a/include/rdma/uverbs_ioctl.h
+++ b/include/rdma/uverbs_ioctl.h
@@ -1075,6 +1075,21 @@ int _ib_copy_validate_udata_cm_fail(struct ib_udata *udata, u64 req_cm,
ret; \
})

+/**
+ * ib_is_udata_in_empty - Check if the udata input buffer is all zeros
+ * @udata: The system calls ib_udata struct
+ *
+ * This should be used if the driver does not currently define a driver data
+ * struct. Returns 0 if the buffer is empty or all zeros, -EOPNOTSUPP if
+ * non-zero data is present, or a negative error code on failure.
+ */
+static inline int ib_is_udata_in_empty(struct ib_udata *udata)
+{
+ if (!udata || udata->inlen == 0)
+ return 0;
+ return _ib_copy_validate_udata_in(udata, NULL, 0, 0);
+}
+
/**
* ib_respond_udata - Copy a driver data response to userspace
* @_udata: The system calls ib_udata struct
--
2.43.0