Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp901948rwl; Thu, 10 Aug 2023 03:34:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbShIwLMpKgEeLUeDzgTHGtSx8m5zMcJQBCv559a3yf27tkiuf/Zsr7eF13+ZrcbpX563a X-Received: by 2002:a05:6512:2098:b0:4fc:4f3e:9cbf with SMTP id t24-20020a056512209800b004fc4f3e9cbfmr1284967lfr.50.1691663653812; Thu, 10 Aug 2023 03:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691663653; cv=none; d=google.com; s=arc-20160816; b=QnbDLp95rWajl1NeKyXHFmvCEtbH+UsqmILrrutiO0nrH/sEerfdFODcyhZycKCZU8 ydH5fjkl3apCbbYahyndJhkTwwsEtnV2S52V1TorGptqZLnwE/IOm+zvSZb9uaReFKSg wcW0ADW8u9Cadj4en30lEOJuZLbNWB19cMshzlGb5ga21rJOQi8zWC03P7yyIlrVPSYK JXXJ7S74o7mhgdOm6fBYB12fYlUVJyNA0mT4MR+ad6WPyIoaESS/LKAaMRckkk8+y4bz xHT7cHI/FCwW5IsANEJkgpbUXmRNlY+Cch1eCjmj94XaVLHiMLk8LfHj3mqSiMzqenX+ 4YeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=f2KiOgaws3UETZrdcLtV2ox5M5Vu1lSehzSm5hUFIGE=; fh=k7XzfpyqnKqnwxpqVF0NftrWa2FIpeAcHVbykF5xarA=; b=kYF39nSmPiE6HjrwmYYFj660w2COcy9XgJ7nY57kgRJWejBL4WFs14QBqxyB4aP3Eu SQ+MpRgAqSoc2qftdjqCLFXfpyjy1C7J43oTca8dR6JUjF8Q4k3NMzNwR60fqR9hjPM2 CnXzBkwtTMqsCPkKBxfwk4PANHWEhwsHULW9UtMt3bCuODguocSXxT/qhfL6y4HgAcJm E5LvPB9A61It5+QXfkoss5WDx8nVu99HhSj7zqgm2uSLNp9j/zzrqxImgpKlKN7eF3Q2 GDs/7iQZfi/vbIHnqawdHlN9ReEjrXuPLmlvx62zLLxbxE/E/WJMo06h3aHPc8YV565N 168A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mHZNMbwj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020aa7da96000000b0052322c44db3si1281178eds.678.2023.08.10.03.33.49; Thu, 10 Aug 2023 03:34:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mHZNMbwj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234729AbjHJJRa (ORCPT + 99 others); Thu, 10 Aug 2023 05:17:30 -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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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) -- 2.41.0