Skip to content

Commit a754292

Browse files
committed
Merge tag 'printk-for-5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux
Pull printk updates from Petr Mladek: - Herbert Xu made printk header file self-contained. - Andy Shevchenko and Sergey Senozhatsky cleaned up console->setup() error handling. - Andy Shevchenko did some cleanups (e.g. sparse warning) in vsprintf code. - Minor documentation updates. * tag 'printk-for-5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux: lib/vsprintf: Force type of flags value for gfp_t lib/vsprintf: Replace custom spec to print decimals with generic one lib/vsprintf: Replace hidden BUILD_BUG_ON() with static_assert() printk: Make linux/printk.h self-contained doc:kmsg: explicitly state the return value in case of SEEK_CUR Replace HTTP links with HTTPS ones: vsprintf hvc: unify console setup naming console: Fix trivia typo 'change' -> 'chance' console: Propagate error code from console ->setup() tty: hvc: Return proper error code from console ->setup() hook serial: sunzilog: Return proper error code from console ->setup() hook serial: sunsab: Return proper error code from console ->setup() hook mips: Return proper error code from console ->setup() hook
2 parents 95ffa67 + 57e60db commit a754292

File tree

13 files changed

+86
-58
lines changed

13 files changed

+86
-58
lines changed

Documentation/ABI/testing/dev-kmsg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ Description: The /dev/kmsg character device node provides userspace access
5656
seek after the last record available at the time
5757
the last SYSLOG_ACTION_CLEAR was issued.
5858

59+
Other seek operations or offsets are not supported because of
60+
the special behavior this device has. The device allows to read
61+
or write only whole variable length messages (records) that are
62+
stored in a ring buffer.
63+
64+
Because of the non-standard behavior also the error values are
65+
non-standard. -ESPIPE is returned for non-zero offset. -EINVAL
66+
is returned for other operations, e.g. SEEK_CUR. This behavior
67+
and values are historical and could not be modified without the
68+
risk of breaking userspace.
69+
5970
The output format consists of a prefix carrying the syslog
6071
prefix including priority and facility, the 64 bit message
6172
sequence number and the monotonic timestamp in microseconds,

Documentation/core-api/printk-formats.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ colon-separators. Leading zeros are always used.
317317

318318
The additional ``c`` specifier can be used with the ``I`` specifier to
319319
print a compressed IPv6 address as described by
320-
http://tools.ietf.org/html/rfc5952
320+
https://tools.ietf.org/html/rfc5952
321321

322322
Passed by reference.
323323

@@ -341,7 +341,7 @@ The additional ``p``, ``f``, and ``s`` specifiers are used to specify port
341341
flowinfo a ``/`` and scope a ``%``, each followed by the actual value.
342342

343343
In case of an IPv6 address the compressed IPv6 address as described by
344-
http://tools.ietf.org/html/rfc5952 is being used if the additional
344+
https://tools.ietf.org/html/rfc5952 is being used if the additional
345345
specifier ``c`` is given. The IPv6 address is surrounded by ``[``, ``]`` in
346346
case of additional specifiers ``p``, ``f`` or ``s`` as suggested by
347347
https://tools.ietf.org/html/draft-ietf-6man-text-addr-representation-07

