Message ID | b8122113-5863-4057-81b5-73f86c9fde4d@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | driver core: class: remove class_compat code | expand |
On Tue, Dec 03, 2024 at 09:10:05PM +0100, Heiner Kallweit wrote: > In preparation of removing class_compat support, add a helper for > creating a pseudo class in sysfs. This way we can keep class_kset > private to driver core. This helper will be used by vfio/mdev, > replacing the call to class_compat_create(). > > Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> > --- > drivers/base/class.c | 14 ++++++++++++++ > include/linux/device/class.h | 1 + > 2 files changed, 15 insertions(+) > > diff --git a/drivers/base/class.c b/drivers/base/class.c > index 582b5a02a..f812236e2 100644 > --- a/drivers/base/class.c > +++ b/drivers/base/class.c > @@ -578,6 +578,20 @@ struct class_compat *class_compat_register(const char *name) > } > EXPORT_SYMBOL_GPL(class_compat_register); > > +/** > + * class_pseudo_register - create a pseudo class entry in sysfs > + * @name: the name of the child > + * > + * Helper for creating a pseudo class in sysfs, keeps class_kset private > + * > + * Returns: the created kobject > + */ > +struct kobject *class_pseudo_register(const char *name) > +{ > + return kobject_create_and_add(name, &class_kset->kobj); > +} > +EXPORT_SYMBOL_GPL(class_pseudo_register); I see the goal here, but let's not continue on and create fake kobjects in places where there should NOT be any kobjects. Also, you might get in trouble when removing this kobject as it thinks it is a 'struct class' but yet it isn't, right? Did you test that? thanks, greg k-h
On 04.12.2024 10:33, Greg Kroah-Hartman wrote: > On Tue, Dec 03, 2024 at 09:10:05PM +0100, Heiner Kallweit wrote: >> In preparation of removing class_compat support, add a helper for >> creating a pseudo class in sysfs. This way we can keep class_kset >> private to driver core. This helper will be used by vfio/mdev, >> replacing the call to class_compat_create(). >> >> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> >> --- >> drivers/base/class.c | 14 ++++++++++++++ >> include/linux/device/class.h | 1 + >> 2 files changed, 15 insertions(+) >> >> diff --git a/drivers/base/class.c b/drivers/base/class.c >> index 582b5a02a..f812236e2 100644 >> --- a/drivers/base/class.c >> +++ b/drivers/base/class.c >> @@ -578,6 +578,20 @@ struct class_compat *class_compat_register(const char *name) >> } >> EXPORT_SYMBOL_GPL(class_compat_register); >> >> +/** >> + * class_pseudo_register - create a pseudo class entry in sysfs >> + * @name: the name of the child >> + * >> + * Helper for creating a pseudo class in sysfs, keeps class_kset private >> + * >> + * Returns: the created kobject >> + */ >> +struct kobject *class_pseudo_register(const char *name) >> +{ >> + return kobject_create_and_add(name, &class_kset->kobj); >> +} >> +EXPORT_SYMBOL_GPL(class_pseudo_register); > > I see the goal here, but let's not continue on and create fake kobjects > in places where there should NOT be any kobjects. Also, you might get > in trouble when removing this kobject as it thinks it is a 'struct > class' but yet it isn't, right? Did you test that? > It's removed using kobject_put(), same as what class_compat_unregister() does. I only compile-tested the changes. > thanks, > > greg k-h
On Wed, Dec 04, 2024 at 06:04:32PM +0100, Heiner Kallweit wrote: > On 04.12.2024 10:33, Greg Kroah-Hartman wrote: > > On Tue, Dec 03, 2024 at 09:10:05PM +0100, Heiner Kallweit wrote: > >> In preparation of removing class_compat support, add a helper for > >> creating a pseudo class in sysfs. This way we can keep class_kset > >> private to driver core. This helper will be used by vfio/mdev, > >> replacing the call to class_compat_create(). > >> > >> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> > >> --- > >> drivers/base/class.c | 14 ++++++++++++++ > >> include/linux/device/class.h | 1 + > >> 2 files changed, 15 insertions(+) > >> > >> diff --git a/drivers/base/class.c b/drivers/base/class.c > >> index 582b5a02a..f812236e2 100644 > >> --- a/drivers/base/class.c > >> +++ b/drivers/base/class.c > >> @@ -578,6 +578,20 @@ struct class_compat *class_compat_register(const char *name) > >> } > >> EXPORT_SYMBOL_GPL(class_compat_register); > >> > >> +/** > >> + * class_pseudo_register - create a pseudo class entry in sysfs > >> + * @name: the name of the child > >> + * > >> + * Helper for creating a pseudo class in sysfs, keeps class_kset private > >> + * > >> + * Returns: the created kobject > >> + */ > >> +struct kobject *class_pseudo_register(const char *name) > >> +{ > >> + return kobject_create_and_add(name, &class_kset->kobj); > >> +} > >> +EXPORT_SYMBOL_GPL(class_pseudo_register); > > > > I see the goal here, but let's not continue on and create fake kobjects > > in places where there should NOT be any kobjects. Also, you might get > > in trouble when removing this kobject as it thinks it is a 'struct > > class' but yet it isn't, right? Did you test that? > > > > It's removed using kobject_put(), same as what class_compat_unregister() does. > I only compile-tested the changes. I would not be able to take these unless someone actually runs them as the kobject removal here might be getting confused a bit. thanks, greg k-h
On 04.12.2024 19:17, Greg Kroah-Hartman wrote: > On Wed, Dec 04, 2024 at 06:04:32PM +0100, Heiner Kallweit wrote: >> On 04.12.2024 10:33, Greg Kroah-Hartman wrote: >>> On Tue, Dec 03, 2024 at 09:10:05PM +0100, Heiner Kallweit wrote: >>>> In preparation of removing class_compat support, add a helper for >>>> creating a pseudo class in sysfs. This way we can keep class_kset >>>> private to driver core. This helper will be used by vfio/mdev, >>>> replacing the call to class_compat_create(). >>>> >>>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> >>>> --- >>>> drivers/base/class.c | 14 ++++++++++++++ >>>> include/linux/device/class.h | 1 + >>>> 2 files changed, 15 insertions(+) >>>> >>>> diff --git a/drivers/base/class.c b/drivers/base/class.c >>>> index 582b5a02a..f812236e2 100644 >>>> --- a/drivers/base/class.c >>>> +++ b/drivers/base/class.c >>>> @@ -578,6 +578,20 @@ struct class_compat *class_compat_register(const char *name) >>>> } >>>> EXPORT_SYMBOL_GPL(class_compat_register); >>>> >>>> +/** >>>> + * class_pseudo_register - create a pseudo class entry in sysfs >>>> + * @name: the name of the child >>>> + * >>>> + * Helper for creating a pseudo class in sysfs, keeps class_kset private >>>> + * >>>> + * Returns: the created kobject >>>> + */ >>>> +struct kobject *class_pseudo_register(const char *name) >>>> +{ >>>> + return kobject_create_and_add(name, &class_kset->kobj); >>>> +} >>>> +EXPORT_SYMBOL_GPL(class_pseudo_register); >>> >>> I see the goal here, but let's not continue on and create fake kobjects >>> in places where there should NOT be any kobjects. Also, you might get >>> in trouble when removing this kobject as it thinks it is a 'struct >>> class' but yet it isn't, right? Did you test that? >>> >> >> It's removed using kobject_put(), same as what class_compat_unregister() does. >> I only compile-tested the changes. > > I would not be able to take these unless someone actually runs them as > the kobject removal here might be getting confused a bit. > Understood. Maybe Alex/Kirti can test. > thanks, > > greg k-h
diff --git a/drivers/base/class.c b/drivers/base/class.c index 582b5a02a..f812236e2 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -578,6 +578,20 @@ struct class_compat *class_compat_register(const char *name) } EXPORT_SYMBOL_GPL(class_compat_register); +/** + * class_pseudo_register - create a pseudo class entry in sysfs + * @name: the name of the child + * + * Helper for creating a pseudo class in sysfs, keeps class_kset private + * + * Returns: the created kobject + */ +struct kobject *class_pseudo_register(const char *name) +{ + return kobject_create_and_add(name, &class_kset->kobj); +} +EXPORT_SYMBOL_GPL(class_pseudo_register); + /** * class_compat_unregister - unregister a compatibility class * @cls: the class to unregister diff --git a/include/linux/device/class.h b/include/linux/device/class.h index 518c9c83d..8b6e890c7 100644 --- a/include/linux/device/class.h +++ b/include/linux/device/class.h @@ -86,6 +86,7 @@ int class_compat_create_link(struct class_compat *cls, struct device *dev, struct device *device_link); void class_compat_remove_link(struct class_compat *cls, struct device *dev, struct device *device_link); +struct kobject *class_pseudo_register(const char *name); void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class, const struct device *start, const struct device_type *type);
In preparation of removing class_compat support, add a helper for creating a pseudo class in sysfs. This way we can keep class_kset private to driver core. This helper will be used by vfio/mdev, replacing the call to class_compat_create(). Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/base/class.c | 14 ++++++++++++++ include/linux/device/class.h | 1 + 2 files changed, 15 insertions(+)