Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp906279rwl; Thu, 10 Aug 2023 03:38:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaSh7rh+zYbSVc08m2JK0bTvTkvu+/Yxsx11lKpLK/trOHd0o9xtTyC2VD90GkBVq7dOrh X-Received: by 2002:a17:906:220e:b0:99b:e6ec:752c with SMTP id s14-20020a170906220e00b0099be6ec752cmr1847536ejs.70.1691663935587; Thu, 10 Aug 2023 03:38:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691663935; cv=none; d=google.com; s=arc-20160816; b=kUnZNGUSdQAt7pP5sLbdi8KHngZoxyutGpTSVLI7dty69Dx0fsMw0JLJvOd3H12mRD vbDgbogAw5GSbTyBaRirsrmvjlAGvN2vom855ASwGO8X868uP+50JHxyI2sYXDnBIB7K u/DEnn65DAxBDnoOrEzGgGTrC0Lc4PcH+Y+ZxPKPdx8qLwqYJIcv2raFZyF1brRLUuLB E4W2Ko9ViSv3khn/IGEZWgBUGemZ3GVodHMT6J08eKpH4ZTXy6hiWBmMfLCwSh1TAARI 7i/YvZhnDGFeoE/fxBk0V7pcex/+XEb5+IptlOKuHP/SMVgV7Ikj70iGbvhkz/6YOZ+p SUug== 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=0rM45iNGZRM6pm297/y5EKHEZssohn/cNWAZ5HWs1jU=; fh=RwSshDj9szMD1MhHfJm+xSkY1q6cPdMvQnhSx7kuLkY=; b=rteQP+7dzV4N6e6eude2pLk9P0G+Kb4Oj99iaiAu5fQofwQszSby/B92s07+UQEu+Q Qo4O30HmNN/UovObRDFOzNKqKVp4DstWPmEAnYn8L32A4DyzSwVAJIACnx4yNmVdkb5V O+5Gj9Lyim9REhHJdx12o4WPlNPsmiG7/A3oiT6i+6RwIwM+FoLzgh72es71swIoEzFN L3R/ZT+TP/Y4ltbb2GYZPYhI+lvZdZcBBb8VET2RR5YCGDBuoffRmiPUk+RxeLR8oCeH NrEzXKlqC1gTgP4usCj/eZknJCExYNByXusqaKDnJreCu4MmTXMauVSUvbhBtoq6/r4J SqOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HFwAREQp; 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 o5-20020a1709061d4500b00993a68a3af5si1118093ejh.529.2023.08.10.03.38.31; Thu, 10 Aug 2023 03:38:55 -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=HFwAREQp; 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 S234807AbjHJJQV (ORCPT + 99 others); Thu, 10 Aug 2023 05:16:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234546AbjHJJPl (ORCPT ); Thu, 10 Aug 2023 05:15:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 874BA2D71; Thu, 10 Aug 2023 02:15:41 -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 263A8654CD; Thu, 10 Aug 2023 09:15:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04BA6C433CC; Thu, 10 Aug 2023 09:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691658940; bh=/6gBp59IIeAJu6gxv5VKOtBckU5nQfxa5DEsbTV9E6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HFwAREQpZ/lAxISpilmXwfEfwiUtf047Qrgajcf6NYSCE2Z57lCQmkCsdr1S7JA+o kckZFTcaZhxk8Mup8VpG8PZpzQuoJXimVvcH06NXH4jXMRPppi8jDftkrkhfNtXeCT jX5tiJugfgwWcGn07n1T+0IQ0C/Nl5fWrv4A1uvFDZ99Y2l9iLnfbBAKtvz05YTW36 X9zgHtoyDa7AD+mWmElBJ12FGQFBruDCy1YI7lkjqZmBc+xwmJv8nJ/BO8qZr00xUs vd/8phH85v3cwFLZE2XMyvJkGCeqy82qjDajro5YmIIwZDL9DTbmXu8hPr7Zhn7JQT wq0icwaUGgWhw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , Max Staudt , Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-can@vger.kernel.org Subject: [PATCH 14/36] tty: can327, move overflow test inside can327_ldisc_rx()'s loop Date: Thu, 10 Aug 2023 11:14:48 +0200 Message-ID: <20230810091510.13006-15-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 'count' is going to be unsigned and the 'count >= 0' test would be always true then. Move the condition to the loop where this is easier to check. It looks as is easier to follow after all too. Signed-off-by: Jiri Slaby (SUSE) Cc: Max Staudt Cc: Wolfgang Grandegger Cc: Marc Kleine-Budde Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: linux-can@vger.kernel.org --- drivers/net/can/can327.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/net/can/can327.c b/drivers/net/can/can327.c index 05e9c035e8f6..4533dc00f215 100644 --- a/drivers/net/can/can327.c +++ b/drivers/net/can/can327.c @@ -901,7 +901,13 @@ static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp, */ first_new_char_idx = elm->rxfill; - while (count-- && elm->rxfill < CAN327_SIZE_RXBUF) { + while (count--) { + if (elm->rxfill >= CAN327_SIZE_RXBUF) { + netdev_err(elm->dev, + "Receive buffer overflowed. Bad chip or wiring? count = %i", + count); + goto uart_failure; + } if (fp && *fp++) { netdev_err(elm->dev, "Error in received character stream. Check your wiring."); @@ -930,13 +936,6 @@ static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp, cp++; } - if (count >= 0) { - netdev_err(elm->dev, - "Receive buffer overflowed. Bad chip or wiring? count = %i", - count); - goto uart_failure; - } - can327_parse_rxbuf(elm, first_new_char_idx); spin_unlock_bh(&elm->lock); -- 2.41.0