From patchwork Mon May 23 07:30:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yegor Yefremov X-Patchwork-Id: 9131271 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 59E59607D3 for ; Mon, 23 May 2016 07:32:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5005E2820E for ; Mon, 23 May 2016 07:32:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4513328218; Mon, 23 May 2016 07:32:55 +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 D8C4D2820E for ; Mon, 23 May 2016 07:32:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932147AbcEWHcy (ORCPT ); Mon, 23 May 2016 03:32:54 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33988 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753457AbcEWHcx (ORCPT ); Mon, 23 May 2016 03:32:53 -0400 Received: by mail-wm0-f67.google.com with SMTP id n129so12304922wmn.1; Mon, 23 May 2016 00:32:52 -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=4f1L+m6I1VRGYKhXmNVV6g/zCNypep82cR4OCDDhWA4=; b=vTgdBmNnF2eaIpBimkzI77pn3aWP4zSlGkV54tTIMg4EjMrVsb9+cpUXzeqOOalv2+ yYtZnDfeo34ZqTUQoqqbNi1q+an0PxqdYKi5xh9VqNkNEoBmqpDChSdtOEnpQbTiQH3+ 4A2u5c7c2sJAkKGfoa3+fGexlhzqwsGEOZo5ZU4uChPJn3hPiD1Nyp1R40Upn8paIQmZ RX2ZYJ6yFzoBqjsOIxDSJ6iGnGIUIRfyEKLLt7+U2Mpl0388BDQ7VJPPoyIIlHioGf9u mI4nmo8BsogLuulAhvSlvd/L+kCJRl110EoWHRZfycjF6OGxysGuYnK9fZ1oE4eTSpjW uDJQ== 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=4f1L+m6I1VRGYKhXmNVV6g/zCNypep82cR4OCDDhWA4=; b=aBzyYUCS7Ueggj30QncMfTAg/k59/0RvQLwyiU31TMMD6yXCPoeL2r3VL2f3Rmp5Bz J4gW9feSJwvRzm1c6Dx+rWvyyMPYIFbNTqNJYjV+hoS6yv/iFeF2nqE2Y7QjupkYzepm j+LLz07oTvk3tmRyptEGLA8MTXt6OxDnQNXXiYcIV5+rK4KsHh6RlrarFxGJB33+kd9K ndgzhyXX0BGOPKqUCevXIjneMd0gR79GVMDNwIM/LcqxQ0jyDFVegfugPhQdzuF7uWo5 GY16BJbL5K4pPcv39Xr6eaJSQfVsFgYf0+QVNEyiQ4Aqm7YdpaYe+lUhFX3iQN8EJVyD P0yg== X-Gm-Message-State: AOPr4FVNK61wTdI6iX0v1VqHGYfVp1XPSBafPbc6cHgvRZvdVvSH+s6M2MF9b+5yWSVFdg== X-Received: by 10.28.8.193 with SMTP id 184mr16370500wmi.56.1463988771986; Mon, 23 May 2016 00:32:51 -0700 (PDT) Received: from development1.visionsystems.de (mail.visionsystems.de. [213.209.99.202]) by smtp.gmail.com with ESMTPSA id o76sm10399991wme.0.2016.05.23.00.32.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 May 2016 00:32:51 -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 v4 3/4] serial: mctrl_gpio: enable API usage only for initialized mctrl_gpios struct Date: Mon, 23 May 2016 09:30:57 +0200 Message-Id: <1463988658-9183-4-git-send-email-yegorslists@googlemail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1463988658-9183-1-git-send-email-yegorslists@googlemail.com> References: <1463988658-9183-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. Return NULL in case of initialization errors or absence of GPIOLIB. This way the above workaround can be safely used. Signed-off-by: Yegor Yefremov --- drivers/tty/serial/serial_mctrl_gpio.c | 24 +++++++++++++++++++++--- drivers/tty/serial/serial_mctrl_gpio.h | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c index a868595..35588c5 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])) @@ -178,7 +187,7 @@ struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx) gpios = mctrl_gpio_init_noauto(port->dev, idx); if (IS_ERR(gpios)) - return gpios; + return NULL; gpios->port = port; @@ -193,7 +202,7 @@ struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx) dev_err(port->dev, "failed to find corresponding irq for %s (idx=%d, err=%d)\n", mctrl_gpios_desc[i].name, idx, ret); - return ERR_PTR(ret); + return NULL; } gpios->irq[i] = ret; @@ -209,7 +218,7 @@ struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx) dev_err(port->dev, "failed to request irq for %s (idx=%d, err=%d)\n", mctrl_gpios_desc[i].name, idx, ret); - return ERR_PTR(ret); + return NULL; } } @@ -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; diff --git a/drivers/tty/serial/serial_mctrl_gpio.h b/drivers/tty/serial/serial_mctrl_gpio.h index fa000bc..82c5fbf 100644 --- a/drivers/tty/serial/serial_mctrl_gpio.h +++ b/drivers/tty/serial/serial_mctrl_gpio.h @@ -130,7 +130,7 @@ struct gpio_desc *mctrl_gpio_to_gpiod(struct mctrl_gpios *gpios, static inline struct mctrl_gpios *mctrl_gpio_init(struct uart_port *port, unsigned int idx) { - return ERR_PTR(-ENOSYS); + return NULL; } static inline