Re: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl

From: Jason Gunthorpe

Date: Fri Mar 13 2026 - 14:47:48 EST


On Wed, Mar 11, 2026 at 09:43:43PM +0000, Jonathan Cameron wrote:
> > + vdev = container_of(iommufd_get_object(ucmd->ictx, cmd->vdevice_id,
> > + IOMMUFD_OBJ_VDEVICE),
>
> As in previous, can the object be PTR_ERR()? Maybe not, but I'd
> be surprised if the static analysis tools are convinced.
> This might work for now if obj is first element but that's not
> elegant or matainable.

The compiler enforces first element:

#define __iommufd_object_alloc(ictx, ptr, type, obj) \
container_of(_iommufd_object_alloc( \
ictx, \
sizeof(*(ptr)) + BUILD_BUG_ON_ZERO( \
offsetof(typeof(*(ptr)), \
obj) != 0), \
type), \
typeof(*(ptr)), obj)

I have a lovely little series

https://github.com/jgunthorpe/linux/commits/container_of/

For this that I keep meaning to send but then never do

Jason