Skip to contentSkip to conversation

kobject: introduce kobj_completion

PATCH In review Jeff Mahoney 3 participants 5 messages Sep 11, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kobject: introduce kobj_completion

A common way to handle kobject lifetimes in embedded in objects with different lifetime rules is to pair the kobject with a struct completion.

This introduces a kobj_completion structure that can be used in place of the pairing, along with several convenience functions for initialization, release, and put-and-wait.

---
 include/linux/kobj_completion.h |   18 ++++++++++++++
 lib/kobject.c                   |   50 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
include/linux/kobj_completion.h new file +18 -0
@@ -0,0 +1,18 @@
+#ifndef _KOBJ_COMPLETION_H_
+#define _KOBJ_COMPLETION_H_
+
+#include <linux/kobject.h>
+#include <linux/completion.h>
+
+struct kobj_completion {
+	struct kobject kc_kobj;
+	struct completion kc_unregister;
+};
+
+#define kobj_to_kobj_completion(kobj) \
+	container_of(kobj, struct kobj_completion, kc_kobj)
+
+void kobj_completion_init(struct kobj_completion *kc, struct kobj_type *ktype);
+void kobj_completion_release(struct kobject *kobj);
+void kobj_completion_del_and_wait(struct kobj_completion *kc);
+#endif /* _KOBJ_COMPLETION_H_ */
lib/kobject.c +50 -0

62 lines not on this page · raw message

#1 lore raw
Quoted 10 lines · Jeff Mahoney

A common way to handle kobject lifetimes in embedded in objects with different lifetime rules is to pair the kobject with a struct completion.

This introduces a kobj_completion structure that can be used in place of the pairing, along with several convenience functions for initialization, release, and put-and-wait.

---
 include/linux/kobj_completion.h |   18 ++++++++++++++

Does this really need a new .h file, or can we just cram it into kobject.h? It's only 13 more lines to add to that file.

thanks,

greg k-h

#3 lore raw
In reply to Jeff Mahoney
Quoted 6 lines · Jeff Mahoney

A common way to handle kobject lifetimes in embedded in objects with different lifetime rules is to pair the kobject with a struct completion.

This introduces a kobj_completion structure that can be used in place of the pairing, along with several convenience functions for initialization, release, and put-and-wait.

That's very easy to misuse, leading to deadlocks...

#4 lore raw
Quoted 9 lines · Al Viro
Quoted 6 lines · Jeff Mahoney

A common way to handle kobject lifetimes in embedded in objects with different lifetime rules is to pair the kobject with a struct completion.

This introduces a kobj_completion structure that can be used in place of the pairing, along with several convenience functions for initialization, release, and put-and-wait.

That's very easy to misuse, leading to deadlocks...

Misuse how? If you're using it any time other than shutting down an object, you're shooting yourself in the foot.

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#2 lore raw
In reply to Greg KH
Quoted 8 lines · Greg KH
Quoted 7 lines · Jeff Mahoney

A common way to handle kobject lifetimes in embedded in objects with different lifetime rules is to pair the kobject with a struct completion.

This introduces a kobj_completion structure that can be used in place of the pairing, along with several convenience functions for initialization, release, and put-and-wait.

Quoted 6 lines
Quoted 3 lines
---
 include/linux/kobj_completion.h |   18 ++++++++++++++

Does this really need a new .h file, or can we just cram it into kobject.h? It's only 13 more lines to add to that file.

It doesn't need to be, but it avoids everywhere that already uses a kobject having to include <linux/completion.h> indirectly.

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs