LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/5] proc: simpler iterations for /proc/*/cmdline
Date: Fri, 20 Apr 2018 22:46:28 +0300	[thread overview]
Message-ID: <20180420194628.GB3003@avx2> (raw)
In-Reply-To: <20180419171520.444c0e9736b6a020fb6b3b7f@linux-foundation.org>

On Thu, Apr 19, 2018 at 05:15:20PM -0700, Andrew Morton wrote:
> On Wed, 21 Feb 2018 22:30:09 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > "rv" variable is used both as a counter of bytes transferred and
> > an error value holder but it can be reduced solely to error values
> > if original start of userspace buffer is stashed and used at the very
> > end.
> > 
> > ...
> >
> > --- a/fs/proc/base.c
> > +++ b/fs/proc/base.c
> >
> > ...
> >
> > @@ -371,12 +365,16 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
> >  		}
> >  	}
> >  
> > +end:
> > +	free_page((unsigned long)page);
> > +	mmput(mm);
> > +	*pos += buf - buf0;
> > +	return buf - buf0;
> > +
> >  out_free_page:
> >  	free_page((unsigned long)page);
> >  out_mmput:
> >  	mmput(mm);
> > -	if (rv > 0)
> > -		*pos += rv;
> >  	return rv;
> >  }
> 
> (scratches head).  Why not do this?
> 
> --- a/fs/proc/base.c~proc-simpler-iterations-for-proc-cmdline-fix
> +++ a/fs/proc/base.c
> @@ -363,11 +363,8 @@ static ssize_t proc_pid_cmdline_read(str
>  	}
>  
>  end:
> -	free_page((unsigned long)page);
> -	mmput(mm);
>  	*pos += buf - buf0;
> -	return buf - buf0;
> -
> +	rv = buf - buf0;
>  out_free_page:
>  	free_page((unsigned long)page);
>  out_mmput:
> 
> (and maybe rv should be ssize_t)

It should as cmdline area can be set to arbitrary values.

I hate ssize_t and it's bloat.

	$ ./scripts/bloat-o-meter ../vmlinux-000 ../obj/vmlinux
	add/remove: 0/0 grow/shrink: 1/0 up/down: 11/0 (11)
	Function                                     old     new   delta
	proc_pid_cmdline_read                        867     878     +11

  reply	other threads:[~2018-04-20 19:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-21 19:23 [PATCH 1/5] proc: make /proc/*/cmdline go through LSM Alexey Dobriyan
2018-02-21 19:26 ` [PATCH 2/5] proc: more "unsigned int" in /proc/*/cmdline Alexey Dobriyan
2018-02-21 19:27   ` [PATCH 3/5] proc: somewhat simpler code for /proc/*/cmdline Alexey Dobriyan
2018-02-21 19:30     ` [PATCH 4/5] proc: simpler iterations " Alexey Dobriyan
2018-02-21 19:33       ` [PATCH 5/5] proc: deduplicate /proc/*/cmdline implementation Alexey Dobriyan
2018-04-20  0:15       ` [PATCH 4/5] proc: simpler iterations for /proc/*/cmdline Andrew Morton
2018-04-20 19:46         ` Alexey Dobriyan [this message]
2018-02-21 19:28 ` [PATCH 1/5] proc: make /proc/*/cmdline go through LSM Andy Shevchenko
2018-02-21 19:39   ` Alexey Dobriyan
2018-02-21 20:06 ` Andrew Morton
2018-02-23 19:43   ` [PATCH v2 " Alexey Dobriyan
2018-04-20  0:02 ` [PATCH " Andrew Morton
2018-04-20 19:25   ` Alexey Dobriyan

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=20180420194628.GB3003@avx2 \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH 4/5] proc: simpler iterations for /proc/*/cmdline' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).