arch/mips/fw/arc/arc_con.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ static void prom_console_write(struct console *co, const char *s,
2828

2929
static int prom_console_setup(struct console *co, char *options)
3030
{
31-
return !(prom_flags & PROM_FLAG_USE_AS_CONSOLE);
31+
if (prom_flags & PROM_FLAG_USE_AS_CONSOLE)
32+
return 0;
33+
return -ENODEV;
3234
}
3335

3436
static struct console arc_cons = {

arch/s390/include/asm/bug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef _ASM_S390_BUG_H
33
#define _ASM_S390_BUG_H
44

5-
#include <linux/kernel.h>
5+
#include <linux/compiler.h>
66

77
#ifdef CONFIG_BUG
88

drivers/tty/hvc/hvc_xen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ static void xen_hvm_early_write(uint32_t vtermno, const char *str, int len) { }
603603
#endif
604604

605605
#ifdef CONFIG_EARLY_PRINTK
606-
static int __init xenboot_setup_console(struct console *console, char *string)
606+
static int __init xenboot_console_setup(struct console *console, char *string)
607607
{
608608
static struct xencons_info xenboot;
609609

@@ -647,7 +647,7 @@ static void xenboot_write_console(struct console *console, const char *string,
647647
struct console xenboot_console = {
648648
.name = "xenboot",
649649
.write = xenboot_write_console,
650-
.setup = xenboot_setup_console,
650+
.setup = xenboot_console_setup,
651651
.flags = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
652652
.index = -1,
653653
};

drivers/tty/hvc/hvsi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ static int __init hvsi_console_setup(struct console *console, char *options)
11281128
int ret;
11291129

11301130
if (console->index < 0 || console->index >= hvsi_count)
1131-
return -1;
1131+
return -EINVAL;
11321132
hp = &hvsi_ports[console->index];
11331133

11341134
/* give the FSP a chance to change the baud rate when we re-open */

drivers/tty/serial/sunsab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ static int sunsab_console_setup(struct console *con, char *options)
886886
* though...
887887
*/
888888
if (up->port.type != PORT_SUNSAB)
889-
return -1;
889+
return -EINVAL;
890890

891891
printk("Console: ttyS%d (SAB82532)\n",
892892
(sunsab_reg.minor - 64) + con->index);

drivers/tty/serial/sunzilog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ static int __init sunzilog_console_setup(struct console *con, char *options)
12211221
int baud, brg;
12221222

12231223
if (up->port.type != PORT_SUNZILOG)
1224-
return -1;
1224+
return -EINVAL;
12251225

12261226
printk(KERN_INFO "Console: ttyS%d (SunZilog zs%d)\n",
12271227
(sunzilog_reg.minor - 64) + con->index, con->index);

include/linux/printk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/kern_levels.h>
88
#include <linux/linkage.h>
99
#include <linux/cache.h>
10+
#include <linux/ratelimit_types.h>
1011

1112
extern const char linux_banner[];
1213
extern const char linux_proc_banner[];

include/linux/ratelimit.h

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,10 @@
22
#ifndef _LINUX_RATELIMIT_H
33
#define _LINUX_RATELIMIT_H
44

5-
#include <linux/param.h>
5+
#include <linux/ratelimit_types.h>
66
#include <linux/sched.h>
77
#include <linux/spinlock.h>
88

9-
#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
10-
#define DEFAULT_RATELIMIT_BURST 10
11-
12-
/* issue num suppressed message on exit */
13-
#define RATELIMIT_MSG_ON_RELEASE BIT(0)
14-
15-
struct ratelimit_state {
16-
raw_spinlock_t lock; /* protect the state */
17-
18-
int interval;
19-
int burst;
20-
int printed;
21-
int missed;
22-
unsigned long begin;
23-
unsigned long flags;
24-
};
25-
26-
#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) { \
27-
.lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
28-
.interval = interval_init, \
29-
.burst = burst_init, \
30-
}
31-
32-
#define RATELIMIT_STATE_INIT_DISABLED \
33-
RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)
34-
35-
#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \
36-
\
37-
struct ratelimit_state name = \
38-
RATELIMIT_STATE_INIT(name, interval_init, burst_init) \
39-
409
static inline void ratelimit_state_init(struct ratelimit_state *rs,
4110
int interval, int burst)
4211
{
@@ -73,9 +42,6 @@ ratelimit_set_flags(struct ratelimit_state *rs, unsigned long flags)
7342

7443
extern struct ratelimit_state printk_ratelimit_state;
7544

76-
extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
77-
#define __ratelimit(state) ___ratelimit(state, __func__)
78-
7945
#ifdef CONFIG_PRINTK
8046

8147
#define WARN_ON_RATELIMIT(condition, state) ({ \

include/linux/ratelimit_types.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_RATELIMIT_TYPES_H
3+
#define _LINUX_RATELIMIT_TYPES_H
4+
5+
#include <linux/bits.h>
6+
#include <linux/param.h>
7+
#include <linux/spinlock_types.h>
8+
9+
#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ)
10+
#define DEFAULT_RATELIMIT_BURST 10
11+
12+
/* issue num suppressed message on exit */
13+
#define RATELIMIT_MSG_ON_RELEASE BIT(0)
14+
15+
struct ratelimit_state {
16+
raw_spinlock_t lock; /* protect the state */
17+
18+
int interval;
19+
int burst;
20+
int printed;
21+
int missed;
22+
unsigned long begin;
23+
unsigned long flags;
24+
};
25+
26+
#define RATELIMIT_STATE_INIT(name, interval_init, burst_init) { \
27+
.lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
28+
.interval = interval_init, \
29+
.burst = burst_init, \
30+
}
31+
32+
#define RATELIMIT_STATE_INIT_DISABLED \
33+
RATELIMIT_STATE_INIT(ratelimit_state, 0, DEFAULT_RATELIMIT_BURST)
34+
35+
#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \
36+
\
37+
struct ratelimit_state name = \
38+
RATELIMIT_STATE_INIT(name, interval_init, burst_init) \
39+
40+
extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
41+
#define __ratelimit(state) ___ratelimit(state, __func__)
42+
43+
#endif /* _LINUX_RATELIMIT_TYPES_H */

kernel/printk/printk.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,14 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
943943
return ret;
944944
}
945945

946+
/*
947+
* Be careful when modifying this function!!!
948+
*
949+
* Only few operations are supported because the device works only with the
950+
* entire variable length messages (records). Non-standard values are
951+
* returned in the other cases and has been this way for quite some time.
952+
* User space applications might depend on this behavior.
953+
*/
946954
static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
947955
{
948956
struct devkmsg_user *user = file->private_data;
@@ -2658,7 +2666,7 @@ early_param("keep_bootcon", keep_bootcon_setup);
26582666
static int try_enable_new_console(struct console *newcon, bool user_specified)
26592667
{
26602668
struct console_cmdline *c;
2661-
int i;
2669+
int i, err;
26622670

26632671
for (i = 0, c = console_cmdline;
26642672
i < MAX_CMDLINECONSOLES && c->name[0];
@@ -2681,8 +2689,8 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
26812689
return 0;
26822690

26832691
if (newcon->setup &&
2684-
newcon->setup(newcon, c->options) != 0)
2685-
return -EIO;
2692+
(err = newcon->setup(newcon, c->options)) != 0)
2693+
return err;
26862694
}
26872695
newcon->flags |= CON_ENABLED;
26882696
if (i == preferred_console) {
@@ -2695,7 +2703,7 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
26952703
/*
26962704
* Some consoles, such as pstore and netconsole, can be enabled even
26972705
* without matching. Accept the pre-enabled consoles only when match()
2698-
* and setup() had a change to be called.
2706+
* and setup() had a chance to be called.
26992707
*/
27002708
if (newcon->flags & CON_ENABLED && c->user_specified == user_specified)
27012709
return 0;

lib/vsprintf.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ int num_to_str(char *buf, int size, unsigned long long num, unsigned int width)
381381
#define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
382382
#define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
383383

384+
static_assert(ZEROPAD == ('0' - ' '));
385+
static_assert(SMALL == ' ');
386+
384387
enum format_type {
385388
FORMAT_TYPE_NONE, /* Just a string part */
386389
FORMAT_TYPE_WIDTH,
@@ -507,7 +510,7 @@ char *number(char *buf, char *end, unsigned long long num,
507510
/* zero or space padding */
508511
if (!(spec.flags & LEFT)) {
509512
char c = ' ' + (spec.flags & ZEROPAD);
510-
BUILD_BUG_ON(' ' + ZEROPAD != '0');
513+
511514
while (--field_width >= 0) {
512515
if (buf < end)
513516
*buf = c;
@@ -1934,7 +1937,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr,
19341937
names = vmaflag_names;
19351938
break;
19361939
case 'g':
1937-
flags = *(gfp_t *)flags_ptr;
1940+
flags = (__force unsigned long)(*(gfp_t *)flags_ptr);
19381941
names = gfpflag_names;
19391942
break;
19401943
default:
@@ -1976,12 +1979,6 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
19761979
char *buf_start = buf;
19771980
struct property *prop;
19781981
bool has_mult, pass;
1979-
static const struct printf_spec num_spec = {
1980-
.flags = SMALL,
1981-
.field_width = -1,
1982-
.precision = -1,
1983-
.base = 10,
1984-
};
19851982

19861983
struct printf_spec str_spec = spec;
19871984
str_spec.field_width = -1;
@@ -2021,7 +2018,7 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
20212018
str_spec.precision = precision;
20222019
break;
20232020
case 'p': /* phandle */
2024-
buf = number(buf, end, (unsigned int)dn->phandle, num_spec);
2021+
buf = number(buf, end, (unsigned int)dn->phandle, default_dec_spec);
20252022
break;
20262023
case 'P': /* path-spec */
20272024
p = fwnode_get_name(of_fwnode_handle(dn));
@@ -2134,7 +2131,7 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode,
21342131
* [4] or [6] and is able to print port [p], flowinfo [f], scope [s]
21352132
* - '[Ii][4S][hnbl]' IPv4 addresses in host, network, big or little endian order
21362133
* - 'I[6S]c' for IPv6 addresses printed as specified by
2137-
* http://tools.ietf.org/html/rfc5952
2134+
* https://tools.ietf.org/html/rfc5952
21382135
* - 'E[achnops]' For an escaped buffer, where rules are defined by combination
21392136
* of the following flags (see string_escape_mem() for the
21402137
* details):

0 commit comments

Comments
 (0)