From patchwork Thu Aug 10 09:15:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 712537 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 06BC2C001B0 for ; Thu, 10 Aug 2023 09:19:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234718AbjHJJTF (ORCPT ); Thu, 10 Aug 2023 05:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234783AbjHJJSW (ORCPT ); Thu, 10 Aug 2023 05:18:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1F2F47EA; Thu, 10 Aug 2023 02:16:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1F9BD654DA; Thu, 10 Aug 2023 09:16:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1808C433C9; Thu, 10 Aug 2023 09:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691658999; bh=7m3JsfPMLiKgFfQV74GNsNXjJ2VCRfWCFVK3pJRiZ3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DG6xWzEwT7xF96/U2407avRLJMGIPoz80XMbZrmyx+9d5u3h3o8q4hXBs0ypGm2hn 79QEOuzO7vfVgAPlK3/AcLRrjafrRCGnzXgZdw+YnRzG2leCYCwX+KbRCEZRO2xNiC Wr911rl2+YUbqX7LNo5CzdJ0aV4fZiY+jZmTtugVhTV6l8FBoB0uTk7nE0TdGYcM8i zH0pz5WbQ0F+NLwWGYMFrDJDixTxGl1FI3yg15sjv5ye2HF8Sy2I196fgYylcM2IIY x7Z8RqPaRj7awBQZ3UjS7xxdKvxheIOPP3u9n1mO3SNe38RQBhI0jmWwBwSB1mFMfe wEduW9x+IblfA== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH 35/36] tty: hso: simplify hso_serial_write() Date: Thu, 10 Aug 2023 11:15:09 +0200 Message-ID: <20230810091510.13006-36-jirislaby@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230810091510.13006-1-jirislaby@kernel.org> References: <20230810091510.13006-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org There is no need for two more variables in hso_serial_write(). Switch to min_t() and eliminate those. Furthermore, the 'if-goto' is superfluous as memcpy() of zero count is a nop. So is addition of zero. So remove the 'if-goto' completely. Signed-off-by: Jiri Slaby (SUSE) Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni --- drivers/net/usb/hso.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index 3f424da87bf4..83b8452220ec 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -1326,7 +1326,6 @@ static ssize_t hso_serial_write(struct tty_struct *tty, const u8 *buf, size_t count) { struct hso_serial *serial = tty->driver_data; - int space, tx_bytes; unsigned long flags; /* sanity check */ @@ -1337,21 +1336,16 @@ static ssize_t hso_serial_write(struct tty_struct *tty, const u8 *buf, spin_lock_irqsave(&serial->serial_lock, flags); - space = serial->tx_data_length - serial->tx_buffer_count; - tx_bytes = (count < space) ? count : space; + count = min_t(size_t, serial->tx_data_length - serial->tx_buffer_count, + count); + memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, count); + serial->tx_buffer_count += count; - if (!tx_bytes) - goto out; - - memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, tx_bytes); - serial->tx_buffer_count += tx_bytes; - -out: spin_unlock_irqrestore(&serial->serial_lock, flags); hso_kick_transmit(serial); /* done */ - return tx_bytes; + return count; } /* how much room is there for writing */