add private data to notifier_block
PATCH 1/1 add private data to notifier_block
While most current uses of notifier_block use a global struct, I would like to be able to use it on a per device basis for drivers which have multiple device instances. I would also like to be able to have a private data struct associated with the notifier block so that per device data can be easily accessed. This patch will modify the notifier_block struct to add a void *, and will require no modifications to any other users of the notifier_block.
--- include/linux/notifier.h | 1 + 1 files changed, 1 insertion(+)
include/linux/notifier.h +1 -0
@@ -15,6 +15,7 @@ struct notifier_block {int (*notifier_call)(struct notifier_block *self,unsigned long ,void *);struct notifier_block *next; +void *data;int priority; };
include/linux/notifier.h struct notifier_block · line 20
Quoted 10 lines · Kristen Accardi
device data can be easily accessed. This patch will modify the
notifier_blockstruct to add a void *, and will require no modifications to any other users of thenotifier_block.{
include/linux/notifier.h +1
-0int (*notifier_call)(struct notifier_block *self,unsigned long ,void *);struct notifier_block *next; +void *data;int priority; };
Well, it might introduce warnings in users who weren't using named initializers -- their bare priority initialization might now shift to trying to initialize a pointer.
Though, that's probably a good thing as it gives an opportunity to convert them. We also don't want to create a padded structure by putting the void * after the int.
- z
Quoted 17 lines · Kristen Accardi
While most current uses of
notifier_blockuse a global struct, I would like to be able to use it on a per device basis for drivers which have multiple device instances. I would also like to be able to have a private data struct associated with the notifier block so that per device data can be easily accessed. This patch will modify thenotifier_blockstruct to add a void *, and will require no modifications to any other users of thenotifier_block.Signed-off-by Kristen Carlson Accardi <[email protected]>--- include/linux/notifier.h | 1 + 1 files changed, 1 insertion(+)
include/linux/notifier.h struct notifier_block · line 20
Quoted 6 lines
include/linux/notifier.h +1
-0@@ -15,6 +15,7 @@ struct notifier_block {int (*notifier_call)(struct notifier_block *self,unsigned long ,void *);struct notifier_block *next; +void *data;int priority; };
I still think this isn't really needed. The same effect can be accomplished by embedding a notifier_block struct within a larger structure that also contains the data pointer.
On the other hand this isn't a terribly big change, so I don't actually object to it.
Alan Stern
Quoted 16 lines · Alan Stern
Quoted 14 lines · Kristen Accardi
While most current uses of
notifier_blockuse a global struct, I would like to be able to use it on a per device basis for drivers which have multiple device instances. I would also like to be able to have a private data struct associated with the notifier block so that per device data can be easily accessed. This patch will modify thenotifier_blockstruct to add a void *, and will require no modifications to any other users of thenotifier_block.Signed-off-by Kristen Carlson Accardi <[email protected]>--- include/linux/notifier.h | 1 + 1 files changed, 1 insertion(+)
Quoted 14 lines
include/linux/notifier.h struct notifier_block · line 20
Quoted 9 lines
include/linux/notifier.h +1
-0@@ -15,6 +15,7 @@ struct notifier_block {int (*notifier_call)(struct notifier_block *self,unsigned long ,void *);struct notifier_block *next; +void *data;int priority; };I still think this isn't really needed. The same effect can be accomplished by embedding a
notifier_blockstruct within a larger structure that also contains the data pointer.
I thought of this, but felt it would make for less easy to read code. But, that's just my personal style.
Quoted 3 lines
On the other hand this isn't a terribly big change, so I don't actually object to it.
Thanks.
Quoted 1 line
Alan Stern
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Kristen" == Kristen Accardi <[email protected]> writes:
Quoted 3 lines · Alan Stern
Quoted 3 lines
I still think this isn't really needed. The same effect can be accomplished by embedding a
notifier_blockstruct within a larger structure that also contains the data pointer.
Kristen> I thought of this, but felt it would make for less easy to Kristen> read code. But, that's just my personal style.
I'd have to vote for Alan's side here. Thats why we have the containerof() stuff. It also means you can embed more than just a pointer with the notifier block and it will generate more efficient code when doing so.
Cheers,
Jes
Quoted 10 lines · Jes Sorensen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Kristen" == Kristen Accardi <[email protected]> writes:
Quoted 3 lines · Alan Stern
Quoted 3 lines
I still think this isn't really needed. The same effect can be accomplished by embedding a
notifier_blockstruct within a larger structure that also contains the data pointer.Kristen> I thought of this, but felt it would make for less easy to Kristen> read code. But, that's just my personal style.
Quoted 7 lines
I'd have to vote for Alan's side here. Thats why we have the
containerof()stuff. It also means you can embed more than just a pointer with the notifier block and it will generate more efficient code when doing so.Cheers,
Jes
Ok, I bow to peer pressure and will do this your way. :) You can ignore this patch.
Thanks,
Kristen