lkml.org 
[lkml]   [2020]   [Sep]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [RFC v8 01/10] mm/damon/debugfs: Allow users to set initial monitoring target regions
Date
On Mon, 31 Aug 2020 20:08:44 +0200 Marco Elver <elver@google.com> wrote:

> On Mon, Aug 31, 2020 at 12:47PM +0200, SeongJae Park wrote:
> [...]
> > diff --git a/mm/damon.c b/mm/damon.c
> > index 7e3c8c82a010..9815d22fc4de 100644
> > --- a/mm/damon.c
> > +++ b/mm/damon.c
> > @@ -2001,6 +2001,147 @@ static ssize_t debugfs_record_write(struct file *file,
> > return ret;
> > }
> >
> > +static ssize_t sprint_init_regions(struct damon_ctx *c, char *buf, ssize_t len)
> > +{
> > + struct damon_target *t;
> > + struct damon_region *r;
> > + int written = 0;
> > + int rc;
> > +
> > + damon_for_each_target(t, c) {
> > + damon_for_each_region(r, t) {
> > + rc = snprintf(&buf[written], len - written,
> > + "%lu %lu %lu\n",
> > + t->id, r->ar.start, r->ar.end);
>
> This most likely will not work as intended, because snprintf() returns
> "[...] the number of characters which would be generated for the given
> input, excluding the trailing null [...]". Would scnprintf() -- which
> returns "[...] the number of characters written into @buf not including
> the trailing '\0' [...]" -- do what you intended?

Ah, you're right! I will use 'scnprintf' instead, not only here but in other
relevant parts.


Thanks,
SeongJae Park

>
> > + if (!rc)
> > + return -ENOMEM;
> > + written += rc;
> > + }
> > + }
> > + return written;
> > +}
> [...]

\
 
 \ /
  Last update: 2020-09-01 08:36    [W:0.053 / U:0.448 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site