* [PATCH] proc: use .%02u format
@ 2018-06-27 20:09 Alexey Dobriyan
0 siblings, 0 replies; only message in thread
From: Alexey Dobriyan @ 2018-06-27 20:09 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
Both /proc/loadavg and /proc/uptime use the following format string:
%lu.%02lu
Fractional part definitely doesn't need "unsigned long" as it is
by definition in [0, 99] range which fits into "unsigned int".
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
fs/proc/loadavg.c | 4 ++--
fs/proc/uptime.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
--- a/fs/proc/loadavg.c
+++ b/fs/proc/loadavg.c
@@ -11,7 +11,7 @@
#include <linux/time.h>
#define LOAD_INT(x) ((x) >> FSHIFT)
-#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
+#define LOAD_FRAC(x) LOAD_INT(((unsigned int)(x) & (FIXED_1 - 1)) * 100)
static int loadavg_proc_show(struct seq_file *m, void *v)
{
@@ -19,7 +19,7 @@ static int loadavg_proc_show(struct seq_file *m, void *v)
get_avenrun(avnrun, FIXED_1/200, 0);
- seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
+ seq_printf(m, "%lu.%02u %lu.%02u %lu.%02u %ld/%d %d\n",
LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
--- a/fs/proc/uptime.c
+++ b/fs/proc/uptime.c
@@ -22,11 +22,11 @@ static int uptime_proc_show(struct seq_file *m, void *v)
get_monotonic_boottime(&uptime);
idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
idle.tv_nsec = rem;
- seq_printf(m, "%lu.%02lu %lu.%02lu\n",
+ seq_printf(m, "%lu.%02u %lu.%02u\n",
(unsigned long) uptime.tv_sec,
- (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
+ (unsigned int)(uptime.tv_nsec / (NSEC_PER_SEC / 100)),
(unsigned long) idle.tv_sec,
- (idle.tv_nsec / (NSEC_PER_SEC / 100)));
+ (unsigned int)(idle.tv_nsec / (NSEC_PER_SEC / 100)));
return 0;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-06-27 20:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-27 20:09 [PATCH] proc: use .%02u format Alexey Dobriyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox