Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp1880292rdb; Sun, 27 Aug 2023 00:56:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGI7EdLpb2XJpovVL0wIMd1Qhs59ClbjZ1KfSf3wrfXv4iJpP4pISZ6ndK5wkjzK9a0JH1w X-Received: by 2002:a17:906:190:b0:9a1:d67c:b4f3 with SMTP id 16-20020a170906019000b009a1d67cb4f3mr7695307ejb.77.1693122973984; Sun, 27 Aug 2023 00:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693122973; cv=none; d=google.com; s=arc-20160816; b=0+8pyXW3Pg+NCanzdvNmhWrq2wa7WdFbxY6ejMuawQQzBICrMgIezMFYMsTIuf4jDr 49dcMCtTqAMMO0+XX0oB/IVxVcdg0w0si6uoYkvbwz+gT9y/udTfBc3Pvzvy2SCAPSUh CeQdxGudoHtq4n/qKHh2KWrTjS34M3syWNQPVBXAiu1AlNaUhAjmuv+zZ90aP7F6bH1K mYjdgoAF8yt4WyhgUf8pJSOUwf18jXcPD0AIQ01KGRLpcW9i3sK1H2bcA3Wm3NngznsT rtvc9EDajiQQvDDqxRpr54nGYna9nOGSR1Bun72W5o5S2k8brTBNW0Enwp0aHv03EMl6 /g1A== 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=ha+Ap2AWHbE4+a2VLQKi2lfAa9iN3jYtHj3WbydIRxg=; fh=1YNwm5KBWetjB3qGkhgLqh/dZnCTsWuqRk83JW6hjgE=; b=DJOyc6h8iUkpzue59mumr0HS/VQ3oh9J3bKXJxfWXPk6YXx5i52mOTuXoMy6Zd+IjU wGm5N3pICJ+GtdqYDJ8J3PGJQYqMs3nYyeEsGIEck+K4vQyy67P++5gvgTXb4kWbvxow E7xxp5jT+smjiLKKIKmszpto1qOq4UD0rDp5o/3zVvNtO6vKWfAXN+BS/6hm1mYXTIFt R0Edz5GVJwwdH4zMe0xJ3HD0HPXqcgqN/0HJboIdDD5IfjT8XLgQcOadVtXYJ56cPQFh hi88VYZ38ZGtSr4vDPGPorka/Q/joBwuT0ZVP+Y7NYdAUyYzX2TkHrJ21kXQ0D/JUhpN 95Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eYbY+GfH; 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 d12-20020a170906344c00b0099207b3bc46si3128905ejb.322.2023.08.27.00.55.38; Sun, 27 Aug 2023 00:56: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=eYbY+GfH; 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 S230078AbjH0HmI (ORCPT + 99 others); Sun, 27 Aug 2023 03:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjH0Hl7 (ORCPT ); Sun, 27 Aug 2023 03:41:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACCE8F4; Sun, 27 Aug 2023 00:41:57 -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 4B8B960B41; Sun, 27 Aug 2023 07:41:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9695C433C8; Sun, 27 Aug 2023 07:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693122116; bh=I0jbQNJLi61D+XXPK1fhJLdvRUL+hmTAhjSbepX9NGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eYbY+GfH0JlCZiIzihSzt2d3B0fcRd7eT4zRGA8oQsLU0Fh2l1qqcwoEw32/tSEx7 9M6sLYqOGuhWFC5LFk+utDaD3MB+qwRZbyFEEM9zuVOOVaHs1bRhF/SLVgPBx6BIt1 +rYafbBjXiudsIV9aTcC/DfPbgZHmGUWDyunatVQgyKt5oipUoI9aeOgnkNNiP4EqO EIFXtm3Zir30ac6oR2kwAZR1ugBY4uN0CtrbO9tcZBqrmtI3YJ+LUKSkJ38/cgZG54 zgxTMoTf1zgNEENY5npvcI8VE00dh9idt0/wFnULoj6iRvQToQT24IhwuqYE3u65tA dy0lW6oVgp1Kg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH v2 04/14] tty: n_tty: use time_is_before_jiffies() in n_tty_receive_overrun() Date: Sun, 27 Aug 2023 09:41:37 +0200 Message-ID: <20230827074147.2287-5-jirislaby@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230827074147.2287-1-jirislaby@kernel.org> References: <20230827074147.2287-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 The jiffies tests in n_tty_receive_overrun() are simplified ratelimiting (without locking). We could use struct ratelimit_state and the helpers, but to me, it occurs to be too complex for this use case. But the code currently tests both if the time passed (the first time_after()) and if jiffies wrapped around (the second time_after()). time_is_before_jiffies() takes care of both, provided overrun_time is initialized at the allocation time. So switch to time_is_before_jiffies(), the same what ratelimiting does. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/n_tty.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 7f9fee4cf7cf..c0b23e975877 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -1173,8 +1173,7 @@ static void n_tty_receive_overrun(const struct tty_struct *tty) struct n_tty_data *ldata = tty->disc_data; ldata->num_overrun++; - if (time_after(jiffies, ldata->overrun_time + HZ) || - time_after(ldata->overrun_time, jiffies)) { + if (time_is_before_jiffies(ldata->overrun_time + HZ)) { tty_warn(tty, "%d input overrun(s)\n", ldata->num_overrun); ldata->overrun_time = jiffies; ldata->num_overrun = 0; -- 2.42.0