From: Greg KH <gregkh@linuxfoundation.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2][next] container_of: add container_first() macro
Date: Wed, 29 Jan 2025 09:04:04 +0100 [thread overview]
Message-ID: <2025012947-hexagon-almighty-57b3@gregkh> (raw)
In-Reply-To: <420cb4b0-16d0-480a-9bd2-7728ee6905e9@stanley.mountain>
On Wed, Jan 29, 2025 at 10:33:56AM +0300, Dan Carpenter wrote:
> 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.
Ick, agreed. you should never be checking the return value of
container_of(). Shouldn't we somehow check for that? Is there the
inverse of __must_check where we "just" want to use the value but never
compare it to anything?
> 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.
But I don't see how container_first() will do anything to help the above
type of code. Gustavo, have any examples of what you need this for?
thanks,
greg k-h
next prev parent reply other threads:[~2025-01-29 8:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-29 5:26 [PATCH v2][next] container_of: add container_first() macro Gustavo A. R. Silva
2025-01-29 5:54 ` Greg KH
2025-01-29 7:29 ` Dan Carpenter
2025-01-29 7:33 ` Dan Carpenter
2025-01-29 8:04 ` Greg KH [this message]
2025-01-29 8:05 ` Gustavo A. R. Silva
2025-01-29 8:34 ` Greg KH
2025-01-29 10:39 ` Dan Carpenter
2025-01-29 13:14 ` Greg KH
2025-01-29 14:06 ` Dan Carpenter
2025-01-29 16:08 ` Greg KH
2025-01-29 23:36 ` Gustavo A. R. Silva
2025-01-30 6:14 ` Greg KH
2025-01-30 6:23 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2025012947-hexagon-almighty-57b3@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=dan.carpenter@linaro.org \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.