Message ID | 20210831065009.29358-1-wqu@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | kobject: add the missing export for kobject_create() | expand |
On Tue, Aug 31, 2021 at 02:50:09PM +0800, Qu Wenruo wrote: > [BUG] > For any module utilizing kobject_create(), it will lead to link error: > > $ make M=fs/btrfs -j12 > CC [M] fs/btrfs/sysfs.o > LD [M] fs/btrfs/btrfs.o > MODPOST fs/btrfs/Module.symvers > ERROR: modpost: "kobject_create" [fs/btrfs/btrfs.ko] undefined! > make[1]: *** [scripts/Makefile.modpost:150: fs/btrfs/Module.symvers] Error 1 > make[1]: *** Deleting file 'fs/btrfs/Module.symvers' > make: *** [Makefile:1766: modules] Error 2 > > [CAUSE] > It's pretty straight forward, kobject_create() doesn't have > EXPORT_SYMBOL_GPL(). > > [FIX] > Fix it by adding the missing EXPORT_SYMBOL_GPL(). > > Signed-off-by: Qu Wenruo <wqu@suse.com> > --- > A little surprised by the fact that no know even is calling > kobject_create() now. > > Or should we just call kmalloc() manually then kobject_init_and_add()? > --- > lib/kobject.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/lib/kobject.c b/lib/kobject.c > index ea53b30cf483..af308cf7dba2 100644 > --- a/lib/kobject.c > +++ b/lib/kobject.c > @@ -788,6 +788,7 @@ struct kobject *kobject_create(void) > kobject_init(kobj, &dynamic_kobj_ktype); > return kobj; > } > +EXPORT_SYMBOL_GPL(kobject_create); > > /** > * kobject_create_and_add() - Create a struct kobject dynamically and > -- > 2.33.0 > What in-kernel module needs to call this function? No driver should be messing with calls to kobjects like this. thanks, greg k-h
On 31.08.21 г. 9:50, Qu Wenruo wrote: > [BUG] > For any module utilizing kobject_create(), it will lead to link error: > > $ make M=fs/btrfs -j12 > CC [M] fs/btrfs/sysfs.o > LD [M] fs/btrfs/btrfs.o > MODPOST fs/btrfs/Module.symvers > ERROR: modpost: "kobject_create" [fs/btrfs/btrfs.ko] undefined! > make[1]: *** [scripts/Makefile.modpost:150: fs/btrfs/Module.symvers] Error 1 > make[1]: *** Deleting file 'fs/btrfs/Module.symvers' > make: *** [Makefile:1766: modules] Error 2 > > [CAUSE] > It's pretty straight forward, kobject_create() doesn't have > EXPORT_SYMBOL_GPL(). > > [FIX] > Fix it by adding the missing EXPORT_SYMBOL_GPL(). > > Signed-off-by: Qu Wenruo <wqu@suse.com> > --- > A little surprised by the fact that no know even is calling > kobject_create() now. > > Or should we just call kmalloc() manually then kobject_init_and_add()? There is kobject_create_and_add which seems to be the preferred public API. > --- > lib/kobject.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/lib/kobject.c b/lib/kobject.c > index ea53b30cf483..af308cf7dba2 100644 > --- a/lib/kobject.c > +++ b/lib/kobject.c > @@ -788,6 +788,7 @@ struct kobject *kobject_create(void) > kobject_init(kobj, &dynamic_kobj_ktype); > return kobj; > } > +EXPORT_SYMBOL_GPL(kobject_create); > > /** > * kobject_create_and_add() - Create a struct kobject dynamically and >
On 2021/8/31 下午2:57, Greg KH wrote: > On Tue, Aug 31, 2021 at 02:50:09PM +0800, Qu Wenruo wrote: >> [BUG] >> For any module utilizing kobject_create(), it will lead to link error: >> >> $ make M=fs/btrfs -j12 >> CC [M] fs/btrfs/sysfs.o >> LD [M] fs/btrfs/btrfs.o >> MODPOST fs/btrfs/Module.symvers >> ERROR: modpost: "kobject_create" [fs/btrfs/btrfs.ko] undefined! >> make[1]: *** [scripts/Makefile.modpost:150: fs/btrfs/Module.symvers] Error 1 >> make[1]: *** Deleting file 'fs/btrfs/Module.symvers' >> make: *** [Makefile:1766: modules] Error 2 >> >> [CAUSE] >> It's pretty straight forward, kobject_create() doesn't have >> EXPORT_SYMBOL_GPL(). >> >> [FIX] >> Fix it by adding the missing EXPORT_SYMBOL_GPL(). >> >> Signed-off-by: Qu Wenruo <wqu@suse.com> >> --- >> A little surprised by the fact that no know even is calling >> kobject_create() now. >> >> Or should we just call kmalloc() manually then kobject_init_and_add()? >> --- >> lib/kobject.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/lib/kobject.c b/lib/kobject.c >> index ea53b30cf483..af308cf7dba2 100644 >> --- a/lib/kobject.c >> +++ b/lib/kobject.c >> @@ -788,6 +788,7 @@ struct kobject *kobject_create(void) >> kobject_init(kobj, &dynamic_kobj_ktype); >> return kobj; >> } >> +EXPORT_SYMBOL_GPL(kobject_create); >> >> /** >> * kobject_create_and_add() - Create a struct kobject dynamically and >> -- >> 2.33.0 >> > > What in-kernel module needs to call this function? No driver should be > messing with calls to kobjects like this. But kobject_create_and_add() can't specify ktype if we want extra attributes to the new kobject. Or is the following way the preferred call style? local_kobj = kmalloc(); ret = kobject_init_and_add(); Then I guess we should not export kobject_create() at all even in its header. Thanks, Qu > > thanks, > > greg k-h >
On Tue, Aug 31, 2021 at 03:53:02PM +0800, Qu Wenruo wrote: > > > On 2021/8/31 下午2:57, Greg KH wrote: > > On Tue, Aug 31, 2021 at 02:50:09PM +0800, Qu Wenruo wrote: > > > [BUG] > > > For any module utilizing kobject_create(), it will lead to link error: > > > > > > $ make M=fs/btrfs -j12 > > > CC [M] fs/btrfs/sysfs.o > > > LD [M] fs/btrfs/btrfs.o > > > MODPOST fs/btrfs/Module.symvers > > > ERROR: modpost: "kobject_create" [fs/btrfs/btrfs.ko] undefined! > > > make[1]: *** [scripts/Makefile.modpost:150: fs/btrfs/Module.symvers] Error 1 > > > make[1]: *** Deleting file 'fs/btrfs/Module.symvers' > > > make: *** [Makefile:1766: modules] Error 2 > > > > > > [CAUSE] > > > It's pretty straight forward, kobject_create() doesn't have > > > EXPORT_SYMBOL_GPL(). > > > > > > [FIX] > > > Fix it by adding the missing EXPORT_SYMBOL_GPL(). > > > > > > Signed-off-by: Qu Wenruo <wqu@suse.com> > > > --- > > > A little surprised by the fact that no know even is calling > > > kobject_create() now. > > > > > > Or should we just call kmalloc() manually then kobject_init_and_add()? > > > --- > > > lib/kobject.c | 1 + > > > 1 file changed, 1 insertion(+) > > > > > > diff --git a/lib/kobject.c b/lib/kobject.c > > > index ea53b30cf483..af308cf7dba2 100644 > > > --- a/lib/kobject.c > > > +++ b/lib/kobject.c > > > @@ -788,6 +788,7 @@ struct kobject *kobject_create(void) > > > kobject_init(kobj, &dynamic_kobj_ktype); > > > return kobj; > > > } > > > +EXPORT_SYMBOL_GPL(kobject_create); > > > /** > > > * kobject_create_and_add() - Create a struct kobject dynamically and > > > -- > > > 2.33.0 > > > > > > > What in-kernel module needs to call this function? No driver should be > > messing with calls to kobjects like this. > > But kobject_create_and_add() can't specify ktype if we want extra attributes > to the new kobject. You didn't answer this question, what in-kernel driver needs this? We do not export things that are not needed to be exported. > Or is the following way the preferred call style? > > local_kobj = kmalloc(); > ret = kobject_init_and_add(); Depends on your need. Why do you need to call this function from a module? thanks, greg k-h
On 2021/9/1 上午4:04, Greg KH wrote: > On Tue, Aug 31, 2021 at 03:53:02PM +0800, Qu Wenruo wrote: >> >> >> On 2021/8/31 下午2:57, Greg KH wrote: >>> On Tue, Aug 31, 2021 at 02:50:09PM +0800, Qu Wenruo wrote: >>>> [BUG] >>>> For any module utilizing kobject_create(), it will lead to link error: >>>> >>>> $ make M=fs/btrfs -j12 >>>> CC [M] fs/btrfs/sysfs.o >>>> LD [M] fs/btrfs/btrfs.o >>>> MODPOST fs/btrfs/Module.symvers >>>> ERROR: modpost: "kobject_create" [fs/btrfs/btrfs.ko] undefined! >>>> make[1]: *** [scripts/Makefile.modpost:150: fs/btrfs/Module.symvers] Error 1 >>>> make[1]: *** Deleting file 'fs/btrfs/Module.symvers' >>>> make: *** [Makefile:1766: modules] Error 2 >>>> >>>> [CAUSE] >>>> It's pretty straight forward, kobject_create() doesn't have >>>> EXPORT_SYMBOL_GPL(). >>>> >>>> [FIX] >>>> Fix it by adding the missing EXPORT_SYMBOL_GPL(). >>>> >>>> Signed-off-by: Qu Wenruo <wqu@suse.com> >>>> --- >>>> A little surprised by the fact that no know even is calling >>>> kobject_create() now. >>>> >>>> Or should we just call kmalloc() manually then kobject_init_and_add()? >>>> --- >>>> lib/kobject.c | 1 + >>>> 1 file changed, 1 insertion(+) >>>> >>>> diff --git a/lib/kobject.c b/lib/kobject.c >>>> index ea53b30cf483..af308cf7dba2 100644 >>>> --- a/lib/kobject.c >>>> +++ b/lib/kobject.c >>>> @@ -788,6 +788,7 @@ struct kobject *kobject_create(void) >>>> kobject_init(kobj, &dynamic_kobj_ktype); >>>> return kobj; >>>> } >>>> +EXPORT_SYMBOL_GPL(kobject_create); >>>> /** >>>> * kobject_create_and_add() - Create a struct kobject dynamically and >>>> -- >>>> 2.33.0 >>>> >>> >>> What in-kernel module needs to call this function? No driver should be >>> messing with calls to kobjects like this. >> >> But kobject_create_and_add() can't specify ktype if we want extra attributes >> to the new kobject. > > You didn't answer this question, what in-kernel driver needs this? We > do not export things that are not needed to be exported. Then the function should not be declared in kobject.h either. Originally I just want a dynamically allocated kobject with extra attributes. Thus I look into the callers of kobject_create_and_add(), and lsp points to the header where just one line before kobject_create_and_add(), there comes kobject_create(). But after more reading into kobject.c, kobject_create() creates kobject with dynamic ktype, thus in theory we shouldn't change its type halfway. > >> Or is the following way the preferred call style? >> >> local_kobj = kmalloc(); >> ret = kobject_init_and_add(); > > Depends on your need. > > Why do you need to call this function from a module? As explained, a want a dynamically allocated kobject while has extra attributes. As kobject_create_and_add() can't have extra attributes, while kobject_init_and_add() needs an existing kobject. But now I understand why it's not that possible, as kobject_create() will initialize its dynamic ktype, thus with its .release function fixed. Currently I go the kmalloc() then kobject_init_and_add() way instead, and the .release is just the same as the dynamic ktype to kfree() the kobject. Thus I send a new patch to unexport kobject_create() from kobject.h. Thanks, Qu > > thanks, > > greg k-h >
diff --git a/lib/kobject.c b/lib/kobject.c index ea53b30cf483..af308cf7dba2 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -788,6 +788,7 @@ struct kobject *kobject_create(void) kobject_init(kobj, &dynamic_kobj_ktype); return kobj; } +EXPORT_SYMBOL_GPL(kobject_create); /** * kobject_create_and_add() - Create a struct kobject dynamically and
[BUG] For any module utilizing kobject_create(), it will lead to link error: $ make M=fs/btrfs -j12 CC [M] fs/btrfs/sysfs.o LD [M] fs/btrfs/btrfs.o MODPOST fs/btrfs/Module.symvers ERROR: modpost: "kobject_create" [fs/btrfs/btrfs.ko] undefined! make[1]: *** [scripts/Makefile.modpost:150: fs/btrfs/Module.symvers] Error 1 make[1]: *** Deleting file 'fs/btrfs/Module.symvers' make: *** [Makefile:1766: modules] Error 2 [CAUSE] It's pretty straight forward, kobject_create() doesn't have EXPORT_SYMBOL_GPL(). [FIX] Fix it by adding the missing EXPORT_SYMBOL_GPL(). Signed-off-by: Qu Wenruo <wqu@suse.com> --- A little surprised by the fact that no know even is calling kobject_create() now. Or should we just call kmalloc() manually then kobject_init_and_add()? --- lib/kobject.c | 1 + 1 file changed, 1 insertion(+)