Skip to contentSkip to conversation

add private data to struct notifier_bock

PATCH In review mark gross 2 participants 3 messages Apr 14, 2008

lore
Share & tools
lore

mark gross

author
#0 lore raw

PATCH 1/1 add private data to struct notifier_bock

I am working with one of the iwl4965 developers to add pm_qos based power management to its power states. We relalized that the block notifier I used in the PM_QOS has no way of passing in any driver device instance data. In this case the developer expected the notification call backs to call the iwl4965 notification function with an instance pointer to the correct *dev.

Poking around I've noticed a handful of drivers using notifications that seem to keep a list of instance pointers around so it can plug into the notification infrastructure. including : ipmi_msghandler.c adb_hid.c md.c ips.c

As having a registered call back called with a private data pointer set up at registration time is such a common idiom I thought it might be a good thing to add a private_data pointer to the struct notifier_block and add the interfaces needed to pass the private data as the notification chain is processed.

please consider adding this to the mm-tree to get some eyeballs on it. I've boot tested this code and will be testing its use within the iwl4965 when the iwl4965 developer is ready.

Thanks,

--mgross

Signed-off-by [email protected]
include/linux/notifier.h +4 -0
index f4df400..995dcda 100644
@@ -51,6 +51,7 @@ struct notifier_block {
 	int (*notifier_call)(struct notifier_block *, unsigned long, void *);
 	struct notifier_block *next;
 	int priority;
+	void *private_data;
 };
 
 struct atomic_notifier_head {
@@ -138,6 +139,9 @@ extern int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
 		unsigned long val, void *v);
 extern int __blocking_notifier_call_chain(struct blocking_notifier_head *nh,
 	unsigned long val, void *v, int nr_to_call, int *nr_calls);
+extern int __blocking_notifier_call_chain_param(
+	struct blocking_notifier_head *nh, unsigned long val, int nr_to_call,
+		int *nr_calls);
 extern int raw_notifier_call_chain(struct raw_notifier_head *nh,
 		unsigned long val, void *v);
 extern int __raw_notifier_call_chain(struct raw_notifier_head *nh,
kernel/notifier.c +74 -0

86 lines not on this page · raw message

kernel/pm_qos_params.c +3 -2
index 0afe32b..cffd8bc 100644
@@ -158,8 +158,9 @@ static void update_target(int target)
 	spin_unlock_irqrestore(&pm_qos_lock, flags);
 
 	if (call_notifier)
-		blocking_notifier_call_chain(pm_qos_array[target]->notifiers,
-			(unsigned long) extreme_value, NULL);
+		__blocking_notifier_call_chain_param(
+			pm_qos_array[target]->notifiers,
+			(unsigned long) extreme_value, -1, NULL);
 }
 
 static int register_pm_qos_misc(struct pm_qos_object *qos)
#1 lore raw
Quoted 12 lines · mark gross

I am working with one of the iwl4965 developers to add pm_qos based power management to its power states. We relalized that the block notifier I used in the PM_QOS has no way of passing in any driver device instance data. In this case the developer expected the notification call backs to call the iwl4965 notification function with an instance pointer to the correct *dev.

Poking around I've noticed a handful of drivers using notifications that seem to keep a list of instance pointers around so it can plug into the notification infrastructure. including : ipmi_msghandler.c adb_hid.c md.c ips.c

Quoted 5 lines

As having a registered call back called with a private data pointer set up at registration time is such a common idiom I thought it might be a good thing to add a private_data pointer to the struct notifier_block and add the interfaces needed to pass the private data as the notification chain is processed.

How is:

struct my_device_thingy {
	...
	struct notifier_block my_notifier;
	...
};

int my_device_notifier_call(struct notifier_block *nb, unsigned long val
void *data)

{
	struct my_device_thingy *mdt = container_of(nb, struct
				 my_device_thingy, my_notifier);

	...
}

not sufficient?

author
#2 lore raw
Quoted 29 lines · Peter Zijlstra
Quoted 12 lines · mark gross

I am working with one of the iwl4965 developers to add pm_qos based power management to its power states. We relalized that the block notifier I used in the PM_QOS has no way of passing in any driver device instance data. In this case the developer expected the notification call backs to call the iwl4965 notification function with an instance pointer to the correct *dev.

Poking around I've noticed a handful of drivers using notifications that seem to keep a list of instance pointers around so it can plug into the notification infrastructure. including : ipmi_msghandler.c adb_hid.c md.c ips.c

Quoted 5 lines

As having a registered call back called with a private data pointer set up at registration time is such a common idiom I thought it might be a good thing to add a private_data pointer to the struct notifier_block and add the interfaces needed to pass the private data as the notification chain is processed.

How is:

struct my_device_thingy {
	...
	struct notifier_block my_notifier;
	...
};

int my_device_notifier_call(struct notifier_block *nb, unsigned long val
void *data)

Quoted 8 lines
{
	struct my_device_thingy *mdt = container_of(nb, struct
				 my_device_thingy, my_notifier);

	...
}

not sufficient?

Because ... um....a.... that would work too.

Please ignore my last patch.

Thanks!

--mgross