From patchwork Thu Sep 20 09:45:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11527 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D4E9123E41 for ; Thu, 20 Sep 2012 09:46:56 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 6EEC73D09AC2 for ; Thu, 20 Sep 2012 09:46:16 +0000 (UTC) Received: by ieje10 with SMTP id e10so2545757iej.11 for ; Thu, 20 Sep 2012 02:46:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:mime-version:content-type :x-gm-message-state; bh=1O0ktJPRUFsK8lu5dOXrVYTM5jF6haHIvOz5l+7tsD0=; b=mvN9RQ5XW0fyBfQF6XJc7z5prs39k1yOIi0OpliGlmSI/L5IBDg5FxncLgoAnOPDwt kYyFQm5N2HFTUIdycMRpZD8aVos46sZyIuPDBtj1KonkyVIoCTfhzlKOsRG+cjwffhEW oKf85GwQvLDpb7tUoq1qMstokLwTq5xbISNn2O4FLJuGOKGCujP2U3gkU66WsJTaZNOT Wh29oa9pCQBauRp4V5S07DiESjlFPMDtVvWgqlY9Fw/mNM/8tNuiikJmVYGgkXeyVxt3 5J/WKPXZAOffbcpFxkNrLrIb2B53Bt+kCYpVuGn1ZegHWoJavzwezC4tfyy3J+CsdE8K FRxg== Received: by 10.50.154.227 with SMTP id vr3mr1507490igb.43.1348134375788; Thu, 20 Sep 2012 02:46:15 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp65939igc; Thu, 20 Sep 2012 02:46:14 -0700 (PDT) Received: by 10.14.204.72 with SMTP id g48mr1425557eeo.45.1348134374235; Thu, 20 Sep 2012 02:46:14 -0700 (PDT) Received: from eu1sys200aog110.obsmtp.com (eu1sys200aog110.obsmtp.com [207.126.144.129]) by mx.google.com with SMTP id a1si3360553eep.28.2012.09.20.02.46.05 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Sep 2012 02:46:14 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.129 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.129; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.129 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob110.postini.com ([207.126.147.11]) with SMTP ID DSNKUFrl3Bd8TT8WyWLbJG9VbLXOU1wUo0M1@postini.com; Thu, 20 Sep 2012 09:46:13 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C0098307; Thu, 20 Sep 2012 09:45:56 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 69BF52767; Thu, 20 Sep 2012 09:45:56 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id A05DA24C2FA; Thu, 20 Sep 2012 11:45:50 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Thu, 20 Sep 2012 11:45:55 +0200 From: Linus Walleij To: , Greg Kroah-Hartman Cc: , Anmar Oueja , Linus Walleij , Par-Gunnar Hjalmdahl , Guillaume Jaunet , Christophe Arnal , Matthias Locher , Rajanikanth H.V Subject: [PATCH 1/3] serial: pl011: safeguard against impossible baudrates Date: Thu, 20 Sep 2012 11:45:46 +0200 Message-ID: <1348134346-25593-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.11.3 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQnHWvA/+1FZydnTe/rTDqD7CQMrc1DTWLzndTwMoHsRNB5d/gAIvDME7OimvuHv1TkQcePA From: Linus Walleij The PL011 generates it's bitrate from the clock to the block, and this in turn will be divided by a minimum of 16 (ARM PL011) or 8 (ST Micro PL011 derivate). Safeguard against illegal rates exceeding that of what the port clock can be divided down to. Since the clkdiv variable is only ever used for calculating the maximum baud rate, let's skip that variable and add a new max_baud variable instead, then use this to check limits and as parameter for getting the baud rate. Cc: Par-Gunnar Hjalmdahl Cc: Guillaume Jaunet Cc: Christophe Arnal Cc: Matthias Locher Cc: Rajanikanth H.V Signed-off-by: Linus Walleij --- drivers/tty/serial/amba-pl011.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index d626d84..9e16ea6 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -1492,18 +1492,25 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios, struct uart_amba_port *uap = (struct uart_amba_port *)port; unsigned int lcr_h, old_cr; unsigned long flags; - unsigned int baud, quot, clkdiv; + unsigned int max_baud, baud, quot; if (uap->vendor->oversampling) - clkdiv = 8; + max_baud = port->uartclk / 8; else - clkdiv = 16; + max_baud = port->uartclk / 16; + + if ((termios->c_ispeed > max_baud) || + (termios->c_ospeed > max_baud)) { + dev_err(port->dev, + "requested a baud rate > clock/mindivisor\n"); + return; + } /* * Ask the core to calculate the divisor for us. */ baud = uart_get_baud_rate(port, termios, old, 0, - port->uartclk / clkdiv); + max_baud); if (baud > port->uartclk/16) quot = DIV_ROUND_CLOSEST(port->uartclk * 8, baud);