mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Haverkamp <haver@linux.vnet.ibm.com>
To: Ryan Mallon <rmallon@gmail.com>
Cc: linux-kernel@vger.kernel.org, arnd@arndb.de,
	gregkh@linuxfoundation.org, cody@linux.vnet.ibm.com,
	schwidefsky@de.ibm.com, utz.bacher@de.ibm.com, mmarek@suse.cz,
	jsvogt@de.ibm.com, MIJUNG@de.ibm.com,
	cascardo@linux.vnet.ibm.com, michael@ibmra.de,
	Frank Haverkamp <haver@vnet.ibm.com>
Subject: Re: [PATCH] Generic WorkQueue Engine (GenWQE) device driver (v4)
Date: Mon, 04 Nov 2013 17:44:01 +0100	[thread overview]
Message-ID: <1383583441.15642.31.camel@oc7383187364.ibm.com> (raw)
In-Reply-To: <5271D340.2090706@gmail.com>

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


  reply	other threads:[~2013-11-04 16:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30  9:32 Frank Haverkamp
2013-10-30  9:32 ` Frank Haverkamp
2013-10-30 17:35   ` Greg KH
2013-10-30 20:38     ` Ryan Mallon
2013-11-04 16:19       ` Frank Haverkamp
2013-11-04 16:18     ` Frank Haverkamp
2013-10-30 17:36   ` Greg KH
2013-11-04 16:20     ` Frank Haverkamp
2013-10-30 17:37   ` Greg KH
2013-11-04 16:30     ` Frank Haverkamp
2013-10-30 17:39   ` Greg KH
2013-10-30 17:44   ` Greg KH
2013-11-04 16:41     ` Frank Haverkamp
2013-11-04 22:15       ` Greg KH
2013-11-05  7:16         ` Frank Haverkamp
2013-11-05 12:50           ` Greg KH
2013-10-31  3:49   ` Ryan Mallon
2013-11-04 16:44     ` Frank Haverkamp [this message]
2013-11-04 16:45     ` Frank Haverkamp
2013-11-12 13:50 ` Pavel Machek
2013-11-13 12:36   ` Frank Haverkamp

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=1383583441.15642.31.camel@oc7383187364.ibm.com \
    --to=haver@linux.vnet.ibm.com \
    --cc=MIJUNG@de.ibm.com \
    --cc=arnd@arndb.de \
    --cc=cascardo@linux.vnet.ibm.com \
    --cc=cody@linux.vnet.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haver@vnet.ibm.com \
    --cc=jsvogt@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@ibmra.de \
    --cc=mmarek@suse.cz \
    --cc=rmallon@gmail.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=utz.bacher@de.ibm.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®