On Mon, 31 Aug 2020 20:08:44 +0200 Marco Elver <el...@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;
> > +}
> [...]

Reply via email to