Skip to content

Commit 8b390ab

Browse files
committed
Merge branch 'for-5.8-printf-time64_t' into for-linus
2 parents d053cf0 + 5f1fcf8 commit 8b390ab

File tree

5 files changed

+55
-29
lines changed

5 files changed

+55
-29
lines changed

Documentation/core-api/printk-formats.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,23 @@ Examples (OF)::
468468
%pfwf /ocp@68000000/i2c@48072000/camera@10/port/endpoint - Full name
469469
%pfwP endpoint - Node name
470470

471-
Time and date (struct rtc_time)
472-
-------------------------------
471+
Time and date
472+
-------------
473473

474474
::
475475

476-
%ptR YYYY-mm-ddTHH:MM:SS
477-
%ptRd YYYY-mm-dd
478-
%ptRt HH:MM:SS
479-
%ptR[dt][r]
476+
%pt[RT] YYYY-mm-ddTHH:MM:SS
477+
%pt[RT]d YYYY-mm-dd
478+
%pt[RT]t HH:MM:SS
479+
%pt[RT][dt][r]
480480

481-
For printing date and time as represented by struct rtc_time structure in
482-
human readable format.
481+
For printing date and time as represented by
482+
R struct rtc_time structure
483+
T time64_t type
484+
in human readable format.
483485

484-
By default year will be incremented by 1900 and month by 1. Use %ptRr (raw)
485-
to suppress this behaviour.
486+
By default year will be incremented by 1900 and month by 1.
487+
Use %pt[RT]r (raw) to suppress this behaviour.
486488

487489
Passed by reference.
488490

drivers/firmware/raspberrypi.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,10 @@ rpi_firmware_print_firmware_revision(struct rpi_firmware *fw)
182182
RPI_FIRMWARE_GET_FIRMWARE_REVISION,
183183
&packet, sizeof(packet));
184184

185-
if (ret == 0) {
186-
struct tm tm;
187-
188-
time64_to_tm(packet, 0, &tm);
185+
if (ret)
186+
return;
189187

190-
dev_info(fw->cl.dev,
191-
"Attached to firmware from %04ld-%02d-%02d %02d:%02d\n",
192-
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
193-
tm.tm_hour, tm.tm_min);
194-
}
188+
dev_info(fw->cl.dev, "Attached to firmware from %ptT\n", &packet);
195189
}
196190

197191
static void

drivers/media/usb/pulse8-cec/pulse8-cec.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ static int pulse8_setup(struct pulse8 *pulse8, struct serio *serio,
661661
u8 *data = pulse8->data + 1;
662662
u8 cmd[2];
663663
int err;
664-
struct tm tm;
665664
time64_t date;
666665

667666
pulse8->vers = 0;
@@ -682,10 +681,7 @@ static int pulse8_setup(struct pulse8 *pulse8, struct serio *serio,
682681
if (err)
683682
return err;
684683
date = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
685-
time64_to_tm(date, 0, &tm);
686-
dev_info(pulse8->dev, "Firmware build date %04ld.%02d.%02d %02d:%02d:%02d\n",
687-
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
688-
tm.tm_hour, tm.tm_min, tm.tm_sec);
684+
dev_info(pulse8->dev, "Firmware build date %ptT\n", &date);
689685

690686
dev_dbg(pulse8->dev, "Persistent config:\n");
691687
cmd[0] = MSGCODE_GET_AUTO_ENABLED;

lib/test_printf.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ struct_va_format(void)
478478
}
479479

480480
static void __init
481-
struct_rtc_time(void)
481+
time_and_date(void)
482482
{
483483
/* 1543210543 */
484484
const struct rtc_time tm = {
@@ -489,14 +489,21 @@ struct_rtc_time(void)
489489
.tm_mon = 10,
490490
.tm_year = 118,
491491
};
492+
/* 2019-01-04T15:32:23 */
493+
time64_t t = 1546615943;
492494

493-
test("(%ptR?)", "%pt", &tm);
495+
test("(%pt?)", "%pt", &tm);
494496
test("2018-11-26T05:35:43", "%ptR", &tm);
495497
test("0118-10-26T05:35:43", "%ptRr", &tm);
496498
test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm);
497499
test("05:35:43|0118-10-26", "%ptRtr|%ptRdr", &tm, &tm);
498500
test("05:35:43|2018-11-26", "%ptRttr|%ptRdtr", &tm, &tm);
499501
test("05:35:43 tr|2018-11-26 tr", "%ptRt tr|%ptRd tr", &tm, &tm);
502+
503+
test("2019-01-04T15:32:23", "%ptT", &t);
504+
test("0119-00-04T15:32:23", "%ptTr", &t);
505+
test("15:32:23|2019-01-04", "%ptTt|%ptTd", &t, &t);
506+
test("15:32:23|0119-00-04", "%ptTtr|%ptTdr", &t, &t);
500507
}
501508

