tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: proposal: some pointer and arithmetic utilities
Date: Thu, 21 Mar 2013 21:11:56 +0100
From: Rhialto <rhialto%falu.nl@localhost>
I would argue that all such mumble() should really be changed to
int
mumble(struct foo *foo)
{
struct bar *bar = &foo->f_bar;
...
}
since they are making that assumption already anyway.
This transformation doesn't make sense when the caller of mumble works
with bars, not foos, and it's the caller of the caller of mumble that
needs to pass in a foo to mumble by way of passing a bar to the caller
of mumble.
For example, consider workqueues and struct work. If you want to put
an object on a workqueue (i.e., pass an argument in a request for
deferred work), you embed a struct work in the object and then the
workqueue's worker takes the struct work and finds the containing
object from of it.
kern_physio.c relies on the fact that the struct work is at the
beginning of struct buf when it does
static void
physio_done(struct work *wk, void *dummy)
{
struct buf *bp = (void *)wk;
...
}
to recover bp after workqueue_enqueue(physio_workqueue, &bp->b_work,
NULL). But instead it could use
struct buf *bp = container_of(wk, struct work, b_work);
In either case, the workqueue abstraction doesn't know or care that
the struct work we're putting into the workqueue is from struct buf.
We have various other abstractions like this in tree too.
Home |
Main Index |
Thread Index |
Old Index