Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp507224rdb; Tue, 19 Sep 2023 01:57:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXRNVNm9qOD7lPToMRaxlJCXdH/3j5thLrWhVeG4jX/WZ1+iPY18vM5mld5dV+zuoSD4Xa X-Received: by 2002:a05:6358:9143:b0:139:d24c:ed28 with SMTP id r3-20020a056358914300b00139d24ced28mr12331083rwr.12.1695113829696; Tue, 19 Sep 2023 01:57:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695113829; cv=none; d=google.com; s=arc-20160816; b=E7+Q0BOBkuMj7jr7qUNQWUwIpckZbfQVINqODfRNurgeUUF07XgZDwLefDL6BsfU+8 SWRlsazZ155e2snouWKf6O9d1H5mSPjMukBVbFLznY7EJkTLNTJZ7wJ9ZPagzeeH5XPJ K/QDrog0VVGcbhnQ9TbivwE/Lt3+k+eaMdvHrS1wSb1AmDnc0DsFiGPkY2C2ZY6BuU9m PwFVnaqmXC/3IFxZWnANMD0HYd6YsU+mRvso+QiMIT3WlCqGuLooeD9NHcbxjMcy6/kc Q/JIVE4TqW71M6OlySbLC4dHO1bBBwJKoMIlPuVgzAByeaS1KlHoKo/6OZvf2T95b+D/ XITg== 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=YSPqq4oXodUIFLj21AdIMp2rCEMZxMK3qDj29oX9N7w=; fh=1YNwm5KBWetjB3qGkhgLqh/dZnCTsWuqRk83JW6hjgE=; b=kNcl4cCe56XWbP1N6VoUm9LzJ2oX2oYp46QPdU2g+ZushWxUbJw5eguscLb9uSrHra 0/Coba8O1/wg47uZLHn3NL3s0A3iSI5KuZnNTTlknGM0Y2tawuCLE6jnMPC6JLNBwK+o Mv/EzpWUq1KbQxnjTto6w1tSpzSemJTxVLoEoGVMgKkQxu3CLw+qWFaD4FcRhRtHht1z CWIdVevHXSP9A5/nszVQU7rBnhHbsQXe1vn0j/OLpi+8IGT/AZiqz5lmBDl24ByUxvb9 qihW2bdvYyf/iUpIImb4BcRQC5oTkKlOx8oNrGulQT7MandlpNQbS+bIEX7gV16aVghS deSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k0QlOdvL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z21-20020a631915000000b005775302b11csi9287291pgl.81.2023.09.19.01.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 01:57:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k0QlOdvL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 60CDE80978BC; Tue, 19 Sep 2023 01:52:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230387AbjISIwV (ORCPT + 99 others); Tue, 19 Sep 2023 04:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbjISIwL (ORCPT ); Tue, 19 Sep 2023 04:52:11 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B97E6; Tue, 19 Sep 2023 01:52:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89483C433CA; Tue, 19 Sep 2023 08:52:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695113525; bh=BIErATDceY6ExeUaCulU3mr2Dddd6kPOEIhHuMduq7w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k0QlOdvLfDUG8c/J1j+tD/EWzkI7Z/KLetbEN00n/upp8pJ9V8mrpZrpEaydJ6nzB yUYBQNmSOqcvAtzYd4LpOkisNbPe/M+B99MV/l7TCUnxWBV9AixJb8xI2g7CTk8glu WDMlZGcBMnPDzxcZi14FVknzyfyP/l1IXJtUrBIRtJkJH57XzJYOURyOOD3IhwPFT8 qGjpXnEsGGDWeP1qAuQZNWLZckWmEF6OIJyWBryteWHtnwX6h1jzoPQSPFf5QGyZJq lqEZJe2FBvUfap+golpuqzH3MiA4UXxkAuhZm0qnYIRagieNDBXJTwAYnWKnpOntD6 xwaOmK06NhrAQ== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 04/15] tty: n_tty: invert the condition in copy_from_read_buf() Date: Tue, 19 Sep 2023 10:51:45 +0200 Message-ID: <20230919085156.1578-5-jirislaby@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230919085156.1578-1-jirislaby@kernel.org> References: <20230919085156.1578-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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 01:52:25 -0700 (PDT) Make "no numbers available" a fast quit from the function. And do the heavy work outside the 'if'. This makes the code more understandable and conforming to the common kernel coding style. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/n_tty.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 6a112910c058..922fb61b587a 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -1966,24 +1966,26 @@ static bool copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, size_t tail = MASK(ldata->read_tail); n = min3(head - ldata->read_tail, N_TTY_BUF_SIZE - tail, *nr); - if (n) { - u8 *from = read_buf_addr(ldata, tail); - memcpy(*kbp, from, n); - is_eof = n == 1 && *from == EOF_CHAR(tty); - tty_audit_add_data(tty, from, n); - zero_buffer(tty, from, n); - smp_store_release(&ldata->read_tail, ldata->read_tail + n); - /* Turn single EOF into zero-length read */ - if (L_EXTPROC(tty) && ldata->icanon && is_eof && - (head == ldata->read_tail)) - return false; - *kbp += n; - *nr -= n; - - /* If we have more to copy, let the caller know */ - return head != ldata->read_tail; - } - return false; + if (!n) + return false; + + u8 *from = read_buf_addr(ldata, tail); + memcpy(*kbp, from, n); + is_eof = n == 1 && *from == EOF_CHAR(tty); + tty_audit_add_data(tty, from, n); + zero_buffer(tty, from, n); + smp_store_release(&ldata->read_tail, ldata->read_tail + n); + + /* Turn single EOF into zero-length read */ + if (L_EXTPROC(tty) && ldata->icanon && is_eof && + head == ldata->read_tail) + return false; + + *kbp += n; + *nr -= n; + + /* If we have more to copy, let the caller know */ + return head != ldata->read_tail; } /** -- 2.42.0