Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2658675pxj; Mon, 31 May 2021 07:36:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiT4MSfddV/66jS9KkfwJMTqjj4w522pX7+M0j9RfMox7pbLHcS5yIktOCs87CsQB+1PsL X-Received: by 2002:a05:6638:10f:: with SMTP id x15mr21105784jao.119.1622471763083; Mon, 31 May 2021 07:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471763; cv=none; d=google.com; s=arc-20160816; b=ce74nu7lPkASAIEn0NTtbLfv9KeOVAEuPXx8y8ouqhiAEXLY3BtjMLmZO1xytzenDG QefIF+GRsD8LNxIUWKBKv2J/AOuCUrm40w9U22MUkWiLsY77nqDzJuLPw5hKFALRJ7av 8OH47c2bxyA0H/3DnoNXYwEXBNDa8HonciWhOcjYAnPo45LR9DiLgB8VZ5P3f5KlhWoM Lx4YV5SAlzPxPJNSkPQmFm2qXuWBrCkLczxojHe5V5qnNR63RFD3nCIlNUTmyNElmu4i pCppNVG6N97w+vamuL00UEKADDk0+OxzjyzsWOCTiR6QsDLEaQ9fW9AIvzBoRh0V+gGt 75nQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zt+oyKauEcmOW6VGSgnq/bIc87SdSeKiRdVh/MVSAnI=; b=c0pGkq8JrAXQ86e0MoVf822LEPR7/Y064M5vGd3c9+ahPi+kCmr8XP0tStZRRXMwUA yR8CjZIefi49v8Rl2gbTZKGJAtJjEHJhxsjKYr2vKZur0rWgbbb0v54u3X4O3yi7a7Nz 4qrQGHI1M6ScOTsd9GWzVeXWEOOa1LFgxf13AnqrKYs222SklzpLv6p5820NJF7OeDD7 0PuOVksTjrzzpO/4U4IVMSZ+Tv+0EFP3Si/VggqOK2LaQeFJqWwFJxgiLGbxxBtOvNDy l2M7AMFqZkMUn1h8Q1fmvuaGbPYudN11a4i0PuwxqNhafMQNfHLjAlC7FpnzG9diwTZN tbwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xZZ+H1hF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t2si13189550ilq.112.2021.05.31.07.35.49; Mon, 31 May 2021 07:36:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xZZ+H1hF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232716AbhEaOgl (ORCPT + 99 others); Mon, 31 May 2021 10:36:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:60414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbhEaNzz (ORCPT ); Mon, 31 May 2021 09:55:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CC02860FE8; Mon, 31 May 2021 13:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468073; bh=PwlgtTkGS+1C9BvwQKkTVlLQQhHTBS25/lKjRtxMhC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xZZ+H1hFOhPPusbi5rtHgRBuQa7kGGUW7CBQReCr/3KDC/JFuQbSiYVD1L0ZTWqsA hD16914Bdj389Jce/uQ6b0wIb6F0sl++9KRnpm/YmD/FVgmFP1BQ8cZIXolGNVcwRl NTFO1E0rVUJXNlFV2rBkiRHW1OVPr+3ps+lTcn4A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linh Phung , Wolfram Sang , Ulrich Hecht , Geert Uytterhoeven Subject: [PATCH 5.10 079/252] serial: sh-sci: Fix off-by-one error in FIFO threshold register setting Date: Mon, 31 May 2021 15:12:24 +0200 Message-Id: <20210531130700.674221127@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Geert Uytterhoeven commit 2ea2e019c190ee3973ef7bcaf829d8762e56e635 upstream. The Receive FIFO Data Count Trigger field (RTRG[6:0]) in the Receive FIFO Data Count Trigger Register (HSRTRGR) of HSCIF can only hold values ranging from 0-127. As the FIFO size is equal to 128 on HSCIF, the user can write an out-of-range value, touching reserved bits. Fix this by limiting the trigger value to the FIFO size minus one. Reverse the order of the checks, to avoid rx_trig becoming zero if the FIFO size is one. Note that this change has no impact on other SCIF variants, as their maximum supported trigger value is lower than the FIFO size anyway, and the code below takes care of enforcing these limits. Fixes: a380ed461f66d1b8 ("serial: sh-sci: implement FIFO threshold register setting") Reported-by: Linh Phung Reviewed-by: Wolfram Sang Reviewed-by: Ulrich Hecht Signed-off-by: Geert Uytterhoeven Cc: stable Link: https://lore.kernel.org/r/5eff320aef92ffb33d00e57979fd3603bbb4a70f.1620648218.git.geert+renesas@glider.be Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/sh-sci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -1023,10 +1023,10 @@ static int scif_set_rtrg(struct uart_por { unsigned int bits; + if (rx_trig >= port->fifosize) + rx_trig = port->fifosize - 1; if (rx_trig < 1) rx_trig = 1; - if (rx_trig >= port->fifosize) - rx_trig = port->fifosize; /* HSCIF can be set to an arbitrary level. */ if (sci_getreg(port, HSRTRGR)->size) {