Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp910031rdb; Sun, 20 Aug 2023 08:09:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSEHevrrBi0f1NPUmNH80MDRs/7Cn3MZvtOdkUZ5Hq2uXDcrcMgNNSmARvJdfTKGuAPz/E X-Received: by 2002:a17:90b:3718:b0:26b:2576:1e48 with SMTP id mg24-20020a17090b371800b0026b25761e48mr2179001pjb.34.1692544172993; Sun, 20 Aug 2023 08:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692544172; cv=none; d=google.com; s=arc-20160816; b=ZtC7a61pdCjHDEXG1XFjhXZxv/Xe6NvyTaI7DHf+PKglwU4fu4i9Ity4ppQayypTv7 xBAgXkKFEPlqZiCQkAFDrPkRXygrehWGltMWzuSBjkVnmEuIrj6aj0e0Y4l8fuv8yxE3 WfIkRbObIeeIiXOgWf7i85fBQig3gW5W82zoc6y1wuURLZlg4OJ8Nh+fCoH/T4lUfDDQ Z+MSIVHzoTa+QEDOz6a2tVFOQIa92+kPRGfl13zYPzojHDBMOYztFgfXInIfiL9f1Ej9 MzJcoSDTyvkhmxOmI4K1VwGrQHnlz5T5qVUJK9Sm7FxJQAfJJWe997K36KG8YnL5/d8p sBsA== 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=XSKBION3ANZjCHFyCuPh7LMrOrS3xoleNyhide/epJE=; fh=k7XzfpyqnKqnwxpqVF0NftrWa2FIpeAcHVbykF5xarA=; b=MHtcM3xKG4OQd3HyUh5XUyhz0CqU/EIFDRjTHChNmuaME/aRlnOVX1smeWUruBL/ol oVaC8Rvbf0fkFbzvLODAPrZflngvqmUlybueUadi6WxCo9AnafQZpuDfoi774PnK8RQx VgH0xYBukOolpxHsfjq8VfCFBlKvHLEUGLFeCK4nc8jSC0lf/W/1A7TaLobTm3ZAt/6P CKJ99NcB4gMh5arX+MXQtinZ8WaU9hsehpG12aRvHaZ3udmocs1Kkk8Wzh5FiO+SxoEr Ez2CkeC3uR6vZb3Z5ZJ/uWkX2K2nUpQpH9Rbaiv8iiOtKS9zOWHIizc/Yj6xq/MRBmxb 7XNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f2XDJqTl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c15-20020a17090a674f00b002613720fcd5si7126736pjm.35.2023.08.20.08.09.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 08:09:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f2XDJqTl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D8C8F39FB89; Sat, 19 Aug 2023 12:14:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244302AbjHPK4S (ORCPT + 99 others); Wed, 16 Aug 2023 06:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244125AbjHPKzu (ORCPT ); Wed, 16 Aug 2023 06:55:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF3E13E; Wed, 16 Aug 2023 03:55:49 -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 4AFE564C77; Wed, 16 Aug 2023 10:55:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0BDFC433C8; Wed, 16 Aug 2023 10:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692183348; bh=VEJwLY7hoPdNX4XnvykJ3RU6LGaAEAvuCCAn2+uGWxk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f2XDJqTl/pi4RpIiL4mEcVSC4RFSFu6dF9VdWLJNMGOyt1fMTbKbHwaOaU15B4Rs8 NpLR5QsCB3Szt52ZVkdxT9ju8/sxRQp8yZ7eyZufL0ja6nDcq4IF/mBlbzanRcaoMg 3YHR9LyFfb8cmb5tuzWKcb4imdnlivnrntNKaqWX4bmY92Z+BV0ceawAVY78ev2ucL wftcYbM/6RR2wVbf3LiW41SX32BBkut/iNUFfb/mrVmne1G3qmQy6j4jkp5WHdC0m7 /w6TFbX/MT5a2mcSHyofaE34a+ryKAjro+N0UFW5/S5FC6/hgv2/WeKERpxLuxnmjW wlVtmqR8WfEIQ== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 10/10] tty: tty_buffer: invert conditions in __tty_buffer_request_room() Date: Wed, 16 Aug 2023 12:55:30 +0200 Message-ID: <20230816105530.3335-11-jirislaby@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816105530.3335-1-jirislaby@kernel.org> References: <20230816105530.3335-1-jirislaby@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 We are used to handle "bad" states in the 'if's in the kernel. Refactor (invert the two conditions in) __tty_buffer_request_room(), so that the code returns from the fast paths immediately instead of postponing to the heavy end of the function. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/tty_buffer.c | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c index 44c0adaec850..5f6d0cf67571 100644 --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c @@ -266,28 +266,28 @@ static int __tty_buffer_request_room(struct tty_port *port, size_t size, size_t left = (b->flags ? 1 : 2) * b->size - b->used; bool change = !b->flags && flags; - if (change || left < size) { - /* This is the slow path - looking for new buffers to use */ - n = tty_buffer_alloc(port, size); - if (n != NULL) { - n->flags = flags; - buf->tail = n; - /* - * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs() - * ensures they see all buffer data. - */ - smp_store_release(&b->commit, b->used); - /* - * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs() - * ensures the latest commit value can be read before the head - * is advanced to the next buffer. - */ - smp_store_release(&b->next, n); - } else if (change) - size = 0; - else - size = left; - } + if (!change && left >= size) + return size; + + /* This is the slow path - looking for new buffers to use */ + n = tty_buffer_alloc(port, size); + if (n == NULL) + return change ? 0 : left; + + n->flags = flags; + buf->tail = n; + /* + * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs() + * ensures they see all buffer data. + */ + smp_store_release(&b->commit, b->used); + /* + * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs() + * ensures the latest commit value can be read before the head + * is advanced to the next buffer. + */ + smp_store_release(&b->next, n); + return size; } -- 2.41.0