2006-12-29 07:47:56

by Martin Stoilov

[permalink] [raw]
Subject: kobject_add unreachable code

The following code in kobject_add
if (!kobj->k_name)
kobj->k_name = kobj->name;
if (!kobj->k_name) {
pr_debug("kobject attempted to be registered with no name!\n");
WARN_ON(1);
return -EINVAL;
}

doesn't look right to me. The second 'if' statement looks useless after
the assignment in the first one. May be it was meant to be like:
if (!*kobj->k_name)

See the full patch:

--- linux-2.6.20-rc2/lib/kobject.c 2006-12-28 19:59:56.000000000 -0800
+++ linux-2.6.20-rc2.mod/lib/kobject.c 2006-12-28 20:00:25.000000000 -0800
@@ -161,19 +161,19 @@
int kobject_add(struct kobject * kobj)
{
int error = 0;
struct kobject * parent;

if (!(kobj = kobject_get(kobj)))
return -ENOENT;
if (!kobj->k_name)
kobj->k_name = kobj->name;
- if (!kobj->k_name) {
+ if (!*kobj->k_name) {
pr_debug("kobject attempted to be registered with no
name!\n");
WARN_ON(1);
return -EINVAL;
}
parent = kobject_get(kobj->parent);


-Martin


2006-12-29 13:55:55

by Olaf Dietsche

[permalink] [raw]
Subject: Re: kobject_add unreachable code

Martin Stoilov <[email protected]> writes:

> The following code in kobject_add
> if (!kobj->k_name)
> kobj->k_name = kobj->name;
> if (!kobj->k_name) {
> pr_debug("kobject attempted to be registered with no name!\n");
> WARN_ON(1);
> return -EINVAL;
> }
>
> doesn't look right to me. The second 'if' statement looks useless after
> the assignment in the first one. May be it was meant to be like:
> if (!*kobj->k_name)

The second test is true, if kobj->name is NULL as well.

Regards, Olaf.

2006-12-29 17:15:22

by Martin Stoilov

[permalink] [raw]
Subject: Re: kobject_add unreachable code

Olaf Dietsche wrote:
> Martin Stoilov <[email protected]> writes:
>
>
>> The following code in kobject_add
>> if (!kobj->k_name)
>> kobj->k_name = kobj->name;
>> if (!kobj->k_name) {
>> pr_debug("kobject attempted to be registered with no name!\n");
>> WARN_ON(1);
>> return -EINVAL;
>> }
>>
>> doesn't look right to me. The second 'if' statement looks useless after
>> the assignment in the first one. May be it was meant to be like:
>> if (!*kobj->k_name)
>>
>
> The second test is true, if kobj->name is NULL as well.
>
And how would that ever be true? kobj->name is a buffer inside kobj:

struct kobject <http://localhost/lxr/http/ident?i=kobject> {
const char * k_name;
char name <http://localhost/lxr/http/ident?i=name>[KOBJ_NAME_LEN <http://localhost/lxr/http/ident?i=KOBJ_NAME_LEN>];

kobj->name will not be NULL, even if kobj itself is NULL.

> Regards, Olaf.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
>

-Martin

2006-12-29 17:36:47

by Martin Stoilov

[permalink] [raw]
Subject: Re: kobject_add unreachable code

Martin Stoilov wrote:
> Olaf Dietsche wrote:
>
>> Martin Stoilov <[email protected]> writes:
>>
>>
>>
>>> The following code in kobject_add
>>> if (!kobj->k_name)
>>> kobj->k_name = kobj->name;
>>> if (!kobj->k_name) {
>>> pr_debug("kobject attempted to be registered with no name!\n");
>>> WARN_ON(1);
>>> return -EINVAL;
>>> }
>>>
>>> doesn't look right to me. The second 'if' statement looks useless after
>>> the assignment in the first one. May be it was meant to be like:
>>> if (!*kobj->k_name)
>>>
>>>
>> The second test is true, if kobj->name is NULL as well.
>>
>>
> And how would that ever be true? kobj->name is a buffer inside kobj:
>
> struct kobject <http://localhost/lxr/http/ident?i=kobject> {
> const char * k_name;
> char name <http://localhost/lxr/http/ident?i=name>[KOBJ_NAME_LEN <http://localhost/lxr/http/ident?i=KOBJ_NAME_LEN>];
>
> kobj->name will not be NULL, even if kobj itself is NULL.
>

Oops, I am sorry for sending badly formated text! Here it is:

I don't understand how would that ever be true? kobj->name is a buffer inside kobj:

struct kobject {
const char * k_name;
char name[KOBJ_NAME_LEN];

kobj->name will not be NULL, even if kobj itself is NULL.


>> Regards, Olaf.
>> -
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
>>
>>
>>
>
> -Martin
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
>

2006-12-29 17:46:06

by Jan Engelhardt

[permalink] [raw]
Subject: Re: kobject_add unreachable code


On Dec 29 2006 09:36, Martin Stoilov wrote:
> Olaf Dietsche wrote:
>> Martin Stoilov <[email protected]> writes:
>>
>>> The following code in kobject_add
>>> if (!kobj->k_name)
>>> kobj->k_name = kobj->name;
>>> if (!kobj->k_name) {
>>> pr_debug("kobject attempted to be registered with no name!\n");
>>> WARN_ON(1);
>>> return -EINVAL;
>>> }
>>>
>>> doesn't look right to me. The second 'if' statement looks useless after
>>> the assignment in the first one. May be it was meant to be like:
>>> if (!*kobj->k_name)
>>>
>> The second test is true, if kobj->name is NULL as well.
>
>I don't understand how would that ever be true? kobj->name is a buffer inside kobj:
>
>struct kobject {
> const char * k_name;
> char name[KOBJ_NAME_LEN];
>
>kobj->name will not be NULL, even if kobj itself is NULL.

So you probably found a bug. Maybe this was intended then?

if (!kobj->k_name)
kobj->k_name = kobj->name;
if (*kobj->k_name == '\0') {
pr_debug("kobject attempted to be registered with no name!\n");
WARN_ON(1);
return -EINVAL;
}


-`J'
--

2006-12-29 20:49:29

by Olaf Dietsche

[permalink] [raw]
Subject: Re: kobject_add unreachable code

Martin Stoilov <[email protected]> writes:

> Martin Stoilov wrote:
>> Olaf Dietsche wrote:
>>
>>> Martin Stoilov <[email protected]> writes:
>>>
>>>
>>>
>>>> The following code in kobject_add
>>>> if (!kobj->k_name)
>>>> kobj->k_name = kobj->name;
>>>> if (!kobj->k_name) {
>>>> pr_debug("kobject attempted to be registered with no name!\n");
>>>> WARN_ON(1);
>>>> return -EINVAL;
>>>> }
>>>>
>>>> doesn't look right to me. The second 'if' statement looks useless after
>>>> the assignment in the first one. May be it was meant to be like:
>>>> if (!*kobj->k_name)
>>>>
>>>>
>>> The second test is true, if kobj->name is NULL as well.
>>>
>>>
>> And how would that ever be true? kobj->name is a buffer inside kobj:
>>
>> struct kobject <http://localhost/lxr/http/ident?i=kobject> {
>> const char * k_name;
>> char name <http://localhost/lxr/http/ident?i=name>[KOBJ_NAME_LEN <http://localhost/lxr/http/ident?i=KOBJ_NAME_LEN>];
>>
>> kobj->name will not be NULL, even if kobj itself is NULL.
>>
>
> Oops, I am sorry for sending badly formated text! Here it is:
>
> I don't understand how would that ever be true? kobj->name is a buffer inside kobj:
>
> struct kobject {
> const char * k_name;
> char name[KOBJ_NAME_LEN];
>
> kobj->name will not be NULL, even if kobj itself is NULL.

Shame on me! I just looked at kobject_add() without a clue about struct
kobject. You're right, of course.

Regards, Olaf.