forked from Imagelibrary/rtems
libchip/serial/ns16550* and z8530*: Assert on baud number to avoid divide by 0
This was flagged by CodeSonar. It should be impossible to get an incorrect baud number back but ensure this in debug mode. The _Assert() keeps their scanner from evaluating for divide by 0 past this point.
This commit is contained in:
committed by
Joel Sherrill
parent
0ad1e8001f
commit
02958c5e53
@@ -592,9 +592,13 @@ static bool ns16550_set_attributes(
|
||||
|
||||
/*
|
||||
* Calculate the baud rate divisor
|
||||
*
|
||||
* Assert ensures there is no division by 0.
|
||||
*/
|
||||
|
||||
baud_requested = rtems_termios_baud_to_number(t->c_cflag);
|
||||
_Assert( baud_requested != 0 );
|
||||
|
||||
ulBaudDivisor = NS16550_GetBaudDivisor(ctx, baud_requested);
|
||||
|
||||
ucLineControl = 0;
|
||||
|
||||
@@ -532,9 +532,12 @@ int ns16550_set_attributes(
|
||||
|
||||
/*
|
||||
* Calculate the baud rate divisor
|
||||
*
|
||||
* Assert ensures there is no division by 0.
|
||||
*/
|
||||
|
||||
baud_requested = rtems_termios_baud_to_number(t->c_cflag);
|
||||
_Assert( baud_requested != 0 );
|
||||
ulBaudDivisor = NS16550_GetBaudDivisor(c, baud_requested);
|
||||
|
||||
ucLineControl = 0;
|
||||
|
||||
@@ -437,6 +437,7 @@ Z85C30_STATIC int z85c30_set_attributes(
|
||||
uint32_t wr4;
|
||||
uint32_t wr5;
|
||||
int baud_requested;
|
||||
uint32_t baud_number;
|
||||
setRegister_f setReg;
|
||||
rtems_interrupt_level Irql;
|
||||
|
||||
@@ -445,15 +446,20 @@ Z85C30_STATIC int z85c30_set_attributes(
|
||||
|
||||
/*
|
||||
* Calculate the baud rate divisor
|
||||
*
|
||||
* Assert ensures there is no division by 0.
|
||||
*/
|
||||
|
||||
baud_requested = t->c_cflag & CBAUD;
|
||||
if (!baud_requested)
|
||||
baud_requested = B9600; /* default to 9600 baud */
|
||||
|
||||
baud_number = (uint32_t) rtems_termios_baud_to_number( baud_requested );
|
||||
_Assert( baud_number != 0 );
|
||||
|
||||
ulBaudDivisor = Z85C30_Baud(
|
||||
(uint32_t) Console_Port_Tbl[minor]->ulClock,
|
||||
(uint32_t) rtems_termios_baud_to_number( baud_requested )
|
||||
baud_number
|
||||
);
|
||||
|
||||
wr3 = SCC_WR3_RX_EN;
|
||||
|
||||
Reference in New Issue
Block a user