502509
static void __init
@@ -661,7 +668,7 @@ test_pointer(void)
661668
uuid();
662669
dentry();
663670
struct_va_format();
664-
struct_rtc_time();
671+
time_and_date();
665672
struct_clk();
666673
bitmap();
667674
netdev_features();

lib/vsprintf.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/dcache.h>
3535
#include <linux/cred.h>
3636
#include <linux/rtc.h>
37+
#include <linux/time.h>
3738
#include <linux/uuid.h>
3839
#include <linux/of.h>
3940
#include <net/addrconf.h>
@@ -1819,15 +1820,40 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm,
18191820
return buf;
18201821
}
18211822

1823+
static noinline_for_stack
1824+
char *time64_str(char *buf, char *end, const time64_t time,
1825+
struct printf_spec spec, const char *fmt)
1826+
{
1827+
struct rtc_time rtc_time;
1828+
struct tm tm;
1829+
1830+
time64_to_tm(time, 0, &tm);
1831+
1832+
rtc_time.tm_sec = tm.tm_sec;
1833+
rtc_time.tm_min = tm.tm_min;
1834+
rtc_time.tm_hour = tm.tm_hour;
1835+
rtc_time.tm_mday = tm.tm_mday;
1836+
rtc_time.tm_mon = tm.tm_mon;
1837+
rtc_time.tm_year = tm.tm_year;
1838+
rtc_time.tm_wday = tm.tm_wday;
1839+
rtc_time.tm_yday = tm.tm_yday;
1840+
1841+
rtc_time.tm_isdst = 0;
1842+
1843+
return rtc_str(buf, end, &rtc_time, spec, fmt);
1844+
}
1845+
18221846
static noinline_for_stack
18231847
char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec,
18241848
const char *fmt)
18251849
{
18261850
switch (fmt[1]) {
18271851
case 'R':
18281852
return rtc_str(buf, end, (const struct rtc_time *)ptr, spec, fmt);
1853+
case 'T':
1854+
return time64_str(buf, end, *(const time64_t *)ptr, spec, fmt);
18291855
default:
1830-
return error_string(buf, end, "(%ptR?)", spec);
1856+
return error_string(buf, end, "(%pt?)", spec);
18311857
}
18321858
}
18331859

@@ -2143,8 +2169,9 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode,
21432169
* - 'd[234]' For a dentry name (optionally 2-4 last components)
21442170
* - 'D[234]' Same as 'd' but for a struct file
21452171
* - 'g' For block_device name (gendisk + partition number)
2146-
* - 't[R][dt][r]' For time and date as represented:
2172+
* - 't[RT][dt][r]' For time and date as represented by:
21472173
* R struct rtc_time
2174+
* T time64_t
21482175
* - 'C' For a clock, it prints the name (Common Clock Framework) or address
21492176
* (legacy clock framework) of the clock
21502177
* - 'Cn' For a clock, it prints the name (Common Clock Framework) or address

0 commit comments

Comments
 (0)