From patchwork Thu Apr 20 12:13:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sjoerd Simons X-Patchwork-Id: 97798 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp697948obc; Thu, 20 Apr 2017 05:13:13 -0700 (PDT) X-Received: by 10.98.193.65 with SMTP id i62mr7687990pfg.149.1492690393611; Thu, 20 Apr 2017 05:13:13 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si6281436pld.316.2017.04.20.05.13.13; Thu, 20 Apr 2017 05:13:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030622AbdDTMNM (ORCPT + 3 others); Thu, 20 Apr 2017 08:13:12 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33767 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970108AbdDTMNJ (ORCPT ); Thu, 20 Apr 2017 08:13:09 -0400 Received: from dawn.luon.net (unknown [IPv6:2001:1af8:fe00:8421:84eb:4143:10ee:73da]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sjoerd) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 07C96261427; Thu, 20 Apr 2017 13:13:08 +0100 (BST) Received: by dawn.luon.net (Postfix, from userid 1000) id 9BAA62FA4E8F; Thu, 20 Apr 2017 14:13:04 +0200 (CEST) From: Sjoerd Simons To: linux-serial@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH v2 2/2] serial: sh-sci: Move uart_register_driver call to device probe Date: Thu, 20 Apr 2017 14:13:01 +0200 Message-Id: <20170420121301.382-3-sjoerd.simons@collabora.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170420121301.382-1-sjoerd.simons@collabora.co.uk> References: <20170420121301.382-1-sjoerd.simons@collabora.co.uk> Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org uart_register_driver call binds the driver to a specific device node through tty_register_driver call. This should typically happen during device probe call. In a multiplatform scenario, it is possible that multiple serial drivers are part of the kernel. Currently the driver registration fails if multiple serial drivers with overlapping major/minor numbers are included. Signed-off-by: Sjoerd Simons --- Changes in v2: - Add locking to prevent issues when two probes run in parallel drivers/tty/serial/sh-sci.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 9a47cc4f16a2..f23254add9a7 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2935,6 +2935,7 @@ static inline int sci_probe_earlyprintk(struct platform_device *pdev) static const char banner[] __initconst = "SuperH (H)SCI(F) driver initialized"; +static DEFINE_MUTEX(sci_uart_registration_lock); static struct uart_driver sci_uart_driver = { .owner = THIS_MODULE, .driver_name = "sci", @@ -3063,6 +3064,16 @@ static int sci_probe_single(struct platform_device *dev, return -EINVAL; } + mutex_lock(&sci_uart_registration_lock); + if (!sci_uart_driver.state) { + ret = uart_register_driver(&sci_uart_driver); + if (ret) { + mutex_unlock(&sci_uart_registration_lock); + return ret; + } + } + mutex_unlock(&sci_uart_registration_lock); + ret = sci_init_single(dev, sciport, index, p, false); if (ret) return ret; @@ -3186,24 +3197,17 @@ static struct platform_driver sci_driver = { static int __init sci_init(void) { - int ret; - pr_info("%s\n", banner); - ret = uart_register_driver(&sci_uart_driver); - if (likely(ret == 0)) { - ret = platform_driver_register(&sci_driver); - if (unlikely(ret)) - uart_unregister_driver(&sci_uart_driver); - } - - return ret; + return platform_driver_register(&sci_driver); } static void __exit sci_exit(void) { platform_driver_unregister(&sci_driver); - uart_unregister_driver(&sci_uart_driver); + + if (sci_uart_driver.state) + uart_unregister_driver(&sci_uart_driver); } #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE