Received: by 10.223.164.202 with SMTP id h10csp1039248wrb; Tue, 7 Nov 2017 20:24:43 -0800 (PST) X-Google-Smtp-Source: ABhQp+TOGQvd+/EooUj0M38gcNNfBwV1uJjV/71hkHLc+FKN+FXWZzW+qvIgoIeyvHM7O/wTs7ag X-Received: by 10.98.8.74 with SMTP id c71mr1095301pfd.101.1510115083193; Tue, 07 Nov 2017 20:24:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510115083; cv=none; d=google.com; s=arc-20160816; b=smZ8aWPG/7alSBlZ6daZOp2/O0Z0vcspafPeAvHEpYgqBKcviOMe95GH0aQzeyi5MJ QFoA3eonrMA7RLuS7IQgUXt0vLJx/IrwO8Zt511PmjZwEqdot54P69NmT4BA167miGTz v7LMOalGCIKDgh0Gei6QWPJUWNtxw0BrFA941/NZjq6FJWWkpfE3nvVEbVcoTpn7hWph RLjR6q5hIEKCh6SuVgsKYuDpK+ca39lqE5NJ9JYTB+hd9bkSmqBvATfxyDiwScx/s9Bz mP6MgLXeeHxE/72zyOGxAA5ikhA/GzZshuYfrCCeB4kfKJWJKSW9q154upII/tBuJX14 3O/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=1rPV7v0Vlx3gZggym4SuwoG5jrqQqcsym8+OnVp06ek=; b=dujLkPOASxM6AtI27rM14CpDFo36once+OwAyCh5fWx3cdj60sjwL9FekBzzPmkYw5 vjAycDg/eJqrawWquAjmnsii4LjTzIXGwLy+/DRI8ZwKxBvE07KsORM/UC6fNPW84lFU WjXZ4TL50aaIHfO5unPtaXzMu27fxcqWlDq6Wplrt0hv5q+8AyGGR+KY9zj8LnW3i0sg OAcGOFbNGUraKNYMFH0ueKpaAUFoadtv/kEW4WqtYWKKc56tmWu3QFf3Xz0XuEMznXO5 7cAnSAS/Vr9uD8nYqVwhT1xO8CztHiVokm2pMQ0vFI5krxymr/VF25yStgqRaohDLL6Z Gk6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ehEfSs1P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si2667222pgo.483.2017.11.07.20.24.30; Tue, 07 Nov 2017 20:24:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ehEfSs1P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753844AbdKHDF4 (ORCPT + 90 others); Tue, 7 Nov 2017 22:05:56 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:46576 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750888AbdKHDFz (ORCPT ); Tue, 7 Nov 2017 22:05:55 -0500 Received: by mail-pl0-f65.google.com with SMTP id y61so372664plh.3; Tue, 07 Nov 2017 19:05:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=1rPV7v0Vlx3gZggym4SuwoG5jrqQqcsym8+OnVp06ek=; b=ehEfSs1PHonD3Xnu9F6NZHm5n1HPuoYgmBkolemvG+4bjOCG/TtODK8NJuaIuDuEsf pbp2kwknT/VFpgRfD9/f6v9SlM0eQBU5TEccf5hquGYReouyYIwl7LInRYJQAaW+R7om z1uZ0nFFExGSR9eFJNpUNLqC2ePFLk2g8AU9oIpsBgBa2o22QSOLjzrPUCf45yKcDv7N VOYfZPOOQsqY0oz1cCzYH1UjwWlPQOa8UFLp8V+gNz1p7JTDmEP3qtRoVrsJe6NISi7C 2BFr1wzMdzw1FMe6nv93hLsQnGQPHM/QrKPhcwKKtDrJyWM0+b8A6aLL7cT+Mxte3Yr8 sO4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1rPV7v0Vlx3gZggym4SuwoG5jrqQqcsym8+OnVp06ek=; b=TiDSMjsOCX0gSkH8XTw5c90LDlTeVBaBFRCDMiLcpAvW2IQWHtrUAcGeCzIBOOamXP nnwNQQCXFXPk2N9FRF8cGI+CG7Y0aIqfEYj2zSpGRzVTpu9weXJQc5Ua0b0/5XYB+u6D kqqhxFomXvFq7vPzqRNklArJ9zDTYm9PsWSFcYQWOQrBmpXixykA6ONjzb9xOASKPZ8T ew0gVArBx4V44jqP2sIb1vWLz7HwDf9b3X2w2gtL6Y2sJ+YJRaXzSXlpgeHIFadFP6lD YQGjEuehzGkAEFcJNw649LIi28ea//fQnRRWYrNEk8Ac8p6JwY/42CYk1rg64kLANxhu YNkw== X-Gm-Message-State: AJaThX7IGEoQ0MdVr2XZdLWr+kR4pR63jZcrpNYNWdiWGnzkJ5PonfqK Z4rMP0VBkBog6rN8aw4LoA0= X-Received: by 10.159.235.147 with SMTP id f19mr831660plr.42.1510110354508; Tue, 07 Nov 2017 19:05:54 -0800 (PST) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id z13sm4552032pgc.29.2017.11.07.19.05.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 19:05:53 -0800 (PST) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: gregkh@linuxfoundation.org Cc: jslaby@suse.com, lukas@wunner.de, rel+kernel@agilox.net, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, ricardo.ribalda@gmail.com, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V1 1/1] serial: 8250_fintek: Fix crash with baud rate B0 Date: Wed, 8 Nov 2017 11:05:46 +0800 Message-Id: <1510110346-28893-1-git-send-email-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The 8250_fintek.c is support the Fintek F81866/F81216 with dynamic clock. But It'll generate "division by zero" exception and crash in fintek_8250_set_termios() with baud rate 0 on baudrate_table[i] % baud. It can be tested with following C code: ... struct termios options; tcgetattr(fd, &options); ... options.c_cflag = CS8 | CREAD; /* baud rate 0 */ tcsetattr(fd, TCSANOW, &options); tcflush(fd, TCIOFLUSH); Fixes: 195638b6d44f ("serial: 8250_fintek: UART dynamic clocksource on Fintek F81866") Reported-by: Lukas Redlinger Cc: Lukas Redlinger Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/tty/serial/8250/8250_fintek.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c index c41cbb52f1fe..3d66c2c0d7ee 100644 --- a/drivers/tty/serial/8250/8250_fintek.c +++ b/drivers/tty/serial/8250/8250_fintek.c @@ -312,6 +312,13 @@ void fintek_8250_set_termios(struct uart_port *port, struct ktermios *termios, F81866_UART_CLK_14_769MHZ, F81866_UART_CLK_18_432MHZ, F81866_UART_CLK_24MHZ }; + /* + * We'll use serial8250_do_set_termios() for baud = 0, otherwise It'll + * crash on baudrate_table[i] % baud with "division by zero". + */ + if (!baud) + goto exit; + switch (pdata->pid) { case CHIP_ID_F81216H: reg = RS485; @@ -324,8 +331,7 @@ void fintek_8250_set_termios(struct uart_port *port, struct ktermios *termios, dev_warn(port->dev, "%s: pid: %x Not support. use default set_termios.\n", __func__, pdata->pid); - serial8250_do_set_termios(port, termios, old); - return; + goto exit; } for (i = 0; i < ARRAY_SIZE(baudrate_table); ++i) { @@ -353,6 +359,7 @@ void fintek_8250_set_termios(struct uart_port *port, struct ktermios *termios, tty_termios_encode_baud_rate(termios, baud, baud); } +exit: serial8250_do_set_termios(port, termios, old); } -- 2.7.4 From 1583566680357273706@xxx Thu Nov 09 05:54:31 +0000 2017 X-GM-THRID: 1583566680357273706 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread