From: Alex Elder <elder@linaro.org>
To: Arnd Bergmann <arnd@arndb.de>, David Lin <dtwlin@gmail.com>,
Johan Hovold <johan@kernel.org>, Alex Elder <elder@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Axel Haslam <ahaslam@baylibre.com>
Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
greybus-dev@lists.linaro.org,
Greg Kroah-Hartman <gregkh@google.com>,
Johan Hovold <johan@hovoldconsulting.com>
Subject: Re: [greybus-dev] [PATCH] greybus: uart: fix uninitialized flow control variable
Date: Wed, 29 Apr 2020 15:00:44 -0500 [thread overview]
Message-ID: <7146e1ca-1fc7-61ab-e798-7b017c7c974b@linaro.org> (raw)
In-Reply-To: <20200429190022.12671-1-arnd@arndb.de>
On 4/29/20 2:00 PM, Arnd Bergmann wrote:
> gcc-10 points out an uninitialized variable use:
Wow, nice, checking individual uninitialized fields within
the structure.
The structure should really be zero-initialized anyway; it's
passed as a structure in a message elsewhere. With your
change, all fields in the structure are written, but in
theory the structure could change and stack garbage could
be sent over the wire.
What do you think of doing this instead? Or in addition?
struct gb_tty_line_coding newline = { };
(Presumably that would also silence the warning.)
I endorse of your change, either way.
-Alex
> drivers/staging/greybus/uart.c: In function 'gb_tty_set_termios':
> drivers/staging/greybus/uart.c:540:24: error: 'newline.flow_control' is used uninitialized in this function [-Werror=uninitialized]
> 540 | newline.flow_control |= GB_SERIAL_AUTO_RTSCTS_EN;
>
> Instead of using |= and &= on the uninitialized variable, use a
> direct assignment.
>
> Fixes: e55c25206d5c ("greybus: uart: Handle CRTSCTS flag in termios")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/staging/greybus/uart.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
> index 55c51143bb09..4ffb334cd5cd 100644
> --- a/drivers/staging/greybus/uart.c
> +++ b/drivers/staging/greybus/uart.c
> @@ -537,9 +537,9 @@ static void gb_tty_set_termios(struct tty_struct *tty,
> }
>
> if (C_CRTSCTS(tty) && C_BAUD(tty) != B0)
> - newline.flow_control |= GB_SERIAL_AUTO_RTSCTS_EN;
> + newline.flow_control = GB_SERIAL_AUTO_RTSCTS_EN;
> else
> - newline.flow_control &= ~GB_SERIAL_AUTO_RTSCTS_EN;
> + newline.flow_control = 0;
>
> if (memcmp(&gb_tty->line_coding, &newline, sizeof(newline))) {
> memcpy(&gb_tty->line_coding, &newline, sizeof(newline));
>
next prev parent reply other threads:[~2020-04-29 20:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 19:00 Arnd Bergmann
2020-04-29 20:00 ` Alex Elder [this message]
2020-05-14 7:04 ` [greybus-dev] " Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7146e1ca-1fc7-61ab-e798-7b017c7c974b@linaro.org \
--to=elder@linaro.org \
--cc=ahaslam@baylibre.com \
--cc=arnd@arndb.de \
--cc=devel@driverdev.osuosl.org \
--cc=dtwlin@gmail.com \
--cc=elder@kernel.org \
--cc=gregkh@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=johan@hovoldconsulting.com \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®