All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Stoilov <mstoilov@odesys.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] kobject: kobj->k_name verification fix
Date: Fri, 29 Dec 2006 14:01:24 -0800	[thread overview]
Message-ID: <45959034.6050702@odesys.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1498 bytes --]

The function 'kobject_add' tries to verify the name of
a new kobject instance is properly set before continuing.
    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;
    }
The statement:
    if (!kobj->k_name) {
        pr_debug("kobject attempted to be registered with no name!\n");
        WARN_ON(1);
        return -EINVAL;
    }
is useless the way it is right now, because it can never be true. I
think the
code was intended to be:
    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;
    }
because this would make sure the kobj->name buffer has something in it.
So the missing '*' is just a typo. Although, I would much prefer
expression like:
    if (*kobj->k_name == '\0') {
        pr_debug("kobject attempted to be registered with no name!\n");
        WARN_ON(1);
        return -EINVAL;
    }
because this would've made the intention clear, in this patch
I just restore the missing '*' without changing the coding style of
the function.

It looks like thunderbird client replaces the tabs with spaces even if I say
'paste without formatting'. Don't know how to insert the patch intact in
the
body of the message. Attaching the patch.

Signed-off-by: Martin Stoilov <mstoilov@odesys.com>
---



[-- Attachment #2: kobject_add.patch --]
[-- Type: text/x-patch, Size: 500 bytes --]

diff -pNru linux-2.6.20-rc2/lib/kobject.c linux-2.6.20-rc2.mod/lib/kobject.c
--- linux-2.6.20-rc2/lib/kobject.c	2006-12-29 11:48:30.000000000 -0800
+++ linux-2.6.20-rc2.mod/lib/kobject.c	2006-12-29 11:50:42.000000000 -0800
@@ -167,7 +167,7 @@ int kobject_add(struct kobject * 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;

                 reply	other threads:[~2006-12-29 22:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45959034.6050702@odesys.com \
    --to=mstoilov@odesys.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.