Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2732437pxj; Mon, 31 May 2021 09:20:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCbVBwNq/95+0QA5j5Ad6rN2kdS4s+lee0wqDnTXmbFEW+oAK6hOZhQxwCVANt22EBL7gH X-Received: by 2002:a05:6602:164c:: with SMTP id y12mr17737608iow.78.1622478018308; Mon, 31 May 2021 09:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622478018; cv=none; d=google.com; s=arc-20160816; b=WevadNGISr6b1kYEvWTKrtolbND2UJaCEccqKbEUo+vhMxcBt7s+AjZLmqCNX0ioS9 DoJkzOufwJ2SPYNOTJPW725Ix2JEGFzujLpqT07oXMrVmCaXjP5WHJ52w7xkBMBE9Jxd tFSpYg71MmDScThMXWWj5Qwz9lWSUc0vDHJGefgdLyh4qSUU77an8O6q6xroug6oCJjY h2wLBap9VFhgqP1LBI+AEU78EstVtinuvwbA9vWCjv5BOarNwpqv2xeuesdEkIGjqSNf FOyPGojEawBt4TH5qlVoHdruVhRQso4NtUjHYP0uMLjTiwWo5hF2mH/QPeLFPE3lUfID kwAQ== 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=IanRnsb1W93kBTMpAAMwxAFgx6YZ+ldeEkaB/SNAzAEGlElnhwY8r2316N5UIfTf2T JeGG+rB2eJ3l2jyhESX53Yt5l/D0a+nukPwag3gmySmdwonArpoQi9Odyx+b5GTzxZE5 dTC8SEoS411Ef1/ROwWWvSgMHGVP2CTEb+yk2su/AlMA6pGfgwJpmnyaOzHc3mv3nes1 bfV1t6RwSaM3S5CAc0M6EApOXE9X/Rt6EzJewUZxYQN43tittbks5+81AsFqTyQkmk/N tfNRyrxf9L/rQ9jUM2P+7kXEjUZDNmZad+QIz/ehbY50rd1zbPdCR4FUsVQQ3xZNzABX YQbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FtmkBumt; 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 l23si12926452jas.94.2021.05.31.09.20.04; Mon, 31 May 2021 09:20:18 -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=FtmkBumt; 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 S234707AbhEaQTl (ORCPT + 99 others); Mon, 31 May 2021 12:19:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:38020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233642AbhEaOlg (ORCPT ); Mon, 31 May 2021 10:41:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A100761C6B; Mon, 31 May 2021 13:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469217; bh=PwlgtTkGS+1C9BvwQKkTVlLQQhHTBS25/lKjRtxMhC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FtmkBumtQCTZDYtVmX3No5V+5dhhb2kIlgTmA+x/MsWpTZv3Hw/Cq07F8Mcbv5g9o vM0WnXDWzG6smJMihO9xN+q2bZtzXkj4s1X49x1bN+z4QFsNZChIGTp2zttvHXlKMQ uzbkngCzGI7b5C0XGkgi+xpJdaV6yM2IeymPFfhs= 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.12 096/296] serial: sh-sci: Fix off-by-one error in FIFO threshold register setting Date: Mon, 31 May 2021 15:12:31 +0200 Message-Id: <20210531130707.148993613@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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) {