Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1146504pxv; Fri, 9 Jul 2021 19:29:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgABB+ZB89YgHTfM9y2InIBEu10EZVOifL9vBf2YNxSxhHOMMVKJs5sR2pftx/Qbjq8smV X-Received: by 2002:a17:906:2c19:: with SMTP id e25mr1479952ejh.477.1625884179575; Fri, 09 Jul 2021 19:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884179; cv=none; d=google.com; s=arc-20160816; b=ax22yHfJK9q/Iea0ztg51BQwmbLnewePctf4kQwyynTDHkpx5yB+fwpZuDTmwLZV5G YtLSzJ6uPZfnuFK3jZifww2SDXkEPApRh5awg5RJlwKSeHI1gU8A+wvoCAIjofuV4jbN M1x7SWtjdJaZq3QfTFn07RntI36+9Rgjg2Tlu2oWAPuyUrz0pGLJq9Ic+wWpyFs7fLAb Pr7PNHvxcjCLq72vXlhBBrWNhYEKhKhJiVHbklEA1mxbe+dGVo4gEG52XOKMTb0bhFUk oyEwTX/bA+IMrdseF1b8wZT4UddEMI5TrvkioaC8/EurYV19tjt5/jsVkP+P4TyWVFPm iAhw== 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=R3V5YOgaM7I67dDUBBcRR5xSh4/ZeCmxAKamcLSSNqc=; b=EcxMqZmh9GoEd8emlpyuiMY/fTp9oedKSG6dfaLW3hA5tMgY5pZ9bUXOmfOwveTkVA m8Ke7aPYw6mux1IoP95YK/6vJqrgm4631r5NTHMqk1ncqWZckRdRvyRCSTJaauL5Plpj 3ic1CZvxaFUeLjdfcZy2jQOds+FDpnTKy5oLSyBCVDKnlrTgbLoHnCXaDOqC50eT6INj j/1U73tClfe9dRJqQ1LgqDI6k8ssOBJzyRk1ngn77yWXHTEBxgtfUHEPSFVj7ETccXyK miYgkgXOhXn+OEM+el2NNmfjDECucsU3CBpRT52YpRX0/48AcN6i4JJJa5kdpZXguEoA eNVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OQrpfU87; 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 s8si9089324edr.527.2021.07.09.19.29.17; Fri, 09 Jul 2021 19:29:39 -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=OQrpfU87; 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 S233629AbhGJC3w (ORCPT + 99 others); Fri, 9 Jul 2021 22:29:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:43192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233662AbhGJC1h (ORCPT ); Fri, 9 Jul 2021 22:27:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 33276613D1; Sat, 10 Jul 2021 02:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883879; bh=gLr8AGwzad/+lkLaGkCkTb6n2SoLCd488fNl48G1pGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OQrpfU87OUQRJ3ad8U+RVs/A9z28PaR6hZuiWpz0XA4NCblxpZ6HJn2xy/kJ7z8Qp DHHrsft8EMtc8GzzjUrs+fsLis3tuvLgzLfbt4lkvmDitIayWdisf3fbsQNRrtteM4 uf53keE4JjKDSSpWonJQGXIbFbfdWJSmVQdNckAvahFrIL2fIRIZquIVu3yx765/d/ 1bPIw27aa/XuVBMI7dwc3JI50wFZSu9Zhnx/PzdVKUbTJHHni52wCTObrDr8b/DvZF q4o9UBLCAFBBPBgx/XDunfZ1M2yYDUwTjVf7QzxJZVsIxi2ALJrMoC9CV1wLJPm4Bo p7e05TN3syHrw== 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.10 08/93] tty: serial: fsl_lpuart: fix the potential risk of division or modulo by zero Date: Fri, 9 Jul 2021 22:23:02 -0400 Message-Id: <20210710022428.3169839-8-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022428.3169839-1-sashal@kernel.org> References: <20210710022428.3169839-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 bd047e1f9bea..7aab87c92192 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