From mboxrd@z Thu Jan 1 00:00:00 1970 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 23A09C43334 for ; Sun, 24 Jul 2022 12:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229772AbiGXMCA (ORCPT ); Sun, 24 Jul 2022 08:02:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiGXMB6 (ORCPT ); Sun, 24 Jul 2022 08:01:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5937E13CC5; Sun, 24 Jul 2022 05:01:57 -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 ams.source.kernel.org (Postfix) with ESMTPS id DEDE9B80D41; Sun, 24 Jul 2022 12:01:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63E84C3411E; Sun, 24 Jul 2022 12:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658664114; bh=GMLEQT2pKFD/Pptp979bJ5ZUw4UMKwp3CoxE5H11hEA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YkUdYt0UINez1KTNfwcai06uMt5CK9o2KpPkby3wvrqC2Gv/dNqE0pzG6EfkJhS47 xetJuGba2JULaZwnofEu1SB5EV2bDwBg/CKsgfeUVmN72n7U432e6Ogj5C80kjNloD vBpfuUZ1bQ3BJva9zYExsXbDs6kq6x7svsdnfLHZzeyVWil4hOebLqNR1on9G49V/G uUWyQgcRUzFDmOj0uFtsSUjYLK/gLFwEsgLaG0R0BYXv2JAJUIqhdWTLF1YwThzVMx /Ri2WBCpuf24ZDusklvkoW3DvUBbAj/1eBeSRqKx+yjGAO9J966Xag4eBrBXI1CU3I baesRdrHr6STw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oFaJ7-0006To-VN; Sun, 24 Jul 2022 14:02:02 +0200 Date: Sun, 24 Jul 2022 14:02:01 +0200 From: Johan Hovold To: Marek =?utf-8?B?QmVow7pu?= Cc: linux-usb@vger.kernel.org, Pali =?utf-8?B?Um9ow6Fy?= , Greg Kroah-Hartman , stable@vger.kernel.org Subject: Re: [PATCH v2 1/7] USB: serial: ftdi_sio: Fix divisor overflow Message-ID: References: <20220712115306.26471-1-kabel@kernel.org> <20220712115306.26471-2-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220712115306.26471-2-kabel@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Tue, Jul 12, 2022 at 01:53:00PM +0200, Marek Behún wrote: > From: Pali Rohár > > The baud rate generating divisor is a 17-bit wide (14 bits integer part > and 3 bits fractional part). > > Example: > base clock = 48 MHz > requested baud rate = 180 Baud > divisor = 48,000,000 / (16 * 180) = 0b100000100011010.101 > > In this case the MSB gets discarded because of the overflow, and the > actually used divisor will be 0b100011010.101 = 282.625, resulting > in baud rate 10615 Baud, instead of the requested 180 Baud. > > The best possible thing to do in this case is to generate lowest possible > baud rate (in the example it would be 183 Baud), by using maximum possible > divisor. Actually, the best way to handle this is to add a sanity check for the lowest supported check as you do in the next patch. That one makes this change superfluous. > In case of divisor overflow, use maximum possible divisor. Johan