Re: [PATCH] i2c: Do not give adapters a default parent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2009-07-22 at 21:07 +0200, Jean Delvare wrote:
> > > * Do we need an actually struct class for each fake class, or just a
> > >  class name?
> > 
> > We will need to create a kobject for the compat class directory, we
> > will not need a "struct class" for it and can just use a simple
> > pointer to the registered kobject. If we use a string, we would need
> > to find the registered kobject with every call to create a link there,
> > not necessarily bad, but an explicitely registered object might be
> > easier.
> 
> Any progress on this? I have just committed the patches to
> sensors-detect and libsensors, and the kernel patch is ready to go, but
> without the compatibility links it doesn't make any sense to push it
> upstream

Something like this? Please change it as you need. I did only a very
quick test.

The only important part is that the kobject of the class directly is not
exposed, so nobody else can do weird things with it.

Thanks,
Kay


--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -488,6 +488,45 @@ void class_interface_unregister(struct c
 	class_put(parent);
 }
 
+struct class_compat {
+	struct kobject *kobj;
+};
+
+struct class_compat *class_compat_register(const char *name)
+{
+	struct class_compat *cls;
+
+	cls = kmalloc(sizeof(struct class_compat), GFP_KERNEL);
+	if (!cls)
+		return NULL;
+	cls->kobj = kobject_create_and_add(name, &class_kset->kobj);
+	if (!cls->kobj) {
+		kfree(cls);
+		return NULL;
+	}
+	return cls;
+}
+EXPORT_SYMBOL_GPL(class_compat_register);
+
+void class_compat_unregister(struct class_compat *cls)
+{
+	kobject_put(cls->kobj);
+	kfree(cls);
+}
+EXPORT_SYMBOL_GPL(class_compat_unregister);
+
+int class_compat_create_link(struct class_compat *cls, struct device *dev)
+{
+	return sysfs_create_link(cls->kobj, &dev->kobj, dev_name(dev));
+}
+EXPORT_SYMBOL_GPL(class_compat_create_link);
+
+void class_compat_remove_link(struct class_compat *cls, struct device *dev)
+{
+	return sysfs_remove_link(cls->kobj, dev_name(dev));
+}
+EXPORT_SYMBOL_GPL(class_compat_remove_link);
+
 int __init classes_init(void)
 {
 	class_kset = kset_create_and_add("class", NULL, NULL);

--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -223,6 +223,12 @@ extern void class_unregister(struct clas
 	__class_register(class, &__key);	\
 })
 
+struct class_compat;
+struct class_compat *class_compat_register(const char *name);
+void class_compat_unregister(struct class_compat *cls);
+int class_compat_create_link(struct class_compat *cls, struct device *dev);
+void class_compat_remove_link(struct class_compat *cls, struct device *dev);
+
 extern void class_dev_iter_init(struct class_dev_iter *iter,
 				struct class *class,
 				struct device *start,


--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux