mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul Menage" <menage@google.com>
To: "Adrian Bunk" <bunk@kernel.org>
Cc: "Paul Jackson" <pj@sgi.com>, linux-kernel@vger.kernel.org
Subject: Re: [2.6 patch] kernel/cgroup.c: remove dead code
Date: Wed, 24 Oct 2007 09:30:23 -0700	[thread overview]
Message-ID: <6599ad830710240930r6649dec0q21b8c00f7d8a796a@mail.gmail.com> (raw)
In-Reply-To: <20071024162534.GZ30533@stusta.de>

I think I'd rather not make this change - if we later changed the size
of release_agent_path[] this could silently fail. Can we get around
the coverity checker somehow?

Paul

On 10/24/07, Adrian Bunk <bunk@kernel.org> wrote:
> This patch removes dead code spotted by the Coverity checker
> (look at the "(nbytes >= PATH_MAX)" check).
>
> Signed-off-by: Adrian Bunk <bunk@kernel.org>
>
> ---
>
>  kernel/cgroup.c |   18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
>
> --- linux-2.6/kernel/cgroup.c.old       2007-10-23 18:37:43.000000000 +0200
> +++ linux-2.6/kernel/cgroup.c   2007-10-23 18:39:15.000000000 +0200
> @@ -1320,90 +1320,88 @@ static ssize_t cgroup_common_file_write(
>
>         if (nbytes >= PATH_MAX)
>                 return -E2BIG;
>
>         /* +1 for nul-terminator */
>         buffer = kmalloc(nbytes + 1, GFP_KERNEL);
>         if (buffer == NULL)
>                 return -ENOMEM;
>
>         if (copy_from_user(buffer, userbuf, nbytes)) {
>                 retval = -EFAULT;
>                 goto out1;
>         }
>         buffer[nbytes] = 0;     /* nul-terminate */
>
>         mutex_lock(&cgroup_mutex);
>
>         if (cgroup_is_removed(cgrp)) {
>                 retval = -ENODEV;
>                 goto out2;
>         }
>
>         switch (type) {
>         case FILE_TASKLIST:
>                 retval = attach_task_by_pid(cgrp, buffer);
>                 break;
>         case FILE_NOTIFY_ON_RELEASE:
>                 clear_bit(CGRP_RELEASABLE, &cgrp->flags);
>                 if (simple_strtoul(buffer, NULL, 10) != 0)
>                         set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
>                 else
>                         clear_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
>                 break;
>         case FILE_RELEASE_AGENT:
>         {
>                 struct cgroupfs_root *root = cgrp->root;
>                 /* Strip trailing newline */
>                 if (nbytes && (buffer[nbytes-1] == '\n')) {
>                         buffer[nbytes-1] = 0;
>                 }
> -               if (nbytes < sizeof(root->release_agent_path)) {
> -                       /* We never write anything other than '\0'
> -                        * into the last char of release_agent_path,
> -                        * so it always remains a NUL-terminated
> -                        * string */
> -                       strncpy(root->release_agent_path, buffer, nbytes);
> -                       root->release_agent_path[nbytes] = 0;
> -               } else {
> -                       retval = -ENOSPC;
> -               }
> +
> +               /* We never write anything other than '\0'
> +                * into the last char of release_agent_path,
> +                * so it always remains a NUL-terminated
> +                * string */
> +               strncpy(root->release_agent_path, buffer, nbytes);
> +               root->release_agent_path[nbytes] = 0;
> +
>                 break;
>         }
>         default:
>                 retval = -EINVAL;
>                 goto out2;
>         }
>
>         if (retval == 0)
>                 retval = nbytes;
>  out2:
>         mutex_unlock(&cgroup_mutex);
>  out1:
>         kfree(buffer);
>         return retval;
>  }
>
>  static ssize_t cgroup_file_write(struct file *file, const char __user *buf,
>                                                 size_t nbytes, loff_t *ppos)
>  {
>         struct cftype *cft = __d_cft(file->f_dentry);
>         struct cgroup *cgrp = __d_cgrp(file->f_dentry->d_parent);
>
>         if (!cft)
>                 return -ENODEV;
>         if (cft->write)
>                 return cft->write(cgrp, cft, file, buf, nbytes, ppos);
>         if (cft->write_uint)
>                 return cgroup_write_uint(cgrp, cft, file, buf, nbytes, ppos);
>         return -EINVAL;
>  }
>
>  static ssize_t cgroup_read_uint(struct cgroup *cgrp, struct cftype *cft,
>                                    struct file *file,
>                                    char __user *buf, size_t nbytes,
>                                    loff_t *ppos)
>  {
>         char tmp[64];
>         u64 val = cft->read_uint(cgrp, cft);
>         int len = sprintf(tmp, "%llu\n", (unsigned long long) val);
>
>
>

  reply	other threads:[~2007-10-24 16:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-24 16:25 Adrian Bunk
2007-10-24 16:30 ` Paul Menage [this message]
2007-10-24 17:07   ` Adrian Bunk
2007-10-24 17:13     ` Paul Menage
2007-10-24 17:34   ` Paul Jackson
2007-10-26  1:10     ` Paul Menage
2007-10-26  1:19       ` Adrian Bunk
2007-10-26  1:24       ` Paul Jackson
2007-10-26  1:26         ` Paul Menage
2007-10-26  1:37           ` Paul Jackson
2007-10-26  1:30         ` Adrian Bunk

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=6599ad830710240930r6649dec0q21b8c00f7d8a796a@mail.gmail.com \
    --to=menage@google.com \
    --cc=bunk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pj@sgi.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®