From patchwork Tue May 3 08:06:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 569251 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 2B7A2C433F5 for ; Tue, 3 May 2022 08:06:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232233AbiECIJs (ORCPT ); Tue, 3 May 2022 04:09:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232619AbiECIJr (ORCPT ); Tue, 3 May 2022 04:09:47 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64A4E20F5A; Tue, 3 May 2022 01:06:15 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 1CFE9210E5; Tue, 3 May 2022 08:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651565174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECu5gs4Na4QCx3MdAZscC5hEAd3uD+930KihhgMqo+g=; b=0t0WBLkRPpnbG5Rz/Q0xOIzDEvzKG6LcU1ZOE/l1sdQVgXdq9v/DmJpdnFNkepgTjiEARx 5ACVvNNwo5QYiItuZMVvSKtSLzhxRGEEwQ3bzXD0/KO7Y2C0SoBQuX3VM5wV50Tyqv+XbI 4wcEXjdg28GfPG51QWjlHxJbGT+/A7Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651565174; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECu5gs4Na4QCx3MdAZscC5hEAd3uD+930KihhgMqo+g=; b=rKX81hd2r72cG0nw9Qh5hiQE9cvWFh2FyS1S/LKNd9V+r0msD1fuOmFfK7hHYRGGABSxz2 B4hWKKeRmGnmcPCg== Received: from localhost.localdomain (unknown [10.100.208.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E67922C143; Tue, 3 May 2022 08:06:13 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 1/7] serial: pch: move size check from pop_tx one level up Date: Tue, 3 May 2022 10:06:07 +0200 Message-Id: <20220503080613.27601-2-jslaby@suse.cz> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220503080613.27601-1-jslaby@suse.cz> References: <20220503080613.27601-1-jslaby@suse.cz> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 'count' is zero in the pop_tx()'s comparison against 'size'. So the 'if' tries to find out if 'size' is negative or zero and returns in that case. But it cannot be negative, due to previous (size < 0) check in the caller: handle_tx(). So simply move this check from pop_tx() to handle_tx(). Now it's clear that pop_tx() is called only if fifo_size is non-zero. Signed-off-by: Jiri Slaby --- drivers/tty/serial/pch_uart.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index affe71f8b50c..f872613a5e83 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -791,7 +791,7 @@ static int pop_tx(struct eg20t_port *priv, int size) struct uart_port *port = &priv->port; struct circ_buf *xmit = &port->state->xmit; - if (uart_tx_stopped(port) || uart_circ_empty(xmit) || count >= size) + if (uart_tx_stopped(port) || uart_circ_empty(xmit)) goto pop_tx_end; do { @@ -895,14 +895,16 @@ static unsigned int handle_tx(struct eg20t_port *priv) tx_empty = 0; fifo_size--; } + size = min(xmit->head - xmit->tail, fifo_size); if (size < 0) size = fifo_size; - - tx_size = pop_tx(priv, size); - if (tx_size > 0) { - port->icount.tx += tx_size; - tx_empty = 0; + if (size) { + tx_size = pop_tx(priv, size); + if (tx_size > 0) { + port->icount.tx += tx_size; + tx_empty = 0; + } } priv->tx_empty = tx_empty;