From: Greg KH <greg@kroah.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: container_of
Date: Tue, 23 Dec 2008 06:09:59 +0000 [thread overview]
Message-ID: <20081223060959.GA1701@kroah.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0812191854150.11217@ask.diku.dk>
On Tue, Dec 23, 2008 at 07:01:59AM +0100, Julia Lawall wrote:
> On Mon, 22 Dec 2008, Greg KH wrote:
>
> > On Fri, Dec 19, 2008 at 06:56:46PM +0100, Julia Lawall wrote:
> > > Considering code such as the following (drivers/acpi/osl.c):
> > >
> > > struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
> > > if (!dpc) {
> > > printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
> > > return;
> > > }
> > >
> > > Is it very likely that container_of can return NULL? Container_of
> > > computes an offset from a pointer, so I have the impression that if given
> > > a NULL value it would normally return a negative number (or a very large
> > > positive one, depending on how it is interpreted).
> >
> > You are correct, that check will never happen, and should be removed.
>
> Actually, someone else pointed out that one could call the function with
> &x->fld, and if x is NULL, then container_of(&x->fld,...) would go back
> down to NULL. I haven't looked at the call sites though to see if that
> can happen.
No, if you were to evaluate x->fld, you would oops :)
So again, the check is pointless. And I say this as someone who has
written such checks many times in the past...
thanks,
greg k-h
next prev parent reply other threads:[~2008-12-23 6:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-19 17:56 container_of Julia Lawall
2008-12-20 11:54 ` container_of Darren Jenkins
2008-12-20 18:19 ` container_of Julia Lawall
2008-12-23 5:37 ` container_of Greg KH
2008-12-23 6:01 ` container_of Julia Lawall
2008-12-23 6:09 ` Greg KH [this message]
2008-12-23 7:00 ` container_of Julia Lawall
-- strict thread matches above, loose matches on Subject: below --
2015-01-17 16:32 container_of Simon Brand
2015-01-17 16:58 ` container_of Manish Katiyar
2015-01-17 19:45 ` container_of Simon Brand
2015-01-17 19:53 ` container_of Mike Krinkin
2015-01-19 15:18 ` container_of Simon Brand
2015-01-17 19:13 ` container_of Anish Kumar
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=20081223060959.GA1701@kroah.com \
--to=greg@kroah.com \
--cc=kernel-janitors@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.