Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2704610pxj; Mon, 31 May 2021 08:40:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzaFmAxPncqDcHIbCPKXp3IaRl66G6JydyKQXaEZnPxgQD/r0t/EhihnA0mnMdLet8DY9Z X-Received: by 2002:a05:6402:2691:: with SMTP id w17mr26840565edd.140.1622475613697; Mon, 31 May 2021 08:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475613; cv=none; d=google.com; s=arc-20160816; b=tOESqla40uSYmZrhSo1sKdKdmQCaeiRhZiHJBMXjODHRVo5tJhkyLB0H6rw9wclzoY nvfDTjx6MCt0HpBtwPPmpcgpctLtoOCOwU0wT4WnVwKPmgAcM21QEBYoOpA2QpCM8qg3 +/jDIo8fNArjt0SoqmVV5l+XQVLMAzuW6F8ifiEHTXmV0bPE3v0Puakk8m9YuR7Pl0G3 jrMK3C7WzvhYU5+GMRa6mIzgF00JmMDmbmEkoW6T9hqFd+0w6GpIrJT21peJUocXth/W XTikluiBaOvAcwGkyeC8VD4talwnqiPRB2g1PAyD7cKVRpgvEq1KnfP09oN18KDMwxne neGQ== 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=vACqX+Jc5ywfzrOr3NyO679wF/ddCVZS5Cpyj6vGp80=; b=MFZzCkUk0/BQCx3KhcFhzObCxhPcIMN8vbY52ls+qNv427nUKcU74be9FcXJBp5OOD L0RoVkp4j0YJU5Dg6ubPMXHNepNhiDx//j1SgZPLxk/ZqEhLBOsqh82CxWVTfpwQn9wf Zh869pdyGVW6VpekCMtqdfw02aE9dfdUqQKH803vB21ss0PJ0jix+2/5anOyGLzCYP5V pqLlfwRqOSE/NeCPM0Lkm8A37bMqbReHYTKlDkRN2Cn8Y5MP9TZdS8zMew7k1SQgzK8+ ZArsuCBYi95OFAWzskmFPK9XsayDxW8+oDAXCtKSUwT+9274j10si12M6Txlvp9yNqFk Q4Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LIJLzyIm; 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 k1si8573581ejg.69.2021.05.31.08.39.51; Mon, 31 May 2021 08:40:13 -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=LIJLzyIm; 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 S232644AbhEaPgh (ORCPT + 99 others); Mon, 31 May 2021 11:36:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:48834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233857AbhEaOVb (ORCPT ); Mon, 31 May 2021 10:21:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A80C619C0; Mon, 31 May 2021 13:44:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468690; bh=zrSSD5pNPwNmFPdwAPPZmx+5i/cwBL/iK4acZnwDC+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LIJLzyIm6RcJU803qeKdGnVqAfrIxmzcNhMUae/BqLnHxNUKekCLhwbjOYtzp79SH 415QygyoZxL7FISEaka0M0n93NfayqBY9JVIQr/2sOERvLpEOMqCqEKImPOp9YLCcV tv7hD6ys4HqfiAO/R20kWo8xda9TROH3XPbiUmaY= 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.4 054/177] serial: sh-sci: Fix off-by-one error in FIFO threshold register setting Date: Mon, 31 May 2021 15:13:31 +0200 Message-Id: <20210531130649.787362966@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 @@ -1026,10 +1026,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) {