Skip to contentSkip to conversation

The use of KOBJ_NAME_LEN

DISCUSSION Dave Young 3 participants 9 messages Dec 4, 2007

Subsystems (2)
lore
Share & tools
lore

Dave Young

author
#0 lore raw

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

In the kobject_set_name, the limit is 1024. Looks like either the comment or the code should be updated.

/**

 *      kobject_set_name - Set the name of an object
 *      @kobj:  object.
 *      @fmt:   format string used to build the name
 *
 *      If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
 *      string that @kobj->k_name points to. Otherwise, use the static 
 *      @kobj->name array.

*/

Regards
dave

#1 lore raw
Quoted 6 lines · Dave Young

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

In the kobject_set_name, the limit is 1024. Looks like either the comment or the code should be updated.

/**

Quoted 8 lines
 *      kobject_set_name - Set the name of an object
 *      @kobj:  object.
 *      @fmt:   format string used to build the name
 *
 *      If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
 *      string that @kobj->k_name points to. Otherwise, use the static
 *      @kobj->name array.

*/

the comment seems fairly clear -- if the name is sufficiently short, it's stored in the static array. if not, then it's stored in dynamically allocated space.

rday
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

author
#2 lore raw
Quoted 18 lines · Robert P. J. Day
Quoted 6 lines · Dave Young

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

In the kobject_set_name, the limit is 1024. Looks like either the comment or the code should be updated.

/**

Quoted 8 lines
 *      kobject_set_name - Set the name of an object
 *      @kobj:  object.
 *      @fmt:   format string used to build the name
 *
 *      If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
 *      string that @kobj->k_name points to. Otherwise, use the static
 *      @kobj->name array.

*/

Quoted 3 lines

the comment seems fairly clear -- if the name is sufficiently short, it's stored in the static array. if not, then it's stored in dynamically allocated space.

Yes, It's clear, but it is not the topic I talk about. Please look at the KOBJ_NAME_LEN macro usage.

Quoted 10 lines

rday
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

#5 lore raw
In reply to Dave Young
Quoted 3 lines · Dave Young

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

No, not anymore, the kobject name is totally dynamic.

Quoted 2 lines

In the kobject_set_name, the limit is 1024. Looks like either the comment or the code should be updated.

Here's a patch below for the comment updating it.

I also have a patch in my -mm series that takes away the 1024 character limit, but for 2.6.24 we'll have to live with it :)

thanks,

greg k-h

---
 lib/kobject.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
