[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20070428005028.54f1b621.akpm@linux-foundation.org>
Date: Sat, 28 Apr 2007 00:50:28 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Simon Arlott <simon@...e.lp0.eu>
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Duncan Sands <duncan.sands@...h.u-psud.fr>,
Greg Kroah-Hartman <gregkh@...e.de>
Subject: Re: [PATCH (rev 2)] cxacru: Cleanup sysfs attribute code
On Wed, 25 Apr 2007 19:41:20 +0100 Simon Arlott <simon@...e.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@...e.lp0.eu>
> Cc: Greg Kroah-Hartman <gregkh@...e.de>
> Cc: Duncan Sands <duncan.sands@...h.u-psud.fr>
> Cc: Andrew Morton <akpm@...ux-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.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists