Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp977340rwd; Thu, 1 Jun 2023 08:55:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KSsiq6FW51QIwmCb5b69efsWfnil6ZSVdfdTSvjg7bcQrGnCWp2t06VnVBt+M5H4Y/LpY X-Received: by 2002:a05:6a20:6f03:b0:103:d538:5ea6 with SMTP id gt3-20020a056a206f0300b00103d5385ea6mr6764020pzb.48.1685634924211; Thu, 01 Jun 2023 08:55:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685634924; cv=none; d=google.com; s=arc-20160816; b=vIGffWGr7V7iAKUn4IgIB2VXzW4vM0dUMfwK83N7Xuy2K0TabhvhRgYdxq0Dd+3Pfs CEwbzjjXFq4qJcHD5ZlPcZx6BJYFMgbbQVuGr7fDqLdr9Y9bvHVRttBXMZYDwbQxEs1E +Gp2g7ALxCiEPmaW10h9rfAbjt3QhqaAD+Wrt/86Vo3N26CsvO8Nhzo6s1vVcbWuMNLH ebBVZ/J4Vdx9LkDONFvYltOSdU4RURXFW5f64SJupRQkLYHdND7n+Xhmi+Y+1yHW50AB dEDkwgj6/73GzPOlaNuMuaytpov/4DPXapMZgggGCGY1GtQWe8vxzOWoYgak9wxwV3JX IFGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=fkeuRrr/pk3RKVYyPQ8Qly+2m40foZ7jMqqvQEI+utY=; b=mUPjnHUDUNbbXybJ7hRrPQRONFDzG0d/JmTOkQrR/o87oJCTZJYRVh8sNUTCiuL/ai d7H2X0l7mg/5LCfMj8zn+FYyXY/eiQmuhmzYjL3k9bkJ8UhCAEzUHrVTKctNXFF+ATFe ejGlL5E7o1esJbBcqN0Ux9zbqzW+GuUMcbCAL3rFx1Li/tauqpaw0uI4R0m4N9wfPjw0 xh/UdZjsRrkjFlqq+NXwEq+kJKROEg4wRY0oPJQ6k8hDpybh0yAziOjv696vP4FdPETu Rk0EuVvrUqo7C93SwVKV5Uuc97p7u4VUMAgkdy8JS6YFPFuzrsr65F7O2t6UkcJo+KbJ muVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a62-20020a639041000000b0051b9a71329fsi202456pge.360.2023.06.01.08.55.09; Thu, 01 Jun 2023 08:55:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234072AbjFAPq0 (ORCPT + 99 others); Thu, 1 Jun 2023 11:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233873AbjFAPqV (ORCPT ); Thu, 1 Jun 2023 11:46:21 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C1434FB; Thu, 1 Jun 2023 08:46:14 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTPS id 0DBA480F1; Thu, 1 Jun 2023 15:46:14 +0000 (UTC) Date: Thu, 1 Jun 2023 18:46:12 +0300 From: Tony Lindgren To: Marek Szyprowski Cc: Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko , Andy Shevchenko , Dhruva Gole , Ilpo =?utf-8?B?SsOkcnZpbmVu?= , John Ogness , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-omap@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] serial: core: Fix probing serial_base_bus devices Message-ID: <20230601154612.GE14287@atomide.com> References: <20230601141445.11321-1-tony@atomide.com> <2023060112-onion-disparate-8ce8@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Marek Szyprowski [230601 15:09]: > On 01.06.2023 16:21, Greg Kroah-Hartman wrote: > > On Thu, Jun 01, 2023 at 05:14:44PM +0300, Tony Lindgren wrote: > >> If a physical serial port device driver uses arch_initcall() we fail to > >> probe the serial_base_bus devices and the serial port tx fails. This is > >> because as serial_base_bus uses module_initcall(). > >> > >> Let's fix the issue by changing serial_base_bus to use arch_initcall(). > > This will only work if the linking order is such that this will always > > come before the drivers. Is that the case here? > > Yes, serial_base_bus is linked as a second object, just after the > serial_core. Device drivers come later. If we don't want to rely on the Makefile order here, we could do something like the patch below. Regards, Tony 8< --------------------- diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -11,12 +11,18 @@ #include #include #include +#include #include #include #include #include "serial_base.h" +static bool serial_base_initialized; +static DEFINE_MUTEX(serial_base_lock); + +static int serial_base_init(void); + static int serial_base_match(struct device *dev, struct device_driver *drv) { int len = strlen(drv->name); @@ -48,6 +54,12 @@ static int serial_base_device_init(struct uart_port *port, void (*release)(struct device *dev), int id) { + /* + * Initialize bus if not yet initialized. Some drivers are using + * arch_initcall() + */ + serial_base_init(); + device_initialize(dev); dev->type = type; dev->parent = parent_dev; @@ -163,6 +175,14 @@ static int serial_base_init(void) { int ret; + mutex_lock(&serial_base_lock); + + /* Also called from serial_base_device_init() in some cases */ + if (serial_base_initialized) { + ret = 0; + goto out_unlock; + } + ret = bus_register(&serial_base_bus_type); if (ret) return ret; @@ -175,6 +195,10 @@ static int serial_base_init(void) if (ret) goto err_ctrl_exit; + serial_base_initialized = true; + + mutex_unlock(&serial_base_lock); + return 0; err_ctrl_exit: @@ -183,15 +207,21 @@ static int serial_base_init(void) err_bus_unregister: bus_unregister(&serial_base_bus_type); +out_unlock: + mutex_unlock(&serial_base_lock); + return ret; } module_init(serial_base_init); static void serial_base_exit(void) { + mutex_lock(&serial_base_lock); serial_base_port_exit(); serial_base_ctrl_exit(); bus_unregister(&serial_base_bus_type); + serial_base_initialized = false; + mutex_unlock(&serial_base_lock); } module_exit(serial_base_exit); -- 2.40.1