Skip to content

Commit e264abe

Browse files
committed
pstore: Remove bogus format string definition
The pstore conversion to timespec64 introduces its own method of passing seconds into sscanf() and sprintf() type functions to work around the timespec64 definition on 64-bit systems that redefine it to 'timespec'. That hack is now finally getting removed, but that means we get a (harmless) warning once both patches are merged: fs/pstore/ram.c: In function 'ramoops_read_kmsg_hdr': fs/pstore/ram.c:39:29: error: format '%ld' expects argument of type 'long int *', but argument 3 has type 'time64_t *' {aka 'long long int *'} [-Werror=format=] #define RAMOOPS_KERNMSG_HDR "====" ^~~~~~ fs/pstore/ram.c:167:21: note: in expansion of macro 'RAMOOPS_KERNMSG_HDR' This removes the pstore specific workaround and uses the same method that we have in place for all other functions that print a timespec64. Related to this, I found that the kasprintf() output contains an incorrect nanosecond values for any number starting with zeroes, and I adapt the format string accordingly. Link: https://lkml.org/lkml/2018/5/19/115 Link: https://lkml.org/lkml/2018/5/16/1080 Fixes: 0f0d83b99ef7 ("pstore: Convert internal records to timespec64") Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 15eefe2 commit e264abe

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

‎fs/pstore/ram.c‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838

3939
#define RAMOOPS_KERNMSG_HDR "===="
4040
#define MIN_MEM_SIZE 4096UL
41-
#if __BITS_PER_LONG == 64
42-
# define TVSEC_FMT "%ld"
43-
#else
44-
# define TVSEC_FMT "%lld"
45-
#endif
4641

4742
static ulong record_size = MIN_MEM_SIZE;
4843
module_param(record_size, ulong, 0400);
@@ -164,15 +159,15 @@ static int ramoops_read_kmsg_hdr(char *buffer, struct timespec64 *time,
164159
char data_type;
165160
int header_length = 0;
166161

167-
if (sscanf(buffer, RAMOOPS_KERNMSG_HDR TVSEC_FMT ".%lu-%c\n%n",
168-
&time->tv_sec, &time->tv_nsec, &data_type,
162+
if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lld.%lu-%c\n%n",
163+
(time64_t *)&time->tv_sec, &time->tv_nsec, &data_type,
169164
&header_length) == 3) {
170165
if (data_type == 'C')
171166
*compressed = true;
172167
else
173168
*compressed = false;
174-
} else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR TVSEC_FMT ".%lu\n%n",
175-
&time->tv_sec, &time->tv_nsec,
169+
} else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lld.%lu\n%n",
170+
(time64_t *)&time->tv_sec, &time->tv_nsec,
176171
&header_length) == 2) {
177172
*compressed = false;
178173
} else {
@@ -367,8 +362,8 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
367362
char *hdr;
368363
size_t len;
369364

370-
hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR TVSEC_FMT ".%lu-%c\n",
371-
record->time.tv_sec,
365+
hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n",
366+
(time64_t)record->time.tv_sec,
372367
record->time.tv_nsec / 1000,
373368
record->compressed ? 'C' : 'D');
374369
WARN_ON_ONCE(!hdr);

0 commit comments

Comments
 (0)