Skip to contentSkip to conversation

-Wsometimes-uninitialized Clang warning in drivers/tty/serial/qcom_geni_serial.c

PATCH In review Nathan Chancellor 4 participants 6 messages Mar 8, 2019 – Mar 22, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi all,

We are trying to get Clang's -Wsometimes-uninitialized turned on for the kernel as it can catch some bugs that GCC can't. This warning came up:

drivers/tty/serial/qcom_geni_serial.c:1079:6: warning: variable 'baud' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

        if (options)
            ^~~~~~~
drivers/tty/serial/qcom_geni_serial.c:1082:37: note: uninitialized use occurs here
        return uart_set_options(uport, co, baud, parity, bits, flow);
                                           ^~~~
drivers/tty/serial/qcom_geni_serial.c:1079:2: note: remove the 'if' if its condition is always true
        if (options)
        ^~~~~~~~~~~~
drivers/tty/serial/qcom_geni_serial.c:1053:10: note: initialize the variable 'baud' to silence this warning
        int baud;
                ^
                 = 0

1 warning generated.

While this is probably not an issue in practice (I assume baud is always supplied as an option), we should clean up this warning. I would fix it myself but I have no idea what baud's initial value should be as it seems it is dependent on the driver. Your input would be much appreciated.

Cheers,
Nathan

#1 lore raw
Quoted 18 lines · Nathan Chancellor

Hi all,

We are trying to get Clang's -Wsometimes-uninitialized turned on for the kernel as it can catch some bugs that GCC can't. This warning came up:

drivers/tty/serial/qcom_geni_serial.c:1079:6: warning: variable 'baud' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

        if (options)
            ^~~~~~~
drivers/tty/serial/qcom_geni_serial.c:1082:37: note: uninitialized use occurs here
        return uart_set_options(uport, co, baud, parity, bits, flow);
                                           ^~~~
drivers/tty/serial/qcom_geni_serial.c:1079:2: note: remove the 'if' if its condition is always true
        if (options)
        ^~~~~~~~~~~~
drivers/tty/serial/qcom_geni_serial.c:1053:10: note: initialize the variable 'baud' to silence this warning
        int baud;
                ^
                 = 0
Quoted 7 lines

1 warning generated.

While this is probably not an issue in practice (I assume baud is always supplied as an option), we should clean up this warning. I would fix it myself but I have no idea what baud's initial value should be as it seems it is dependent on the driver. Your input would be much appreciated.

this function can be called with the option variable set to NULL, so there could not be a default baud rate set, nice catch.

As for the default, let's just be sane and set it to 9600 as that's a normal default baudrate.

Do you want to make up a patch for this, or do you need me to?

thanks,

greg k-h

#2 lore raw

PATCH 1/1 tty: serial: qcom_geni_serial: Initialize baud in qcom_geni_console_setup

When building with -Wsometimes-uninitialized, Clang warns:

drivers/tty/serial/qcom_geni_serial.c:1079:6: warning: variable 'baud' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

It's not wrong; when options is NULL, baud has no default value. Use 9600 as that is a sane default.

---
 drivers/tty/serial/qcom_geni_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/qcom_geni_serial.c +1 -1
index 3bcec1c20219..35e5f9c5d5be 100644
@@ -1050,7 +1050,7 @@ static int __init qcom_geni_console_setup(struct console *co, char *options)
 {
 	struct uart_port *uport;
 	struct qcom_geni_serial_port *port;
-	int baud;
+	int baud = 9600;
 	int bits = 8;
 	int parity = 'n';
 	int flow = 'n';
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#3 lore raw

Re: [PATCH] tty: serial: qcom_geni_serial: Initialize baud in qcom_geni_console_setup

Quoted 7 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/tty/serial/qcom_geni_serial.c:1079:6: warning: variable 'baud' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

Quoted 6 lines

It's not wrong; when options is NULL, baud has no default value. Use 9600 as that is a sane default.

Great find. Thanks for the fix, and thanks Greg for the advice and additional analysis here.

Quoted 20 lines
---
 drivers/tty/serial/qcom_geni_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/qcom_geni_serial.c +1 -2
index 3bcec1c20219..35e5f9c5d5be 100644
@@ -1050,7 +1050,7 @@ static int __init qcom_geni_console_setup(struct console *co, char *options)
 {
        struct uart_port *uport;
        struct qcom_geni_serial_port *port;
-       int baud;
+       int baud = 9600;
        int bits = 8;
        int parity = 'n';
        int flow = 'n';
--

2.21.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw

Re: [PATCH] tty: serial: qcom_geni_serial: Initialize baud in qcom_geni_console_setup

In reply to Nathan Chancellor
Quoted 22 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/tty/serial/qcom_geni_serial.c:1079:6: warning: variable 'baud' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

It's not wrong; when options is NULL, baud has no default value. Use 9600 as that is a sane default.

---
 drivers/tty/serial/qcom_geni_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/qcom_geni_serial.c +0 -0
index 3bcec1c20219..35e5f9c5d5be 100644

drivers/tty/serial/qcom_geni_serial.c static int __init qcom_geni_console_setup(struct console *co, char *options) · line 1056

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c +1 -1
@@ -1050,7 +1050,7 @@ static int __init qcom_geni_console_setup(struct console *co, char *options)
 {
        struct uart_port *uport;
        struct qcom_geni_serial_port *port;
-       int baud;
+       int baud = 9600;
        int bits = 8;
        int parity = 'n';
        int flow = 'n';

I made a similar patch here, but after looking at the driver concluded that the bitrate had to be 115200, since that is used as the default value otherwise.

Arnd

#5 lore raw

Re: [PATCH] tty: serial: qcom_geni_serial: Initialize baud in qcom_geni_console_setup

Quoted 29 lines · Arnd Bergmann
Quoted 26 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/tty/serial/qcom_geni_serial.c:1079:6: warning: variable 'baud' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

It's not wrong; when options is NULL, baud has no default value. Use 9600 as that is a sane default.

---
 drivers/tty/serial/qcom_geni_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/qcom_geni_serial.c +0 -1
index 3bcec1c20219..35e5f9c5d5be 100644
@@ -1050,7 +1050,7 @@ static int __init qcom_geni_console_setup(struct console *co, char *options)
 {
        struct uart_port *uport;
        struct qcom_geni_serial_port *port;
-       int baud;
Quoted 8 lines

drivers/tty/serial/qcom_geni_serial.c static int __init qcom_geni_console_setup(struct console *co, char *options) · line 1056

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c +1 -0
+       int baud = 9600;
        int bits = 8;
        int parity = 'n';
        int flow = 'n';

I made a similar patch here, but after looking at the driver concluded that the bitrate had to be 115200, since that is used as the default value otherwise.

Good point, we use this driver for Pixel, and I usually connect with a baud rate of 115200.

Signature · 2 lines
Thanks,
~Nick Desaulniers