Skip to contentSkip to conversation

kobject_add unreachable code

PATCH Martin Stoilov 4 participants 6 messages Dec 29, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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:

lib/kobject.c 2006-12-28 20:00:25.000000000 -0800 renamed from lib/kobject.c 2006-12-28 19:59:56.000000000 -0800 +1 -1
@@ -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

#1 lore raw
Quoted 9 lines · Martin Stoilov

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;
    }
Quoted 3 lines

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.

#2 lore raw
Quoted 12 lines · Olaf Dietsche
Quoted 9 lines · Martin Stoilov

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;
    }
Quoted 7 lines
Quoted 4 lines

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.

Quoted 8 lines

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

#3 lore raw
Quoted 23 lines · Martin Stoilov
Quoted 13 lines · Olaf Dietsche
Quoted 9 lines · Martin Stoilov

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;
    }
Quoted 8 lines
Quoted 5 lines

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.

Quoted 8 lines

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.

Quoted 18 lines
Quoted 9 lines

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/

(quoted diff) +0 -2
-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/

#4 lore raw
Quoted 18 lines · Martin Stoilov
Quoted 11 lines · Olaf Dietsche
Quoted 9 lines · Martin Stoilov

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;
    }
Quoted 5 lines
Quoted 4 lines

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.

Quoted 7 lines

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'
#5 lore raw
In reply to Martin Stoilov
Quoted 35 lines · Martin Stoilov
Quoted 23 lines · Martin Stoilov
Quoted 13 lines · Olaf Dietsche
Quoted 9 lines · Martin Stoilov

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;
    }
Quoted 8 lines
Quoted 5 lines

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.

Quoted 8 lines

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:

Quoted 7 lines

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.