From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DA6CC4167B for ; Fri, 8 Dec 2023 06:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233121AbjLHGsE (ORCPT ); Fri, 8 Dec 2023 01:48:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjLHGsB (ORCPT ); Fri, 8 Dec 2023 01:48:01 -0500 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30DBF1727 for ; Thu, 7 Dec 2023 22:48:07 -0800 (PST) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id EA2A4240104 for ; Fri, 8 Dec 2023 07:48:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1702018084; bh=XHW0wpRIcKcG33IpWEqGDMS0yycm1FN2SxUGJcODXsQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=jxfxlJoqiQRkZnHGhAiJ2yyjS1igfIsmI0OA1KmF3SBRlAtwMtkS4qIBLJ3U4m56E 5vZ4q1zJ0Tcl1E5db5wo/e1uMOFdA75YpqsGuFVaA2vBmfs2M2JhjFC4lQjJlm+tvu SbjAaBS3BmnfVBFxiEQsN3ZxebaZoYt70MSpWyND+4Nko70ToSHWXajREL2j1/xPl1 SgCtvMBx5th8+Rq7sJfPUjw500Gj7pDfypiDqqeIn7AyW+TeuwZsGoaIjHt26Xlwoy uyjXc+nLQOIEkNY76yfhDPnPfm60GVOGRFyXpNW5E1lttpgCrqmllGa6i8DyAva4CJ 8fFQN8UAC4wPQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4SmhXy6Zfqz6tvc; Fri, 8 Dec 2023 07:48:02 +0100 (CET) Date: Fri, 8 Dec 2023 06:48:02 +0000 From: Wilken Gottwalt To: Armin Wolf Cc: jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] hwmon: (corsair-psu) Fix probe when built-in Message-ID: <20231208074802.56bb2d78@posteo.net> In-Reply-To: <20231207210723.222552-1-W_Armin@gmx.de> References: <20231207210723.222552-1-W_Armin@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 Dec 2023 22:07:23 +0100 Armin Wolf wrote: > It seems that when the driver is built-in, the HID bus is > initialized after the driver is loaded, which whould cause > module_hid_driver() to fail. > Fix this by registering the driver after the HID bus using > late_initcall() in accordance with other hwmon HID drivers. > > Compile-tested only. So you did not test this? Well, I did. [ 2.225831] Driver 'corsair-psu' was unable to register with bus_type 'hid' because the bus was not initialized. [ 2.225835] amd_pstate: driver load is disabled, boot with specific mode to enable this [ 2.226363] ledtrig-cpu: registered to indicate activity on CPUs [ 2.226679] hid: raw HID events driver (C) Jiri Kosina You are right, it is a timing issue and this can actually happen. I'm fine with the fix. Though, this could even be a bigger issue. There are currently 104 HID drivers using the module_hid_driver macro. Maybe it would be a better idea to change the module_hid_driver macro to use the lateinit calls instead of the plain init/exit calls. greetings, Will > Signed-off-by: Armin Wolf > --- > drivers/hwmon/corsair-psu.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c > index 904890598c11..2c7c92272fe3 100644 > --- a/drivers/hwmon/corsair-psu.c > +++ b/drivers/hwmon/corsair-psu.c > @@ -899,7 +899,23 @@ static struct hid_driver corsairpsu_driver = { > .reset_resume = corsairpsu_resume, > #endif > }; > -module_hid_driver(corsairpsu_driver); > + > +static int __init corsair_init(void) > +{ > + return hid_register_driver(&corsairpsu_driver); > +} > + > +static void __exit corsair_exit(void) > +{ > + hid_unregister_driver(&corsairpsu_driver); > +} > + > +/* > + * With module_init() the driver would load before the HID bus when > + * built-in, so use late_initcall() instead. > + */ > +late_initcall(corsair_init); > +module_exit(corsair_exit); > > MODULE_LICENSE("GPL"); > MODULE_AUTHOR("Wilken Gottwalt "); > -- > 2.39.2 >