2007-12-04 06:45:25

by Dave Young

[permalink] [raw]
Subject: The use of KOBJ_NAME_LEN

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


2007-12-04 06:51:15

by Robert P. J. Day

[permalink] [raw]
Subject: Re: The use of KOBJ_NAME_LEN

On Tue, 4 Dec 2007, Dave Young wrote:

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

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

2007-12-04 07:17:42

by Dave Young

[permalink] [raw]
Subject: Re: The use of KOBJ_NAME_LEN

On Dec 4, 2007 2:50 PM, Robert P. J. Day <[email protected]> wrote:
>
> On Tue, 4 Dec 2007, Dave Young wrote:
>
> > 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.
> > */
>
> 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.

>
> rday
> ========================================================================
> Robert P. J. Day
> Linux Consulting, Training and Annoying Kernel Pedantry
> Waterloo, Ontario, CANADA
>
> http://crashcourse.ca
> ========================================================================
>

2007-12-04 07:44:25

by Greg KH

[permalink] [raw]
Subject: Re: The use of KOBJ_NAME_LEN

On Tue, Dec 04, 2007 at 02:45:47PM +0800, Dave Young wrote:
> 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.

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

--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -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, ...)
{

2007-12-04 07:44:43

by Greg KH

[permalink] [raw]
Subject: Re: The use of KOBJ_NAME_LEN

On Tue, Dec 04, 2007 at 01:50:53AM -0500, Robert P. J. Day wrote:
> On Tue, 4 Dec 2007, Dave Young wrote:
>
> > 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.
> > */
>
> 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

2007-12-04 07:53:25

by Dave Young

[permalink] [raw]
Subject: Re: The use of KOBJ_NAME_LEN

On Dec 4, 2007 3:46 PM, Greg KH <[email protected]> wrote:
> On Tue, Dec 04, 2007 at 02:45:47PM +0800, Dave Young wrote:
> > 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.

>
> > 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
>
> 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(-)
>
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -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, ...)
> {
>

2007-12-04 08:02:17

by Robert P. J. Day

[permalink] [raw]
Subject: Re: The use of KOBJ_NAME_LEN

On Mon, 3 Dec 2007, Greg KH wrote:

> On Tue, Dec 04, 2007 at 01:50:53AM -0500, Robert P. J. Day wrote:
> > On Tue, 4 Dec 2007, Dave Young wrote:
> >
> > > 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.
> > > */
> >
> > 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
========================================================================

2007-12-04 08:18:31

by Greg KH

[permalink] [raw]
Subject: Re: The use of KOBJ_NAME_LEN

On Tue, Dec 04, 2007 at 03:53:15PM +0800, Dave Young wrote:
> On Dec 4, 2007 3:46 PM, Greg KH <[email protected]> wrote:
> > On Tue, Dec 04, 2007 at 02:45:47PM +0800, Dave Young wrote:
> > > 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

2007-12-04 08:22:22

by Dave Young

[permalink] [raw]
Subject: Re: The use of KOBJ_NAME_LEN

On Dec 4, 2007 4:20 PM, Greg KH <[email protected]> wrote:
> On Tue, Dec 04, 2007 at 03:53:15PM +0800, Dave Young wrote:
> > On Dec 4, 2007 3:46 PM, Greg KH <[email protected]> wrote:
> > > On Tue, Dec 04, 2007 at 02:45:47PM +0800, Dave Young wrote:
> > > > 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.
>

Good to know, thanks!

> thanks,
>
> greg k-h
>