Skip to content

Commit bbeddf5

Browse files
JoePerchestorvalds
authored andcommitted
printk: move braille console support into separate braille.[ch] files
Create files with prototypes and static inlines for braille support. Make braille_console functions return 1 on success. Corrected CONFIG_A11Y_BRAILLE_CONSOLE=n _braille_console_setup return value to NULL. Signed-off-by: Joe Perches <joe@perches.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Cc: Ming Lei <ming.lei@canonical.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d197c43 commit bbeddf5

5 files changed

Lines changed: 117 additions & 33 deletions

File tree

‎drivers/accessibility/braille/braille_console.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ int braille_register_console(struct console *console, int index,
359359
char *console_options, char *braille_options)
360360
{
361361
int ret;
362+
363+
if (!(console->flags & CON_BRL))
364+
return 0;
362365
if (!console_options)
363366
/* Only support VisioBraille for now */
364367
console_options = "57600o8";
@@ -374,15 +377,17 @@ int braille_register_console(struct console *console, int index,
374377
braille_co = console;
375378
register_keyboard_notifier(&keyboard_notifier_block);
376379
register_vt_notifier(&vt_notifier_block);
377-
return 0;
380+
return 1;
378381
}
379382

380383
int braille_unregister_console(struct console *console)
381384
{
382385
if (braille_co != console)
383386
return -EINVAL;
387+
if (!(console->flags & CON_BRL))
388+
return 0;
384389
unregister_keyboard_notifier(&keyboard_notifier_block);
385390
unregister_vt_notifier(&vt_notifier_block);
386391
braille_co = NULL;
387-
return 0;
392+
return 1;
388393
}

‎kernel/printk/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
obj-y = printk.o
2+
obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o

‎kernel/printk/braille.c‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2+
3+
#include <linux/kernel.h>
4+
#include <linux/console.h>
5+
#include <linux/string.h>
6+
7+
#include "console_cmdline.h"
8+
#include "braille.h"
9+
10+
char *_braille_console_setup(char **str, char **brl_options)
11+
{
12+
if (!memcmp(*str, "brl,", 4)) {
13+
*brl_options = "";
14+
*str += 4;
15+
} else if (!memcmp(str, "brl=", 4)) {
16+
*brl_options = *str + 4;
17+
*str = strchr(*brl_options, ',');
18+
if (!*str)
19+
pr_err("need port name after brl=\n");
20+
else
21+
*((*str)++) = 0;
22+
}
23+
24+
return *str;
25+
}
26+
27+
int
28+
_braille_register_console(struct console *console, struct console_cmdline *c)
29+
{
30+
int rtn = 0;
31+
32+
if (c->brl_options) {
33+
console->flags |= CON_BRL;
34+
rtn = braille_register_console(console, c->index, c->options,
35+
c->brl_options);
36+
}
37+
38+
return rtn;
39+
}
40+
41+
int
42+
_braille_unregister_console(struct console *console)
43+
{
44+
if (console->flags & CON_BRL)
45+
return braille_unregister_console(console);
46+
47+
return 0;
48+
}

‎kernel/printk/braille.h‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef _PRINTK_BRAILLE_H
2+
#define _PRINTK_BRAILLE_H
3+
4+
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
5+
6+
static inline void
7+
braille_set_options(struct console_cmdline *c, char *brl_options)
8+
{
9+
c->brl_options = brl_options;
10+
}
11+
12+
char *
13+
_braille_console_setup(char **str, char **brl_options);
14+
15+
int
16+
_braille_register_console(struct console *console, struct console_cmdline *c);
17+
18+
int
19+
_braille_unregister_console(struct console *console);
20+
21+
#else
22+
23+
static inline void
24+
braille_set_options(struct console_cmdline *c, char *brl_options)
25+
{
26+
}
27+
28+
static inline char *
29+
_braille_console_setup(char **str, char **brl_options)
30+
{
31+
return NULL;
32+
}
33+
34+
static inline int
35+
_braille_register_console(struct console *console, struct console_cmdline *c)
36+
{
37+
return 0;
38+
}
39+
40+
static inline int
41+
_braille_unregister_console(struct console *console)
42+
{
43+
return 0;
44+
}
45+
46+
#endif
47+
48+
#endif

‎kernel/printk/printk.c‎

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <trace/events/printk.h>
5353

5454
#include "console_cmdline.h"
55+
#include "braille.h"
5556

5657
/* printk's without a loglevel use this.. */
5758
#define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL
@@ -1769,9 +1770,8 @@ static int __add_preferred_console(char *name, int idx, char *options,
17691770
c = &console_cmdline[i];
17701771
strlcpy(c->name, name, sizeof(c->name));
17711772
c->options = options;
1772-
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1773-
c->brl_options = brl_options;
1774-
#endif
1773+
braille_set_options(c, brl_options);
1774+
17751775
c->index = idx;
17761776
return 0;
17771777
}
@@ -1784,20 +1784,8 @@ static int __init console_setup(char *str)
17841784
char *s, *options, *brl_options = NULL;
17851785
int idx;
17861786

1787-
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1788-
if (!memcmp(str, "brl,", 4)) {
1789-
brl_options = "";
1790-
str += 4;
1791-
} else if (!memcmp(str, "brl=", 4)) {
1792-
brl_options = str + 4;
1793-
str = strchr(brl_options, ',');
1794-
if (!str) {
1795-
printk(KERN_ERR "need port name after brl=\n");
1796-
return 1;
1797-
}
1798-
*(str++) = 0;
1799-
}
1800-
#endif
1787+
if (_braille_console_setup(&str, &brl_options))
1788+
return 1;
18011789

18021790
/*
18031791
* Decode str into name, index, options.
@@ -2291,16 +2279,10 @@ void register_console(struct console *newcon)
22912279
continue;
22922280
if (newcon->index < 0)
22932281
newcon->index = console_cmdline[i].index;
2294-
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
2295-
if (console_cmdline[i].brl_options) {
2296-
newcon->flags |= CON_BRL;
2297-
braille_register_console(newcon,
2298-
console_cmdline[i].index,
2299-
console_cmdline[i].options,
2300-
console_cmdline[i].brl_options);
2282+
2283+
if (_braille_register_console(newcon, &console_cmdline[i]))
23012284
return;
2302-
}
2303-
#endif
2285+
23042286
if (newcon->setup &&
23052287
newcon->setup(newcon, console_cmdline[i].options) != 0)
23062288
break;
@@ -2388,13 +2370,13 @@ EXPORT_SYMBOL(register_console);
23882370
int unregister_console(struct console *console)
23892371
{
23902372
struct console *a, *b;
2391-
int res = 1;
2373+
int res;
23922374

2393-
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
2394-
if (console->flags & CON_BRL)
2395-
return braille_unregister_console(console);
2396-
#endif
2375+
res = _braille_unregister_console(console);
2376+
if (res)
2377+
return res;
23972378

2379+
res = 1;
23982380
console_lock();
23992381
if (console_drivers == console) {
24002382
console_drivers=console->next;

0 commit comments

Comments
 (0)