Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1144739pxv; Fri, 9 Jul 2021 19:25:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeqMjn2w1ptkMjXysHMG5o8CeJs52RMtvBeDWkaBLx90eqylyimqJaIQohKkaouhTGncb3 X-Received: by 2002:a17:906:70cf:: with SMTP id g15mr40450870ejk.366.1625883950741; Fri, 09 Jul 2021 19:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883950; cv=none; d=google.com; s=arc-20160816; b=uYyHPY9NTT3G+uWt86Nq4rTXKbb9HW18Po82jUKRENLz9sTBWLr07IpLHfCunl8C4B k/2HVQiIVbFtKNqaRrUyNkk09Egfga4F3rBwvQ7qrf/cOAgvUM6mGaAslznZrKkK8LCe cid4xRLUb33Fzm6F5MZzGm5ctQToslLla9FniMLuiygMimy+qO5qn78Yfh+SpZSlnd0P rHzvsh1VPWJsbIb7OYfdTk11dJfwExVG8afquIsd4MCmPB/7sCzTvs+2h9fTpeTBTfj2 wjYuEFhm9na1YWwGS8LOIdvksXDi2CA05wGedKI32dx3iyBgt8TPyCUfCi6hXbARLqcT j6Pw== 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=kWd+hU+9Ad4XdNPueoRHgQRIo62QlMjKjlCcAZAAZFY=; b=Po7Fk16RmbVJ2NRKg2ebGnJZyKFSz8sY6mZg8evbWuVJm6wzQjfX1FbTPEpykYCYXc EbuZSZ8KPNaniLQjlu1to5CG2P3Ozsaeo3S6dOI381ZE2w5GEFswPRIrOfP1ul9Mw8AA XjlFPHwTCAitrAinI0qiuGiJFP+D1yt7x773qas0ttnteplJIN/Hc0kR3UVPZBM4ZLLI SdvouTihGw9UCgJ0r/sdQtgXt4beXOOXOERptC1r6ck8zEhpTlj/c/I7nO3v87vF9kHG obR6etdMidywrdeMG/j6VkIJobjkZMMefIdxb7cs863zv04gm8Uwd/lqmaSLKzxrWrOs HTag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bcwDP9z5; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si9856144edr.274.2021.07.09.19.25.27; Fri, 09 Jul 2021 19:25:50 -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=@kernel.org header.s=k20201202 header.b=bcwDP9z5; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232540AbhGJCZD (ORCPT + 99 others); Fri, 9 Jul 2021 22:25:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:41714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232102AbhGJCYx (ORCPT ); Fri, 9 Jul 2021 22:24:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8A5EA613BE; Sat, 10 Jul 2021 02:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883729; bh=+9UPDC3W+FxbL0Fh0wF+dzwqqgzFRZAhf/9SCoD6MX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bcwDP9z5R6UZFHjFjcuH/fPt4PEb5GwfIxlYh+0dfsFfdB+gAbQ1aX1bPkZJ7LvlR p8OIB+GUZxsEw2FQPiM3kli2X7YJqjIiEl0Pz3NYzzgm7LGJDMyR/+l2wAgybFAEtM 9mGTB++jFWAfi4v6rm6FiWh3FbAX0ihbXtr8sgH6PQEYQnNGzk3wwlSOV9aVuADr88 NMSGFEIQi0CRIamJz38nVb1T0yYrTaMCQLFWFFLov2KD9/Fc8gPZ/LVpGu3LCgrJrY +rkD8yDFciX8nXnM5IjSw/U5CZtktxPjZ4slkbh9x7OtOB1UkcUltsXaXXx1lKPg2k mhkq9xX8AI3rg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sherry Sun , Greg Kroah-Hartman , Sasha Levin , linux-serial@vger.kernel.org Subject: [PATCH AUTOSEL 5.12 009/104] tty: serial: fsl_lpuart: fix the potential risk of division or modulo by zero Date: Fri, 9 Jul 2021 22:20:21 -0400 Message-Id: <20210710022156.3168825-9-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sherry Sun [ Upstream commit fcb10ee27fb91b25b68d7745db9817ecea9f1038 ] We should be very careful about the register values that will be used for division or modulo operations, althrough the possibility that the UARTBAUD register value is zero is very low, but we had better to deal with the "bad data" of hardware in advance to avoid division or modulo by zero leading to undefined kernel behavior. Signed-off-by: Sherry Sun Link: https://lore.kernel.org/r/20210427021226.27468-1-sherry.sun@nxp.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/fsl_lpuart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index 794035041744..777d54b593f8 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -2414,6 +2414,9 @@ lpuart32_console_get_options(struct lpuart_port *sport, int *baud, bd = lpuart32_read(&sport->port, UARTBAUD); bd &= UARTBAUD_SBR_MASK; + if (!bd) + return; + sbr = bd; uartclk = lpuart_get_baud_clk_rate(sport); /* -- 2.30.2