diff mbox series

[v2,2/7] USB: serial: ftdi_sio: Add missing baud rate validation

Message ID 20220712115306.26471-3-kabel@kernel.org
State New
Headers show
Series ftdi_sio driver improvements | expand

Commit Message

Marek Behún July 12, 2022, 11:53 a.m. UTC
From: Pali Rohár <pali@kernel.org>

Add lower checks for requested baud rate for FT8U232AM, FT232BM, FT2232C,
FT232RL, FTX, FT2232H, FT4232H and FT232H. For all of these the minimum
baud rate they can generate is 183 Baud.

Signed-off-by: Pali Rohár <pali@kernel.org>
Tested-by: Marek Behún <kabel@kernel.org>
Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/usb/serial/ftdi_sio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Marek Behún July 12, 2022, 10:24 p.m. UTC | #1
On Tue, 12 Jul 2022 18:27:28 +0100
Rob Pearce <rob@flitspace.org.uk> wrote:

> On 12/07/2022 12:53, Marek Behún wrote:
> > From: Pali Rohár <pali@kernel.org>
> >
> > Add lower checks for requested baud rate for FT8U232AM, FT232BM, FT2232C,
> > FT232RL, FTX, FT2232H, FT4232H and FT232H. For all of these the minimum
> > baud rate they can generate is 183 Baud.
> >
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > Tested-by: Marek Behún <kabel@kernel.org>
> > Signed-off-by: Marek Behún <kabel@kernel.org>
> > ---
> >   drivers/usb/serial/ftdi_sio.c | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
> > index ea40f367e70c..717b97f4e094 100644
> > --- a/drivers/usb/serial/ftdi_sio.c
> > +++ b/drivers/usb/serial/ftdi_sio.c
> > @@ -1330,7 +1330,7 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
> >   		}
> >   		break;
> >   	case FT8U232AM: /* 8U232AM chip */
> > -		if (baud <= 3000000) {
> > +		if (baud >= 183 && baud <= 3000000) {
> >   			div_value = ftdi_232am_baud_to_divisor(baud);
> >   		} else {
> >   			dev_dbg(dev, "%s - Baud rate too high!\n", __func__);  
> Due to the above change, this debug message is now incorrect.

Thx for noticing that. I will update. Also I will probably do some more
refactors, I am not yet sure.

Marek

> > @@ -1343,7 +1343,7 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
> >   	case FT2232C: /* FT2232C chip */
> >   	case FT232RL: /* FT232RL chip */
> >   	case FTX:     /* FT-X series */
> > -		if (baud <= 3000000) {
> > +		if (baud >= 183 && baud <= 3000000) {
> >   			u16 product_id = le16_to_cpu(
> >   				port->serial->dev->descriptor.idProduct);
> >   			if (((product_id == FTDI_NDI_HUC_PID)		||
> > @@ -1367,7 +1367,7 @@ static u32 get_ftdi_divisor(struct tty_struct *tty,
> >   	case FT232H:  /* FT232H chip */
> >   		if ((baud <= 12000000) && (baud >= 1200)) {
> >   			div_value = ftdi_2232h_baud_to_divisor(baud);
> > -		} else if (baud < 1200) {
> > +		} else if (baud >= 183 && baud < 1200) {
> >   			div_value = ftdi_232bm_baud_to_divisor(baud);
> >   		} else {
> >   			dev_dbg(dev, "%s - Baud rate too high!\n", __func__);  
> As above
> 
>
diff mbox series

Patch

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index ea40f367e70c..717b97f4e094 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1330,7 +1330,7 @@  static u32 get_ftdi_divisor(struct tty_struct *tty,
 		}
 		break;
 	case FT8U232AM: /* 8U232AM chip */
-		if (baud <= 3000000) {
+		if (baud >= 183 && baud <= 3000000) {
 			div_value = ftdi_232am_baud_to_divisor(baud);
 		} else {
 			dev_dbg(dev, "%s - Baud rate too high!\n", __func__);
@@ -1343,7 +1343,7 @@  static u32 get_ftdi_divisor(struct tty_struct *tty,
 	case FT2232C: /* FT2232C chip */
 	case FT232RL: /* FT232RL chip */
 	case FTX:     /* FT-X series */
-		if (baud <= 3000000) {
+		if (baud >= 183 && baud <= 3000000) {
 			u16 product_id = le16_to_cpu(
 				port->serial->dev->descriptor.idProduct);
 			if (((product_id == FTDI_NDI_HUC_PID)		||
@@ -1367,7 +1367,7 @@  static u32 get_ftdi_divisor(struct tty_struct *tty,
 	case FT232H:  /* FT232H chip */
 		if ((baud <= 12000000) && (baud >= 1200)) {
 			div_value = ftdi_2232h_baud_to_divisor(baud);
-		} else if (baud < 1200) {
+		} else if (baud >= 183 && baud < 1200) {
 			div_value = ftdi_232bm_baud_to_divisor(baud);
 		} else {
 			dev_dbg(dev, "%s - Baud rate too high!\n", __func__);