lkml.org 
[lkml]   [2020]   [Aug]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs
From
Date
On Fri, 2020-08-28 at 00:58 -0700, Kees Cook wrote:
> On Thu, Aug 27, 2020 at 09:12:06PM -0700, Joe Perches wrote:
> > Perhaps something like the below with a sample conversion
> > that uses single and multiple sysfs_emit uses.
>
> On quick review, I like it. :)
>
> > [...]
> > +int sysfs_emit(char *buf, char *pos, const char *fmt, ...)
> > +{
> > + int len;
> > + va_list args;
> > +
> > + WARN(pos < buf, "pos < buf\n");
> > + WARN(pos - buf >= PAGE_SIZE, "pos >= PAGE_SIZE (%tu > %lu)\n",
> > + pos - buf, PAGE_SIZE);
> > + if (pos < buf || pos - buf >= PAGE_SIZE)
> > + return 0;
>
> This can be:
>
> if (WARN(pos < buf, "pos < buf\n") ||
> WARN(pos - buf >= PAGE_SIZE, "pos >= PAGE_SIZE (%tu > %lu)\n",
> pos - buf, PAGE_SIZE))
> return 0;

I had some vague recollection that WARN could be compiled
away to nothing somehow. True or false?

If false, sure, of course, it'd be faster too.

\
 
 \ /
  Last update: 2020-08-28 10:10    [W:0.241 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site