Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp865156rwl; Thu, 10 Aug 2023 02:54:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnZcdOIO2VNoP5Y0XDXDKW7GP0BFKDf5m9gcnXzGrvRIKTFFmxx0cui3l+R2wO8w3f1xbh X-Received: by 2002:a05:6512:1283:b0:4f8:70b0:eec6 with SMTP id u3-20020a056512128300b004f870b0eec6mr1703010lfs.28.1691661265915; Thu, 10 Aug 2023 02:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691661265; cv=none; d=google.com; s=arc-20160816; b=MJB9OiXnxk0FLg6RLta4ZEkBxoBz+AwMrhzebYx5fC6y3NBzv6d83a9r7gP/zzN2Ev F6hGW7WmgkgoCSofupBAYdAA655sVVKPU7xLevxOTLceUa5gTD6qQIuC56wRWuC7q7tO 9hMhOhybrJIEz1vRdyYHpNIN21goZ2dhb7pkTJU1rW4jkziCQq5+LRM14hUObAHc2sQP epLBnhl8+CbjXh91KX2JFFgZP3CdWeNEjmoFebmqpN4uQRhrNbEbQxZ4Uwn+IfC/IxWz N8bNgeg+HsGl94rYvJal58QQt1HjmIJP3/rQkbivJEARA3bxYy1g9kxPVlE7YnpWPp3g /2sg== 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=bQFUCuzPb2qvQN6dl+rm+Qb0umAdNjWmg3DsY4Llkrk=; fh=k7XzfpyqnKqnwxpqVF0NftrWa2FIpeAcHVbykF5xarA=; b=Pvk7KRDGF6tvv8iPVUWdi9NHIfyNQlbjneL1npd8lVm2y3YwuK9Ke1PpOhT2J0RcYe mgbIuK71zM8OVmshuXrZRzweu/OUaDgDAUR3/UPocNoyraE+Ws2OGDsKpxc40+NRCZTc aeTnk51bh+kpois02q1CQ9vrVIlU2Q5E5F2vJnSnqGGcb7ozvls0SPgloc6tpIXD7G5u DaDzsLPhSY1YiLfH8QqW0rU9GtL/paDi8Arpa22cAN9JJLv3Pgk/Ia9tfQY9RTkE6Ev7 GKyBrA8MZgJzfHcTc4d6riBjTX3L8nwj0GNiRCoryz3tABGiNWhSzwZtzmhzgapaWNaK V9Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KNFPxPS7; 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 m15-20020a056402050f00b005234684a7e2si1191784edv.119.2023.08.10.02.54.01; Thu, 10 Aug 2023 02:54:25 -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=KNFPxPS7; 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 S233627AbjHJJRh (ORCPT + 99 others); Thu, 10 Aug 2023 05:17:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234851AbjHJJRA (ORCPT ); Thu, 10 Aug 2023 05:17:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B7B24223; Thu, 10 Aug 2023 02:16:13 -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 4E0426550A; Thu, 10 Aug 2023 09:16:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B400C433CA; Thu, 10 Aug 2023 09:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691658972; bh=14gTPQx7XyzDqSWiJUFV6C/aJrHW2+ALhVNcSU3mPbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KNFPxPS7MK3Hchuv55BVxmG7yaaf0nj8sRDWsSSkcD6FEOkMBIfHt1qIlMfYbLGTu nfC50KXzI9blYYWmOAxfucPu4FveHK6Wx3hPG7/gFdSlmbh+pSMlUTHt/R7RoYiTWv G8KxrtKZcL49/fGJACFQYkwEZ2xTyL/AwLv1pZ7hhqojM4WWu/3dQlkI1kbidh+GgX MEEjRHCL1Tj7NlxdOS9wvgtH2On+Bvr+HJwHMaKEKrusamCSUSrDeZ6cQ3pjW6xLBR gRFkOaTvN0319wHDb/1d9RpjcsFCWBATzRT8i9cDWcx3OhQpuwCLcIJip+hJEgr5Bf q5EGUQjZOqTfg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 26/36] tty: use min() for size computation in iterate_tty_read() Date: Thu, 10 Aug 2023 11:15:00 +0200 Message-ID: <20230810091510.13006-27-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 The computation is more obvious with min(). Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/tty_io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 7cfa99fbbb62..4f21a21a1fd5 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -853,9 +853,8 @@ static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, size_t copied, count = iov_iter_count(to); do { - ssize_t size; + ssize_t size = min(count, sizeof(kernel_buf)); - size = count > sizeof(kernel_buf) ? sizeof(kernel_buf) : count; size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset); if (!size) break; -- 2.41.0