From patchwork Tue May 31 08:59:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yegor Yefremov X-Patchwork-Id: 9143831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D68460757 for ; Tue, 31 May 2016 08:59:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 625AB28187 for ; Tue, 31 May 2016 08:59:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 573FC28223; Tue, 31 May 2016 08:59:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE81628187 for ; Tue, 31 May 2016 08:59:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756888AbcEaI7n (ORCPT ); Tue, 31 May 2016 04:59:43 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35930 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756476AbcEaI7i (ORCPT ); Tue, 31 May 2016 04:59:38 -0400 Received: by mail-wm0-f68.google.com with SMTP id q62so30470131wmg.3; Tue, 31 May 2016 01:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4QjNNUPvIZwXegMveN08jD2ftZZLO/OKcA01/FmrdZU=; b=LpD6SfER4/PbGpCDyqeP2bRjLEByyLb62WY3WiTM6Es0PPorzJpQYHiU91cBcSreaC x1fb1ZFTr1oOKyOLMZy8t045foTZe4EtAslabYnlZjctUb0TH8XaVIx0JEzLcRvQfMIk 3AWKDEilUcHTVdvKLv6L1lNeYPTFy2e5pxvxyshXpWWD0PdeDMCV8r5oYaw1r2FaZmCj n3kUfe6gQ5xfCtA1vpgASKoXZj5qnMHYSxkd59B9zdrNeoNy3Htj+MmV1D8SM3mz/MhG eKqkktsKMDUHi/zjZCZU3f8FYSkODNGtq/weocoMqBHXr0BBZ+IPvcdYkJh9EWPqmkPi 26Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4QjNNUPvIZwXegMveN08jD2ftZZLO/OKcA01/FmrdZU=; b=H2f8ExPnj04I/CgiDsosGKE5h7CLdVSnhOkZ48B9ZrgV6kHh7u3zhwTaxUkDF7LGWI 6/uBC82OctdP5QRDWk0c02y7D/xnGuHL12EUwlc1F/I4kBcr5Jmp4ToeVSbtNOj7WJRJ 5B8WgVHikq6Mjfm99lQn2Ce2LeaRciFA/JEg7d38c2OXbwip0c77cXYrs5Fwmb7hgjT3 bG8yvAKY/RpowwLj6te4Mmpu4NHtVKu+esEL+mcpaTi0d4gKuFhvo8PJGaOuUEPT6mJe kedzziHt4quPIXbbb9yXgJRxbwwkLH2BEJgnomZwu8pHmqBrDMzxu93iSzt6uNfh1pgi 2Jsw== X-Gm-Message-State: ALyK8tJT420TeE+1XHUALdJJ2IWVTPFUmkfuyVD3kVOntd5gzaiTZpGuu2zOYVoDN1oMvg== X-Received: by 10.194.112.6 with SMTP id im6mr35085093wjb.48.1464685177168; Tue, 31 May 2016 01:59:37 -0700 (PDT) Received: from development1.visionsystems.de (mail.visionsystems.de. [213.209.99.202]) by smtp.gmail.com with ESMTPSA id w123sm27902335wmw.0.2016.05.31.01.59.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 May 2016 01:59:36 -0700 (PDT) From: yegorslists@googlemail.com To: linux-serial@vger.kernel.org Cc: linux-omap@vger.kernel.org, gregkh@linuxfoundation.org, u.kleine-koenig@pengutronix.de, peter@hurleysoftware.com, Yegor Yefremov Subject: [PATCH v5 3/4] serial: mctrl_gpio: enable API usage only for initialized mctrl_gpios struct Date: Tue, 31 May 2016 10:59:17 +0200 Message-Id: <1464685158-17389-4-git-send-email-yegorslists@googlemail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464685158-17389-1-git-send-email-yegorslists@googlemail.com> References: <1464685158-17389-1-git-send-email-yegorslists@googlemail.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yegor Yefremov This workaround is needed for the cases, where mctrl_gpio API is used before mctrl_gpio_init() was invoked. This happens in 8250 during console initialization, as the driver sets DTR signal. Signed-off-by: Yegor Yefremov --- Changes: v5: revert changes concerning mctrl_gpio_init return value drivers/tty/serial/serial_mctrl_gpio.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c index a868595..d2da6aa 100644 --- a/drivers/tty/serial/serial_mctrl_gpio.c +++ b/drivers/tty/serial/serial_mctrl_gpio.c @@ -52,6 +52,9 @@ void mctrl_gpio_set(struct mctrl_gpios *gpios, unsigned int mctrl) int value_array[UART_GPIO_MAX]; unsigned int count = 0; + if (gpios == NULL) + return; + for (i = 0; i < UART_GPIO_MAX; i++) if (gpios->gpio[i] && mctrl_gpios_desc[i].dir_out) { desc_array[count] = gpios->gpio[i]; @@ -73,6 +76,9 @@ unsigned int mctrl_gpio_get(struct mctrl_gpios *gpios, unsigned int *mctrl) { enum mctrl_gpio_idx i; + if (gpios == NULL) + return *mctrl; + for (i = 0; i < UART_GPIO_MAX; i++) { if (gpios->gpio[i] && !mctrl_gpios_desc[i].dir_out) { if (gpiod_get_value(gpios->gpio[i])) @@ -91,6 +97,9 @@ mctrl_gpio_get_outputs(struct mctrl_gpios *gpios, unsigned int *mctrl) { enum mctrl_gpio_idx i; + if (gpios == NULL) + return *mctrl; + for (i = 0; i < UART_GPIO_MAX; i++) { if (gpios->gpio[i] && mctrl_gpios_desc[i].dir_out) { if (gpiod_get_value(gpios->gpio[i])) @@ -221,6 +230,9 @@ void mctrl_gpio_free(struct device *dev, struct mctrl_gpios *gpios) { enum mctrl_gpio_idx i; + if (gpios == NULL) + return; + for (i = 0; i < UART_GPIO_MAX; i++) { if (gpios->irq[i]) devm_free_irq(gpios->port->dev, gpios->irq[i], gpios); @@ -236,6 +248,9 @@ void mctrl_gpio_enable_ms(struct mctrl_gpios *gpios) { enum mctrl_gpio_idx i; + if (gpios == NULL) + return; + /* .enable_ms may be called multiple times */ if (gpios->mctrl_on) return; @@ -258,6 +273,9 @@ void mctrl_gpio_disable_ms(struct mctrl_gpios *gpios) { enum mctrl_gpio_idx i; + if (gpios == NULL) + return; + if (!gpios->mctrl_on) return;