From: Purva Yeshi <purvayeshi550@gmail.com>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org
Cc: andriy.shevchenko@linux.intel.com, arnd@kernel.org,
cang1@live.co.uk, bhelgaas@google.com,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
Purva Yeshi <purvayeshi550@gmail.com>
Subject: [PATCH] tty: serial: 8250: Fix uninitialized variable warnings in pci_oxsemi_tornado_get_divisor
Date: Fri, 11 Apr 2025 17:20:48 +0530 [thread overview]
Message-ID: <20250411115048.34948-1-purvayeshi550@gmail.com> (raw)
Fix Smatch-detected issue:
drivers/tty/serial/8250/8250_pci.c:1233 pci_oxsemi_tornado_get_divisor()
error: uninitialized symbol 'tcr'.
drivers/tty/serial/8250/8250_pci.c:1234 pci_oxsemi_tornado_get_divisor()
error: uninitialized symbol 'quot'.
drivers/tty/serial/8250/8250_pci.c:1238 pci_oxsemi_tornado_get_divisor()
error: uninitialized symbol 'quot'.
drivers/tty/serial/8250/8250_pci.c:1242 pci_oxsemi_tornado_get_divisor()
error: uninitialized symbol 'cpr'.
drivers/tty/serial/8250/8250_pci.c:1252 pci_oxsemi_tornado_get_divisor()
error: uninitialized symbol 'cpr'.
Fix uninitialized variable usage in pci_oxsemi_tornado_get_divisor() that
was triggering sparse warnings and potential undefined behavior. The
variables tcr, cpr, and quot were used before being explicitly assigned
values, leading to smatch warning in multiple lines of the function.
Initialize quot to 1, tcr to 16, and cpr to OXSEMI_TORNADO_CPR_DEF at the
point of declaration. This ensures safe fallback values are used when these
variables are not conditionally set later in the function, avoiding
uninitialized access.
Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
drivers/tty/serial/8250/8250_pci.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 73c200127b08..ba4dedccc29e 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1187,9 +1187,9 @@ static unsigned int pci_oxsemi_tornado_get_divisor(struct uart_port *port,
unsigned int sdiv = DIV_ROUND_CLOSEST(sclk, baud);
unsigned int best_squot;
unsigned int squot;
- unsigned int quot;
- u16 cpr;
- u8 tcr;
+ unsigned int quot = 1;
+ u16 cpr = OXSEMI_TORNADO_CPR_DEF; /* Default Control Prescaler Register */
+ u8 tcr = 16; /* Typical default value for the Timer Control Register */
int i;
/* Old custom speed handling. */
--
2.34.1
next reply other threads:[~2025-04-11 11:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 11:50 Purva Yeshi [this message]
2025-04-11 12:29 ` [PATCH] tty: serial: 8250: Fix uninitialized variable warnings in pci_oxsemi_tornado_get_divisor Greg KH
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=20250411115048.34948-1-purvayeshi550@gmail.com \
--to=purvayeshi550@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@kernel.org \
--cc=bhelgaas@google.com \
--cc=cang1@live.co.uk \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@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