lkml.org 
[lkml]   [2013]   [Nov]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] Generic WorkQueue Engine (GenWQE) device driver (v4)
From
Date
Hi Ryan,

Am Donnerstag, den 31.10.2013, 14:49 +1100 schrieb Ryan Mallon:
> > +static ssize_t show_card_status(struct device *dev,
> > + struct device_attribute *attr,
> > + char *buf)
> > +{
> > + ssize_t len = 0;
> > + struct genwqe_dev *cd = dev_get_drvdata(dev);
> > + const char *cs[GENWQE_CARD_STATE_MAX] = { "unused", "used",
> "error" };
> > +
> > + len += scnprintf(&buf[len], PAGE_SIZE - len,
> > + "%s\n", cs[cd->card_state]);
> > + return len;
>
> This is a bit confusingly written. Why do:
>
> scnprintf(&buf[len], ...
>
> When len is always zero at that point? Since you are printing from an
> array of statically sized strings that are guaranteed to be smaller
> than
> PAGE_SIZE, you can safely do:
>
> sprintf(buf, "%s\n", cs[cd->card_state]);
>
> You might want to add some checking for cd->card_state being out of
> bounds, and printing "unknown" or something in that case.
>
> Same issue exists in other sysfs handlers.
>

I kept using scnprintf(), but reworked the code around it. ssize_t len
is not needed of course and the &buf[len] stuff is obsolete too. I had
sysfs entries with multiple lines of output, where it was convenient and
safe to code it like that. Now since those interfaces were moved to
debugfs, the sysfs code can be simpler, as you pointed it out.

Regards

Frank



\
 
 \ /
  Last update: 2013-11-04 18:21    [W:0.240 / U:0.292 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site