lib/kobject.c +6 -6
@@ -234,13 +234,13 @@ int kobject_register(struct kobject * ko
 
 
 /**
- *	kobject_set_name - Set the name of an object
- *	@kobj:	object.
- *	@fmt:	format string used to build the name
+ * kobject_set_name - Set the name of a kobject
+ * @kobj: kobject to name
+ * @fmt: format string used to build the name
  *
- *	If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
- *	string that @kobj->k_name points to. Otherwise, use the static 
- *	@kobj->name array.
+ * This sets the name of the kobject.  If you have already added the
+ * kobject to the system, you must call kobject_rename() in order to
+ * change the name of the kobject.
  */
 int kobject_set_name(struct kobject * kobj, const char * fmt, ...)
 {
#3 lore raw
In reply to Robert P. J. Day
Quoted 17 lines · Robert P. J. Day
Quoted 6 lines · Dave Young

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

In the kobject_set_name, the limit is 1024. Looks like either the comment or the code should be updated.

/**

Quoted 8 lines
 *      kobject_set_name - Set the name of an object
 *      @kobj:  object.
 *      @fmt:   format string used to build the name
 *
 *      If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
 *      string that @kobj->k_name points to. Otherwise, use the static
 *      @kobj->name array.

*/

Quoted 3 lines

the comment seems fairly clear -- if the name is sufficiently short, it's stored in the static array. if not, then it's stored in dynamically allocated space.

Unfortunately, it's totally wrong, the code was updated by the comment wasn't, sorry. See my patch to fix this.

thanks,

greg k-h

author
#6 lore raw
In reply to Greg KH
Quoted 6 lines · Greg KH
Quoted 3 lines · Dave Young

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

No, not anymore, the kobject name is totally dynamic.

Eh, Why does this macro still exist? If KOBJ_NAME_LEN is really needed, maybe it should be renamed to something else to avoid misleading.

Quoted 5 lines
Quoted 3 lines

In the kobject_set_name, the limit is 1024. Looks like either the comment or the code should be updated.

Here's a patch below for the comment updating it.

Thanks

Quoted 36 lines

I also have a patch in my -mm series that takes away the 1024 character limit, but for 2.6.24 we'll have to live with it :)

thanks,

greg k-h

---
 lib/kobject.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
lib/kobject.c +6 -6
@@ -234,13 +234,13 @@ int kobject_register(struct kobject * ko
 
 
 /**
- *     kobject_set_name - Set the name of an object
- *     @kobj:  object.
- *     @fmt:   format string used to build the name
+ * kobject_set_name - Set the name of a kobject
+ * @kobj: kobject to name
+ * @fmt: format string used to build the name
  *
- *     If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
- *     string that @kobj->k_name points to. Otherwise, use the static
- *     @kobj->name array.
+ * This sets the name of the kobject.  If you have already added the
+ * kobject to the system, you must call kobject_rename() in order to
+ * change the name of the kobject.
  */
 int kobject_set_name(struct kobject * kobj, const char * fmt, ...)
 {
#4 lore raw
In reply to Greg KH
Quoted 18 lines · Greg KH
Quoted 17 lines · Robert P. J. Day
Quoted 14 lines · Dave Young

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

In the kobject_set_name, the limit is 1024. Looks like either the comment or the code should be updated.

/**

 *      kobject_set_name - Set the name of an object
 *      @kobj:  object.
 *      @fmt:   format string used to build the name
 *
 *      If strlen(name) >= KOBJ_NAME_LEN, then use a dynamically allocated
 *      string that @kobj->k_name points to. Otherwise, use the static
 *      @kobj->name array.

*/

Quoted 6 lines
Quoted 3 lines

the comment seems fairly clear -- if the name is sufficiently short, it's stored in the static array. if not, then it's stored in dynamically allocated space.

Unfortunately, it's totally wrong, the code was updated by the comment wasn't, sorry. See my patch to fix this.

ah, quite right, now i see what dave was talking about.

rday
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

#7 lore raw
In reply to Dave Young
Quoted 11 lines · Dave Young
Quoted 6 lines · Greg KH
Quoted 3 lines · Dave Young

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

No, not anymore, the kobject name is totally dynamic.

Eh, Why does this macro still exist? If KOBJ_NAME_LEN is really needed, maybe it should be renamed to something else to avoid misleading.

Right now other .h files use it also. It isn't hurting anything for now, and Kay has some patches he is working on to get rid of the static bus_id array, which will then let us get rid of that define entirely.

thanks,

greg k-h

author
#8 lore raw
Quoted 9 lines · Greg KH
Quoted 8 lines · Dave Young
Quoted 6 lines · Greg KH
Quoted 3 lines · Dave Young

Hi,
Does the KOBJ_NAME_LEN really means the limit of kobject name length? seems not . And if it's true, is the KOBJ_NAME_LEN of 20 enough to use?

No, not anymore, the kobject name is totally dynamic.

Quoted 8 lines
Quoted 3 lines

Eh, Why does this macro still exist? If KOBJ_NAME_LEN is really needed, maybe it should be renamed to something else to avoid misleading.

Right now other .h files use it also. It isn't hurting anything for now, and Kay has some patches he is working on to get rid of the static bus_id array, which will then let us get rid of that define entirely.

Good to know, thanks!

Quoted 4 lines

thanks,

greg k-h