From patchwork Thu Mar 9 08:20:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 661534 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 ED8E0C61DA4 for ; Thu, 9 Mar 2023 08:23:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229963AbjCIIXa (ORCPT ); Thu, 9 Mar 2023 03:23:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjCIIWt (ORCPT ); Thu, 9 Mar 2023 03:22:49 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE1BB61B1; Thu, 9 Mar 2023 00:21:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678350116; x=1709886116; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1gjDjb6XOju7BxrPkMiH9NjVH6xJrxEdgnWQjbfCD6k=; b=FDvlVHOVmQJZoiuG5w1pDjIvU06vFYMzPabMqLrf3BSYub87zBfFvdBA M4xG2CyxIiUeMvyRksF1gD6sJ6sqfob5wRS5FoEJLeyVdUujkt9n0vqyX RuMMv/0fYLUF+EyM7sn5IqRHOvpfGmZ1ICZrMCW9j0I+1xr/Yu+o6welj v0ePHbaeu9Fyt55RpDXW2LURtqac0WcvRh/Z7CErBb2hE0+7so5l8OOlJ W7qF8rUVe8LY6v3ZpFrBkdQZeG0lyi8EXWJQjJPwvFq1bwaT+/3HzfFrh /asDIoo6ryJF1ZPJavLkayhoBSqNvOZgV2aK4J3NhPF3lMawNhp2QSV3a Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="364025940" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="364025940" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2023 00:21:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10643"; a="787473884" X-IronPort-AV: E=Sophos;i="5.98,245,1673942400"; d="scan'208";a="787473884" Received: from unknown (HELO ijarvine-MOBL2.mshome.net) ([10.237.66.35]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2023 00:21:07 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-serial@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 5/8] n_tty: Use DIV_ROUND_UP() in room calculation Date: Thu, 9 Mar 2023 10:20:32 +0200 Message-Id: <20230309082035.14880-6-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230309082035.14880-1-ilpo.jarvinen@linux.intel.com> References: <20230309082035.14880-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org When PARMRK is set, a character can result in up to 3 chars in the read buffer. Receive code calculates for how many characters there (at least) is room. Convert an opencoded rounding in the calculation to use DIV_ROUND_UP(). Note: the room variable is decremented afterwards by one which ensures the characters will fit into the buffer for real so the code is okay despite rounding upwards. Signed-off-by: Ilpo Järvinen --- drivers/tty/n_tty.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 2cf263de1366..6d754fc35dce 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1692,7 +1693,7 @@ n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp, room = N_TTY_BUF_SIZE - (ldata->read_head - tail); if (I_PARMRK(tty)) - room = (room + 2) / 3; + room = DIV_ROUND_UP(room, 3); room--; if (room <= 0) { overflow = ldata->icanon && ldata->canon_head == tail;