[Cbe-oss-dev] [patch 04/16] powerpc and x86_64: Initial port of PCIe endpoint device driver for axon

Arnd Bergmann arnd at arndb.de
Mon Mar 31 17:36:27 EST 2008


On Thursday 27 March 2008, H Brett Bolen wrote:
> I looked at the notifier and determined I could not use it.  The 
> notifier passes the same struct * to all clients,
> and I need something to pass the instance struct back -- when you 
> register for the callback, it takes
> a callback function, and a generic void * pointer.  When you register 
> for a notifier, it takes a callback function.
> It seems like it also sent an int along, and I could have implemented a 
> 'lookup' in the host function to get
> a void * ( or instance ptr), but I thought it was ugly.  I did not see a 
> reason to fix something that already
> works with a hack.
> 

The way it is supposed to work is that you embed a struct notifier_block
in your instance structure, and pass a pointer to that notifier_block
into atomic_notifier_chain_register().

Your notifier function then looks like this:

static struct my_struct {
	void *my_instance;
	struct notifier_block notifier;
};

static int my_notifier_call(struct notifier_block *nb, unsigned long val, void *obj)
{
	struct my_struct *my_data = container_of(nb, struct my_struct, notifier);

	return do_something(my_data);
}

This is a common scheme we use in all sorts of places in linux as a way of
doing object oriented programming in C. Think of the my_struct class being
derived from the notifier_block class.

	Arnd <><



More information about the cbe-oss-dev mailing list