From patchwork Tue Jul 12 11:53:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 590288 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59F6EC43334 for ; Tue, 12 Jul 2022 11:54:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232732AbiGLLy3 (ORCPT ); Tue, 12 Jul 2022 07:54:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232756AbiGLLyP (ORCPT ); Tue, 12 Jul 2022 07:54:15 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C984B5D37 for ; Tue, 12 Jul 2022 04:53:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 7C31CCE1A9B for ; Tue, 12 Jul 2022 11:53:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7844CC341CB; Tue, 12 Jul 2022 11:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657626794; bh=lSNgtyL8u/58a3asNaRqnCpMiCYfkWiKLPR4264utCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uk1WQ3MjF51mLZ/E7rijqppVD7ZjqaYEP373WTNxaaKvOkbgvLhp5SyZvhX5Oue7b TaLia35D7IXW+NI2oGCjJLQ8pKOK2OC/i9Z+u+U7E5JPE/p+5IZuBWfiqYjqo+90td 1uzHdK1jRJ7N6K9VJ9CBoWXfIKVjxR4lweuqsBQes12NlMZJ5HJRtiQ8Mt3NnJfm8V 6hpbwkm1W0/ro0d285+gw2r7VPZUuPbt0lBgLt8brdtln/T0/KByxL4ytI+y4IIIXo MqQ0HAALMuiT0/wz7CCUUFvM/KU3D+32TH2NKPcuRIukG6tt+C+ZY96Oj+sDqyASL2 F0e1CmvF3WUmg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: linux-usb@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Johan Hovold , Greg Kroah-Hartman , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v2 2/7] USB: serial: ftdi_sio: Add missing baud rate validation Date: Tue, 12 Jul 2022 13:53:01 +0200 Message-Id: <20220712115306.26471-3-kabel@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220712115306.26471-1-kabel@kernel.org> References: <20220712115306.26471-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Pali Rohár 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 Tested-by: Marek Behún Signed-off-by: Marek Behún --- 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__); @@ -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__);