Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1149679pxv; Fri, 9 Jul 2021 19:36:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRGiXML8LWlcEToyyh7MsM+1WSDD3nf/YdHUeSrcYypCojB24JMokKRf0f29DnlNCF4CVe X-Received: by 2002:a6b:f41a:: with SMTP id i26mr30419040iog.162.1625884566063; Fri, 09 Jul 2021 19:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884566; cv=none; d=google.com; s=arc-20160816; b=RpAY3qyJibt46AEOhIs9UbheSyTOuthIyhDnDQ3DEEHlgnpux6U0YFtSrl67YASpdR KDMd/jEM05h4XbKUyqBJvhoupevRBMDVTk2fF9zAnBlhKXODrGnw4XtJG30ChOWg0K0g Xev3yZgKEmk6sHlqMQ1w6KuCnY6iUuH/JU5EDsFaxfmL9et+4BX7CokH4tlc/e5b5NMQ ESLq9Fb8kwWiPynSZJ6vayGIB6L1h9ryzwnvvnXhnYd7dYUsaacS8X/CgpyB/k7xzWx2 r0wbhJyk20A48rfzDZzsIva7cFHPW7ClfKHIH2Jp+nKm/Se46sK64qVDZIfMD9fzhLlN V76g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Zq4RGEtJr7yS4du5+7q2O9J5mbkSwCzyX3jJXtrb/Vo=; b=GNt/kc43b9/PE4T1q+mmILlHmRZFIxu2y6nsh8WpS4dkZ9Hf/JK16WcG/YYlRfX7Ae 0OEVN1YtaLRtMaxMi+fEVvyf4ai4ikZi8LlvF8p3c5SD8AWbT/YLHPXkSvrOlz8siRQd 28cPJegCfbZ5kiiEhQMCVmD/uLCHm2a2yYkkgjXp58OZ2i92MH0ZFy2mLxvGN67ylFTn vdHstWUrege3K91bIKfmt9cbWBM4qwxDPco1ffu724BMvAZgx6DN1cdcbhfjvWshkyZ3 M5S7jR+tkEEFjsGL4tfWyWuzBubpMk4jC0Yi3rfdUXOYe4YCqpaqSYqGQpNvp8zcDY/S qhZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JbONIqs5; 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 h26si8415576jav.114.2021.07.09.19.35.53; Fri, 09 Jul 2021 19:36:06 -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=JbONIqs5; 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 S234258AbhGJCiH (ORCPT + 99 others); Fri, 9 Jul 2021 22:38:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:53326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235644AbhGJCe5 (ORCPT ); Fri, 9 Jul 2021 22:34:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9BCF26124C; Sat, 10 Jul 2021 02:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625884326; bh=jubVaQRlhNSmiN+XmTt572cEjRXXkVgH+Bp7bvrT6Vg=; h=From:To:Cc:Subject:Date:From; b=JbONIqs5EynXwNL7RjgaOGjuP7BVbgW1N0Pt1yUkiR2abyRLO1aCRCWrejKGa3Otx 6fjzA2IGLzgRDUr5X+9AuSRhppXZnV8XgNwzt/eb7GqPxcnA4FfZ/RnicKMTvCQd0O UWPc3zB4cFcC3GH5Tnk34nhg+XfzEgxGQVzVvR008G8CuOhYCOzAYCHylyyyn06Pit MklNqLg9DbtQIJuuz5EROreiy7WyGgE3GC9c8pBCF3mvY4oMBMVCYrw8OuJTp+auP5 3UqWXbF/nMJp/OYybbT4K/L3gLG+pSTiLMxkOEIxXBy4dzH+DqE4Rg+hJywpqEGytE ULQRKhXrKx6mg== 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 4.19 01/39] tty: serial: fsl_lpuart: fix the potential risk of division or modulo by zero Date: Fri, 9 Jul 2021 22:31:26 -0400 Message-Id: <20210710023204.3171428-1-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 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 4b9f42269477..deb9d4fa9cb0 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -1992,6 +1992,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 = clk_get_rate(sport->clk); /* -- 2.30.2