All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Simon Arlott <simon@fire.lp0.eu>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Duncan Sands <duncan.sands@math.u-psud.fr>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: Re: [PATCH (rev 2)] cxacru: Cleanup sysfs attribute code
Date: Sat, 28 Apr 2007 00:50:28 -0700	[thread overview]
Message-ID: <20070428005028.54f1b621.akpm@linux-foundation.org> (raw)
In-Reply-To: <462FA0D0.9040901@simon.arlott.org.uk>

On Wed, 25 Apr 2007 19:41:20 +0100 Simon Arlott <simon@fire.lp0.eu> wrote:

> This changes the format of unknown status values to be less verbose and 
> uses an array instead of several different snprintf calls. Since only 
> enum values are assigned to it, poll_state is changed from int to enum. 
> Use abs() for dB values instead of two almost identical return lines.
> 
> Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
> Cc: Greg Kroah-Hartman <gregkh@suse.de>
> Cc: Duncan Sands <duncan.sands@math.u-psud.fr>
> Cc: Andrew Morton <akpm@linux-foundation.org>
>
> ...
>  
>  static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
>  {
> -	switch (value) {
> -	case 0: return snprintf(buf, PAGE_SIZE, "no\n");
> -	case 1: return snprintf(buf, PAGE_SIZE, "yes\n");
> -	default: return 0;
> -	}
> +	static char *str[] = { "no", "yes" };
> +	if (unlikely(value >= ARRAY_SIZE(str)))
> +		return snprintf(buf, PAGE_SIZE, "%u\n", value);
> +	return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
>  }

Should a bool be displayed as "true" or "false"?

>  static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
>  {
>
> ...
>
> +		return snprintf(buf, PAGE_SIZE, "%u\n", value);
>  }

To be completely pedantic: we shouldn't be printing u32's with %u.  Because
%u assumes that u32 is implemented as unsigned int.  Only it's an opaque
type and we don't know what actual C type the architecture chose to use.

It happens to work OK on all architectures and I expect it always will, so
no change is needed, but there you have it.

u64's and %llu _are_ incompatible on some architectures and I get to fix
that about 1000000 times.


  parent reply	other threads:[~2007-04-28  7:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-24 21:13 [PATCH] cxacru: Cleanup sysfs attribute code Simon Arlott
2007-04-25  7:19 ` Duncan Sands
2007-04-25 11:18   ` Simon Arlott
2007-04-25 18:41     ` [PATCH (rev 2)] " Simon Arlott
2007-04-25 19:33       ` Duncan Sands
2007-04-28  7:50       ` Andrew Morton [this message]
2007-04-28  8:58         ` Simon Arlott

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=20070428005028.54f1b621.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=duncan.sands@math.u-psud.fr \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=simon@fire.lp0.eu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.