Skip to contentSkip to conversation

kobject: add the missing export for kobject_create()

PATCH In review Qu Wenruo 4 participants 6 messages Aug 31, 2021

Subsystems (3)
lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 kobject: add the missing export for kobject_create()

[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().

---
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(+)
lib/kobject.c +1 -0
index ea53b30cf483..af308cf7dba2 100644
@@ -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
Signature · 1 line
2.33.0
maintainer
#1 lore raw
Quoted 44 lines · Qu Wenruo

[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().

---
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(+)
lib/kobject.c +1 -0
index ea53b30cf483..af308cf7dba2 100644
@@ -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
Signature · 1 line
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

author
#2 lore raw
Quoted 40 lines · Greg KH
Quoted 39 lines · Qu Wenruo

[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().

---
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(+)
lib/kobject.c +1 -0
index ea53b30cf483..af308cf7dba2 100644
@@ -788,6 +788,7 @@ struct kobject *kobject_create(void)
  	kobject_init(kobj, &dynamic_kobj_ktype);
  	return kobj;
  }
+EXPORT_SYMBOL_GPL(kobject_create);
 
Quoted 8 lines
Quoted 5 lines
lib/kobject.c +0 -0
  /**
   * kobject_create_and_add() - Create a struct kobject dynamically and
Signature · 1 line
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

Quoted 5 lines

thanks,

greg k-h

maintainer
#3 lore raw
Quoted 51 lines · Qu Wenruo
Quoted 39 lines · Greg KH
Quoted 38 lines · Qu Wenruo

[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().

---
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(+)
lib/kobject.c +1 -0
index ea53b30cf483..af308cf7dba2 100644
@@ -788,6 +788,7 @@ struct kobject *kobject_create(void)
  	kobject_init(kobj, &dynamic_kobj_ktype);
  	return kobj;
  }
+EXPORT_SYMBOL_GPL(kobject_create);
Quoted 8 lines
Quoted 5 lines
lib/kobject.c +0 -0
  /**
   * kobject_create_and_add() - Create a struct kobject dynamically and
Signature · 1 line
2.33.0

What in-kernel module needs to call this function? No driver should be messing with calls to kobjects like this.

Quoted 2 lines

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.

Quoted 4 lines

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

#4 lore raw
Quoted 52 lines · Greg KH
Quoted 51 lines · Qu Wenruo
Quoted 47 lines · Greg KH
Quoted 41 lines · Qu Wenruo

[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().

---
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(+)
lib/kobject.c +1 -1
index ea53b30cf483..af308cf7dba2 100644
@@ -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
--
Quoted 2 lines

2.33.0

What in-kernel module needs to call this function? No driver should be messing with calls to kobjects like this.

Quoted 5 lines
Quoted 2 lines

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.

Quoted 9 lines
Quoted 5 lines

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

Quoted 5 lines

thanks,

greg k-h

#5 lore raw
In reply to Qu Wenruo
Quoted 19 lines · Qu Wenruo

[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().

Quoted 6 lines

---
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.

Quoted 17 lines
---
 lib/kobject.c | 1 +
 1 file changed, 1 insertion(+)
lib/kobject.c +1 -0
index ea53b30cf483..af308cf7dba2 100644
@@ -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