From patchwork Tue Jul 12 11:53:04 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: 590287 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 60BE1CCA47C for ; Tue, 12 Jul 2022 11:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbiGLLyc (ORCPT ); Tue, 12 Jul 2022 07:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232753AbiGLLyP (ORCPT ); Tue, 12 Jul 2022 07:54:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7311FB62B1 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 dfw.source.kernel.org (Postfix) with ESMTPS id F28F26156D for ; Tue, 12 Jul 2022 11:53:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38302C341CB; Tue, 12 Jul 2022 11:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657626799; bh=SMWs9lHYCGSSpuMZB3WjxczPj7PPubzF2MJZNYCfYmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BGed5AsgyBZNmBHLqAlKpqpjAsWrdTV+9SaqJ1dW1IvBFIX9XDkLmbg+DjsmenjOC PUbw5fEq9N/rlQkfVgRffhI/aI45eFhVqycL0jDTfLZ3B7OMr/S+7fINY40suC5tbd qq2uBNveOtcOXhE8PaOZLeNAi0JNM8H3+FS0x4xb39bne0BSaJHmEH147Znu1ITm53 0PvjDYbBRvcA8vdrkZopAOMMJVUYi1t99JKrRbgOgTqlUeBlq7p+n7LfRJpAREoc8X 3p5PlCoOR02AH2ICD73RcEYvDzOavSNrSSbfWLZykohBMWNZiUIzolBbQulBL2hSzT dDll4cXLDbvQw== 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 5/7] USB: serial: ftdi_sio: Fix baud rate rounding for ASYNC_SPD_CUST Date: Tue, 12 Jul 2022 13:53:04 +0200 Message-Id: <20220712115306.26471-6-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 To compute more accurate baud rate when user uses ASYNC_SPD_CUST API, use DIV_ROUND_CLOSEST() instead of just rounding down. Rationale: Application uses old API, so it computes divisor D for baud rate B. The driver then tries to compute back the requested baud rate B, but rounds down in the division. Using rounding to closest value instead should increate accuracy here. Signed-off-by: Pali Rohár Tested-by: Marek Behún Signed-off-by: Marek Behún --- drivers/usb/serial/ftdi_sio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index cdbba1a9edd9..5db1293bb7a2 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1317,7 +1317,7 @@ static u32 get_ftdi_divisor(struct tty_struct *tty, if (baud == 38400 && ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && (priv->custom_divisor)) { - baud = priv->baud_base / priv->custom_divisor; + baud = DIV_ROUND_CLOSEST(priv->baud_base, priv->custom_divisor); dev_dbg(dev, "%s - custom divisor %d sets baud rate to %d\n", __func__, priv->custom_divisor, baud); }