public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_pci: Fix uninitialized variable use in pci_oxsemi_tornado_get_divisor
@ 2026-01-21 15:53 Lee Yongjun
  2026-01-21 16:36 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Lee Yongjun @ 2026-01-21 15:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-serial, linux-kernel, Andy Shevchenko, Lee Yongjun

Smatch reports the following errors:

  drivers/tty/serial/8250/8250_pci.c:1246 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'tcr'.
  drivers/tty/serial/8250/8250_pci.c:1247 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'quot'.
  drivers/tty/serial/8250/8250_pci.c:1251 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'quot'.
  drivers/tty/serial/8250/8250_pci.c:1255 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'cpr'.
  drivers/tty/serial/8250/8250_pci.c:1265 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'cpr'.

These variables are initialized in the if branch or inside the loop in
the else branch. However, if the loop finishes without finding a suitable
divisor, they remain uninitialized.

Initialize 'quot', 'cpr', and 'tcr' to 0 to prevent undefined behavior.

Signed-off-by: Lee Yongjun <jun85566@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 c5a932f48f74..b32d7e03c29a 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1200,9 +1200,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 = 0;
+	u16 cpr = 0;
+	u8 tcr = 0;
 	int i;
 
 	/* Old custom speed handling.  */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: 8250_pci: Fix uninitialized variable use in pci_oxsemi_tornado_get_divisor
  2026-01-21 15:53 [PATCH] serial: 8250_pci: Fix uninitialized variable use in pci_oxsemi_tornado_get_divisor Lee Yongjun
@ 2026-01-21 16:36 ` Greg Kroah-Hartman
  2026-01-22  0:18   ` Lee Yongjun
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-01-21 16:36 UTC (permalink / raw)
  To: Lee Yongjun; +Cc: Jiri Slaby, linux-serial, linux-kernel, Andy Shevchenko

On Thu, Jan 22, 2026 at 12:53:52AM +0900, Lee Yongjun wrote:
> Smatch reports the following errors:
> 
>   drivers/tty/serial/8250/8250_pci.c:1246 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'tcr'.
>   drivers/tty/serial/8250/8250_pci.c:1247 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'quot'.
>   drivers/tty/serial/8250/8250_pci.c:1251 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'quot'.
>   drivers/tty/serial/8250/8250_pci.c:1255 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'cpr'.
>   drivers/tty/serial/8250/8250_pci.c:1265 pci_oxsemi_tornado_get_divisor() error: uninitialized symbol 'cpr'.
> 
> These variables are initialized in the if branch or inside the loop in
> the else branch. However, if the loop finishes without finding a suitable
> divisor, they remain uninitialized.

But can that ever really happen?  Please step through it all with the
values that the hardware provides to see this.

> Initialize 'quot', 'cpr', and 'tcr' to 0 to prevent undefined behavior.

Why haven't we seen any real problems with this?  I think this is ok
as-is.  Maybe a little bit complex and non-intutive, but ok.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: 8250_pci: Fix uninitialized variable use in pci_oxsemi_tornado_get_divisor
  2026-01-21 16:36 ` Greg Kroah-Hartman
@ 2026-01-22  0:18   ` Lee Yongjun
  0 siblings, 0 replies; 3+ messages in thread
From: Lee Yongjun @ 2026-01-22  0:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Jiri Slaby, linux-serial, linux-kernel, Andy Shevchenko

Hi Greg,

Thanks for the clarification.

I agree that this case cannot occur in practice and the current code is
fine as-is. I will drop this patch.

Thanks,

Lee Yongjun

Hi Greg,

Thanks for the clarification.

I agree that this case cannot occur in practice and the current code is
fine as-is. I will drop this patch.

Thanks,

Lee Yongjun

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-22  0:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-21 15:53 [PATCH] serial: 8250_pci: Fix uninitialized variable use in pci_oxsemi_tornado_get_divisor Lee Yongjun
2026-01-21 16:36 ` Greg Kroah-Hartman
2026-01-22  0:18   ` Lee Yongjun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox