From patchwork Thu Aug 10 09:14:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 712543 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 03324C04FE1 for ; Thu, 10 Aug 2023 09:17:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234460AbjHJJRQ (ORCPT ); Thu, 10 Aug 2023 05:17:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234698AbjHJJQz (ORCPT ); Thu, 10 Aug 2023 05:16:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC9DA3C2A; Thu, 10 Aug 2023 02:16:08 -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 A9BC5654E7; Thu, 10 Aug 2023 09:16:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0843EC433C9; Thu, 10 Aug 2023 09:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691658968; bh=IB0hueHyK3s8u1ECn26OKi6iqqaceaJXgBWW7btEaaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mHZNMbwj1MnnCeLdtrTf2s66/O+j1ggY1IbheoYNwEcnUUm+JSEeKXMRteP92DE0Z LaY+LvVx3ezt3aEDnMZwQWGdLbS/fCzdqvz9r6Erh4uE+abQgpjNfE98FTjmc+CDYp TMHcQ83ltUAgE//QVPeBJ4G6ADWdVAxb9adOlRYC2ZYp+60oLS5TcVEi+ild20GZbK HGhSwPcKiePICG68ciE3i+YDeF/Deu9BtmccXrUkPQY14+keD1EcXkTtRoBybYzBPt 5Q28/mpbRyCLx+b8Leh2fxsTYc4+og4ipG/cIrKrF02bVdqcnrLrba3KtWZxEtqyrU erEVLq1ebyaXg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 23/36] tty: use min() in iterate_tty_write() Date: Thu, 10 Aug 2023 11:14:57 +0200 Message-ID: <20230810091510.13006-24-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 It simplifies the code. The "price" is we have to unify 'chunk' to be size_t the same as 'count' is. But that change is actually correct. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/tty_io.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 846460c02c58..0cf1277e260b 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -964,9 +964,8 @@ int tty_write_lock(struct tty_struct *tty, bool ndelay) static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, struct file *file, struct iov_iter *from) { - size_t count = iov_iter_count(from); + size_t chunk, count = iov_iter_count(from); ssize_t ret, written = 0; - unsigned int chunk; ret = tty_write_lock(tty, file->f_flags & O_NDELAY); if (ret < 0) @@ -1010,10 +1009,7 @@ static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, /* Do the write .. */ for (;;) { - size_t size = count; - - if (size > chunk) - size = chunk; + size_t size = min(chunk, count); ret = -EFAULT; if (copy_from_iter(tty->write_buf, size, from) != size)