2017-03-19 14:38:19

by Samuel Thibault

[permalink] [raw]
Subject: [PATCH] braille-console: Fix value returned by _braille_console_setup

commit bbeddf52adc1 ("printk: move braille console support into
separate braille.[ch] files") introduced _braille_console_setup()
to outline the braille initialization code. There was however some
confusion over the value it was supposed to return. commit 2cfe6c4ac7ee
("printk: Fix return of braille_register_console()") tried to fix it
but failed to.

This fixes and documents the returned value according to the use
in printk.c: non-zero return means a parsing error, and thus this
console configuration should be ignored.

Signed-off-by: Samuel Thibault <[email protected]>
Cc: Aleksey Makarov <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Ming Lei <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Petr Mladek <[email protected]>

Index: linux-4.10/kernel/printk/braille.c
===================================================================
--- linux-4.10.orig/kernel/printk/braille.c
+++ linux-4.10/kernel/printk/braille.c
@@ -2,12 +2,13 @@

#include <linux/kernel.h>
#include <linux/console.h>
+#include <linux/errno.h>
#include <linux/string.h>

#include "console_cmdline.h"
#include "braille.h"

-char *_braille_console_setup(char **str, char **brl_options)
+int _braille_console_setup(char **str, char **brl_options)
{
if (!strncmp(*str, "brl,", 4)) {
*brl_options = "";
@@ -15,14 +16,15 @@ char *_braille_console_setup(char **str,
} else if (!strncmp(*str, "brl=", 4)) {
*brl_options = *str + 4;
*str = strchr(*brl_options, ',');
- if (!*str)
+ if (!*str) {
pr_err("need port name after brl=\n");
+ return -EINVAL;
+ }
else
*((*str)++) = 0;
- } else
- return NULL;
+ }

- return *str;
+ return 0;
}

int
Index: linux-4.10/kernel/printk/braille.h
===================================================================
--- linux-4.10.orig/kernel/printk/braille.h
+++ linux-4.10/kernel/printk/braille.h
@@ -9,7 +9,14 @@ braille_set_options(struct console_cmdli
c->brl_options = brl_options;
}

-char *
+/*
+ * Setup console according to braille options.
+ * Return -EINVAL on syntax error, 0 on success (or no braille option was
+ * actually given).
+ * Modifies str to point to the serial options
+ * Sets brl_options to the parsed braille options.
+ */
+int
_braille_console_setup(char **str, char **brl_options);

int
@@ -25,10 +32,10 @@ braille_set_options(struct console_cmdli
{
}

-static inline char *
+static inline int
_braille_console_setup(char **str, char **brl_options)
{
- return NULL;
+ return 0;
}

static inline int


2017-03-19 15:44:30

by Aleksey Makarov

[permalink] [raw]
Subject: Re: [PATCH] braille-console: Fix value returned by _braille_console_setup



On 03/19/2017 05:37 PM, Samuel Thibault wrote:
> commit bbeddf52adc1 ("printk: move braille console support into
> separate braille.[ch] files") introduced _braille_console_setup()
> to outline the braille initialization code. There was however some
> confusion over the value it was supposed to return. commit 2cfe6c4ac7ee
> ("printk: Fix return of braille_register_console()") tried to fix it
> but failed to.
>
> This fixes and documents the returned value according to the use
> in printk.c: non-zero return means a parsing error, and thus this
> console configuration should be ignored.

Did you test the code on real braille hardware?
I am asking because there could also be other problems with the code
that have not been run for 3 years since it was changed.

Thank you
Aleksey Makarov

> Signed-off-by: Samuel Thibault <[email protected]>
> Cc: Aleksey Makarov <[email protected]>
> Cc: Joe Perches <[email protected]>
> Cc: Ming Lei <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: Petr Mladek <[email protected]>
>
> Index: linux-4.10/kernel/printk/braille.c
> ===================================================================
> --- linux-4.10.orig/kernel/printk/braille.c
> +++ linux-4.10/kernel/printk/braille.c
> @@ -2,12 +2,13 @@
>
> #include <linux/kernel.h>
> #include <linux/console.h>
> +#include <linux/errno.h>
> #include <linux/string.h>
>
> #include "console_cmdline.h"
> #include "braille.h"
>
> -char *_braille_console_setup(char **str, char **brl_options)
> +int _braille_console_setup(char **str, char **brl_options)
> {
> if (!strncmp(*str, "brl,", 4)) {
> *brl_options = "";
> @@ -15,14 +16,15 @@ char *_braille_console_setup(char **str,
> } else if (!strncmp(*str, "brl=", 4)) {
> *brl_options = *str + 4;
> *str = strchr(*brl_options, ',');
> - if (!*str)
> + if (!*str) {
> pr_err("need port name after brl=\n");
> + return -EINVAL;
> + }
> else
> *((*str)++) = 0;
> - } else
> - return NULL;
> + }
>
> - return *str;
> + return 0;
> }
>
> int
> Index: linux-4.10/kernel/printk/braille.h
> ===================================================================
> --- linux-4.10.orig/kernel/printk/braille.h
> +++ linux-4.10/kernel/printk/braille.h
> @@ -9,7 +9,14 @@ braille_set_options(struct console_cmdli
> c->brl_options = brl_options;
> }
>
> -char *
> +/*
> + * Setup console according to braille options.
> + * Return -EINVAL on syntax error, 0 on success (or no braille option was
> + * actually given).
> + * Modifies str to point to the serial options
> + * Sets brl_options to the parsed braille options.
> + */
> +int
> _braille_console_setup(char **str, char **brl_options);
>
> int
> @@ -25,10 +32,10 @@ braille_set_options(struct console_cmdli
> {
> }
>
> -static inline char *
> +static inline int
> _braille_console_setup(char **str, char **brl_options)
> {
> - return NULL;
> + return 0;
> }
>
> static inline int
>

2017-03-19 15:50:55

by Samuel Thibault

[permalink] [raw]
Subject: Re: [PATCH] braille-console: Fix value returned by _braille_console_setup

Aleksey Makarov, on dim. 19 mars 2017 18:44:23 +0300, wrote:
> On 03/19/2017 05:37 PM, Samuel Thibault wrote:
> > commit bbeddf52adc1 ("printk: move braille console support into
> > separate braille.[ch] files") introduced _braille_console_setup()
> > to outline the braille initialization code. There was however some
> > confusion over the value it was supposed to return. commit 2cfe6c4ac7ee
> > ("printk: Fix return of braille_register_console()") tried to fix it
> > but failed to.
> >
> > This fixes and documents the returned value according to the use
> > in printk.c: non-zero return means a parsing error, and thus this
> > console configuration should be ignored.
>
> Did you test the code on real braille hardware?

Not on actual hardware, but I checked that the output on the serial port
is what is expected.

> I am asking because there could also be other problems with the code
> that have not been run for 3 years since it was changed.

The code which actually implements the braille protocol has not changed
since it was tested.

Samuel

2017-03-24 16:41:50

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH] braille-console: Fix value returned by _braille_console_setup

On Sun 2017-03-19 15:37:26, Samuel Thibault wrote:
> commit bbeddf52adc1 ("printk: move braille console support into
> separate braille.[ch] files") introduced _braille_console_setup()
> to outline the braille initialization code. There was however some
> confusion over the value it was supposed to return. commit 2cfe6c4ac7ee
> ("printk: Fix return of braille_register_console()") tried to fix it
> but failed to.
>
> This fixes and documents the returned value according to the use
> in printk.c: non-zero return means a parsing error, and thus this
> console configuration should be ignored.
>
> Signed-off-by: Samuel Thibault <[email protected]>
> Cc: Aleksey Makarov <[email protected]>
> Cc: Joe Perches <[email protected]>
> Cc: Ming Lei <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: Petr Mladek <[email protected]>
>
> Index: linux-4.10/kernel/printk/braille.c
> ===================================================================
> --- linux-4.10.orig/kernel/printk/braille.c
> +++ linux-4.10/kernel/printk/braille.c
> @@ -2,12 +2,13 @@
>
> #include <linux/kernel.h>
> #include <linux/console.h>
> +#include <linux/errno.h>
> #include <linux/string.h>
>
> #include "console_cmdline.h"
> #include "braille.h"
>
> -char *_braille_console_setup(char **str, char **brl_options)
> +int _braille_console_setup(char **str, char **brl_options)
> {
> if (!strncmp(*str, "brl,", 4)) {
> *brl_options = "";
> @@ -15,14 +16,15 @@ char *_braille_console_setup(char **str,
> } else if (!strncmp(*str, "brl=", 4)) {
> *brl_options = *str + 4;
> *str = strchr(*brl_options, ',');
> - if (!*str)
> + if (!*str) {
> pr_err("need port name after brl=\n");
> + return -EINVAL;
> + }
> else

This "else" has become superfluous because there is return now.

> *((*str)++) = 0;
> - } else
> - return NULL;
> + }
>
> - return *str;
> + return 0;
> }

Otherwise, the patch looks fine to me. With it, the logic is
exactly the same as before the commit bbeddf52adc1b4207674ab
("printk: move braille console support into separate braille.[ch]
files") that broke it.

With the superfluous "else" removed:

Acked-by: Petr Mladek <[email protected]>

Best Regards,
Petr