lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <420cb4b0-16d0-480a-9bd2-7728ee6905e9@stanley.mountain>
Date: Wed, 29 Jan 2025 10:33:56 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Greg KH <gregkh@...uxfoundation.org>
Cc: "Gustavo A. R. Silva" <gustavoars@...nel.org>,
	linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH v2][next] container_of: add container_first() macro

On Wed, Jan 29, 2025 at 10:29:24AM +0300, Dan Carpenter wrote:
> drivers/iommu/iommufd/iommufd_private.h
>    243  static inline struct iommufd_ioas *iommufd_get_ioas(struct iommufd_ctx *ictx,
>    244                                                      u32 id)
>    245  {
>    246          return container_of(iommufd_get_object(ictx, id,
>    247                                                 IOMMUFD_OBJ_IOAS),
>    248                              struct iommufd_ioas, obj);
>    249  }
> 
> It's just a cast like you say, but it looks like pointer math.  It would
> be more readable as container_of_first().

I left out the important bit...  iommufd_get_object() returns error pointers.
It doesn't make sense to pass error pointers to container_of() unless the
offset is zero.

Smatch could check that the offset is zero, but Coccinelle can't.  There are
a bunch of advantages to Coccinelle at times so this will improve the
readability and make it easier for static checkers as well.

regards,
dan carpenter



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