public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: (corsair-psu) Fix failure to load when built-in to kernel
@ 2023-12-08 13:07 Aleksa Savic
  2023-12-08 13:11 ` Aleksa Savic
  0 siblings, 1 reply; 6+ messages in thread
From: Aleksa Savic @ 2023-12-08 13:07 UTC (permalink / raw)
  To: linux-hwmon
  Cc: Aleksa Savic, Wilken Gottwalt, Jean Delvare, Guenter Roeck,
	linux-kernel

When built-in to the kernel, the corsair-psu driver fails to register with
the following message:

"Driver 'corsair-psu' was unable to register with bus_type 'hid'
because the bus was not initialized."

Fix this by initializing the driver after the HID bus using
late_initcall(), as hwmon is built before HID.

Fixes: d115b51e0e56 ("hwmon: add Corsair PSU HID controller driver")
Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
---
 drivers/hwmon/corsair-psu.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
index 904890598c11..48831a528965 100644
--- a/drivers/hwmon/corsair-psu.c
+++ b/drivers/hwmon/corsair-psu.c
@@ -899,7 +899,20 @@ static struct hid_driver corsairpsu_driver = {
 	.reset_resume	= corsairpsu_resume,
 #endif
 };
-module_hid_driver(corsairpsu_driver);
+
+static int __init corsairpsu_hid_init(void)
+{
+	return hid_register_driver(&corsairpsu_driver);
+}
+
+static void __exit corsairpsu_hid_exit(void)
+{
+	hid_unregister_driver(&corsairpsu_driver);
+}
+
+/* When compiled into the kernel, initialize after the hid bus */
+late_initcall(corsairpsu_hid_init);
+module_exit(corsairpsu_hid_exit);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Wilken Gottwalt <wilken.gottwalt@posteo.net>");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (corsair-psu) Fix failure to load when built-in to kernel
  2023-12-08 13:07 [PATCH] hwmon: (corsair-psu) Fix failure to load when built-in to kernel Aleksa Savic
@ 2023-12-08 13:11 ` Aleksa Savic
  2023-12-08 13:57   ` Wilken Gottwalt
  0 siblings, 1 reply; 6+ messages in thread
From: Aleksa Savic @ 2023-12-08 13:11 UTC (permalink / raw)
  To: linux-hwmon
  Cc: savicaleksa83, Wilken Gottwalt, Jean Delvare, Guenter Roeck,
	linux-kernel

On 2023-12-08 14:07:10 GMT+01:00, Aleksa Savic wrote:
> When built-in to the kernel, the corsair-psu driver fails to register with
> the following message:
> 
> "Driver 'corsair-psu' was unable to register with bus_type 'hid'
> because the bus was not initialized."
> 
> Fix this by initializing the driver after the HID bus using
> late_initcall(), as hwmon is built before HID.
> 
> Fixes: d115b51e0e56 ("hwmon: add Corsair PSU HID controller driver")
> Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
> ---
>  drivers/hwmon/corsair-psu.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
> index 904890598c11..48831a528965 100644
> --- a/drivers/hwmon/corsair-psu.c
> +++ b/drivers/hwmon/corsair-psu.c
> @@ -899,7 +899,20 @@ static struct hid_driver corsairpsu_driver = {
>  	.reset_resume	= corsairpsu_resume,
>  #endif
>  };
> -module_hid_driver(corsairpsu_driver);
> +
> +static int __init corsairpsu_hid_init(void)
> +{
> +	return hid_register_driver(&corsairpsu_driver);
> +}
> +
> +static void __exit corsairpsu_hid_exit(void)
> +{
> +	hid_unregister_driver(&corsairpsu_driver);
> +}
> +
> +/* When compiled into the kernel, initialize after the hid bus */
> +late_initcall(corsairpsu_hid_init);
> +module_exit(corsairpsu_hid_exit);
>  
>  MODULE_LICENSE("GPL");
>  MODULE_AUTHOR("Wilken Gottwalt <wilken.gottwalt@posteo.net>");


Woops! Just saw that the same fix was sent yesterday. Please disregard, sorry!

Aleksa

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (corsair-psu) Fix failure to load when built-in to kernel
  2023-12-08 13:11 ` Aleksa Savic
@ 2023-12-08 13:57   ` Wilken Gottwalt
  2023-12-08 15:43     ` Guenter Roeck
  0 siblings, 1 reply; 6+ messages in thread
From: Wilken Gottwalt @ 2023-12-08 13:57 UTC (permalink / raw)
  To: Aleksa Savic; +Cc: linux-hwmon, Jean Delvare, Guenter Roeck, linux-kernel

On Fri, 8 Dec 2023 14:11:44 +0100
Aleksa Savic <savicaleksa83@gmail.com> wrote:

> On 2023-12-08 14:07:10 GMT+01:00, Aleksa Savic wrote:
> > When built-in to the kernel, the corsair-psu driver fails to register with
> > the following message:
> > 
> > "Driver 'corsair-psu' was unable to register with bus_type 'hid'
> > because the bus was not initialized."
> > 
> > Fix this by initializing the driver after the HID bus using
> > late_initcall(), as hwmon is built before HID.
> > 
> > Fixes: d115b51e0e56 ("hwmon: add Corsair PSU HID controller driver")
> > Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
> > ---
> >  drivers/hwmon/corsair-psu.c | 15 ++++++++++++++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
> > index 904890598c11..48831a528965 100644
> > --- a/drivers/hwmon/corsair-psu.c
> > +++ b/drivers/hwmon/corsair-psu.c
> > @@ -899,7 +899,20 @@ static struct hid_driver corsairpsu_driver = {
> >  	.reset_resume	= corsairpsu_resume,
> >  #endif
> >  };
> > -module_hid_driver(corsairpsu_driver);
> > +
> > +static int __init corsairpsu_hid_init(void)
> > +{
> > +	return hid_register_driver(&corsairpsu_driver);
> > +}
> > +
> > +static void __exit corsairpsu_hid_exit(void)
> > +{
> > +	hid_unregister_driver(&corsairpsu_driver);
> > +}
> > +
> > +/* When compiled into the kernel, initialize after the hid bus */
> > +late_initcall(corsairpsu_hid_init);
> > +module_exit(corsairpsu_hid_exit);
> >  
> >  MODULE_LICENSE("GPL");
> >  MODULE_AUTHOR("Wilken Gottwalt <wilken.gottwalt@posteo.net>");
> 
> 
> Woops! Just saw that the same fix was sent yesterday. Please disregard, sorry!
>
> Aleksa

It is fine. I just start to wonder if there was a change in the subsystem. I
used the driver as built-in in the past for several months and never had that
issue. And now it is a real flood of reports.

greetings,
Will

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (corsair-psu) Fix failure to load when built-in to kernel
  2023-12-08 13:57   ` Wilken Gottwalt
@ 2023-12-08 15:43     ` Guenter Roeck
  2023-12-08 16:52       ` Aleksa Savic
  0 siblings, 1 reply; 6+ messages in thread
From: Guenter Roeck @ 2023-12-08 15:43 UTC (permalink / raw)
  To: Wilken Gottwalt, Aleksa Savic
  Cc: linux-hwmon, Jean Delvare, linux-kernel, linux-input, Jiri Kosina,
	Benjamin Tissoires

On 12/8/23 05:57, Wilken Gottwalt wrote:
> On Fri, 8 Dec 2023 14:11:44 +0100
> Aleksa Savic <savicaleksa83@gmail.com> wrote:
> 
>> On 2023-12-08 14:07:10 GMT+01:00, Aleksa Savic wrote:
>>> When built-in to the kernel, the corsair-psu driver fails to register with
>>> the following message:
>>>
>>> "Driver 'corsair-psu' was unable to register with bus_type 'hid'
>>> because the bus was not initialized."
>>>
>>> Fix this by initializing the driver after the HID bus using
>>> late_initcall(), as hwmon is built before HID.
>>>
>>> Fixes: d115b51e0e56 ("hwmon: add Corsair PSU HID controller driver")
>>> Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
>>> ---
>>>   drivers/hwmon/corsair-psu.c | 15 ++++++++++++++-
>>>   1 file changed, 14 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
>>> index 904890598c11..48831a528965 100644
>>> --- a/drivers/hwmon/corsair-psu.c
>>> +++ b/drivers/hwmon/corsair-psu.c
>>> @@ -899,7 +899,20 @@ static struct hid_driver corsairpsu_driver = {
>>>   	.reset_resume	= corsairpsu_resume,
>>>   #endif
>>>   };
>>> -module_hid_driver(corsairpsu_driver);
>>> +
>>> +static int __init corsairpsu_hid_init(void)
>>> +{
>>> +	return hid_register_driver(&corsairpsu_driver);
>>> +}
>>> +
>>> +static void __exit corsairpsu_hid_exit(void)
>>> +{
>>> +	hid_unregister_driver(&corsairpsu_driver);
>>> +}
>>> +
>>> +/* When compiled into the kernel, initialize after the hid bus */
>>> +late_initcall(corsairpsu_hid_init);
>>> +module_exit(corsairpsu_hid_exit);
>>>   
>>>   MODULE_LICENSE("GPL");
>>>   MODULE_AUTHOR("Wilken Gottwalt <wilken.gottwalt@posteo.net>");
>>
>>
>> Woops! Just saw that the same fix was sent yesterday. Please disregard, sorry!
>>
>> Aleksa
> 
> It is fine. I just start to wonder if there was a change in the subsystem. I
> used the driver as built-in in the past for several months and never had that
> issue. And now it is a real flood of reports.
> 

Maybe there was a change in the build order, or some subtle change
in driver registration code. Question though is _when_ this changed.
It would be great if someone could bisect it. For example, bus registration
code has been changed significantly in v6.3. I am copying linux-input
and the hid maintainers for feedback.

Either case, I now have two patches and at least the first one was actually
tested, but no Reviewed-by: or Tested-by: for either of them. While that is
of course a formality, it would still be useful to show that it is not just
a random change.

Thanks,
Guenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (corsair-psu) Fix failure to load when built-in to kernel
  2023-12-08 15:43     ` Guenter Roeck
@ 2023-12-08 16:52       ` Aleksa Savic
  2023-12-08 18:34         ` Guenter Roeck
  0 siblings, 1 reply; 6+ messages in thread
From: Aleksa Savic @ 2023-12-08 16:52 UTC (permalink / raw)
  To: Guenter Roeck, Wilken Gottwalt
  Cc: savicaleksa83, linux-hwmon, Jean Delvare, linux-kernel,
	linux-input, Jiri Kosina, Benjamin Tissoires

On 2023-12-08 16:43:07 GMT+01:00, Guenter Roeck wrote:
> On 12/8/23 05:57, Wilken Gottwalt wrote:
>> On Fri, 8 Dec 2023 14:11:44 +0100
>> Aleksa Savic <savicaleksa83@gmail.com> wrote:
>>
>>> On 2023-12-08 14:07:10 GMT+01:00, Aleksa Savic wrote:
>>>> When built-in to the kernel, the corsair-psu driver fails to register with
>>>> the following message:
>>>>
>>>> "Driver 'corsair-psu' was unable to register with bus_type 'hid'
>>>> because the bus was not initialized."
>>>>
>>>> Fix this by initializing the driver after the HID bus using
>>>> late_initcall(), as hwmon is built before HID.
>>>>
>>>> Fixes: d115b51e0e56 ("hwmon: add Corsair PSU HID controller driver")
>>>> Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
>>>> ---
>>>>   drivers/hwmon/corsair-psu.c | 15 ++++++++++++++-
>>>>   1 file changed, 14 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
>>>> index 904890598c11..48831a528965 100644
>>>> --- a/drivers/hwmon/corsair-psu.c
>>>> +++ b/drivers/hwmon/corsair-psu.c
>>>> @@ -899,7 +899,20 @@ static struct hid_driver corsairpsu_driver = {
>>>>       .reset_resume    = corsairpsu_resume,
>>>>   #endif
>>>>   };
>>>> -module_hid_driver(corsairpsu_driver);
>>>> +
>>>> +static int __init corsairpsu_hid_init(void)
>>>> +{
>>>> +    return hid_register_driver(&corsairpsu_driver);
>>>> +}
>>>> +
>>>> +static void __exit corsairpsu_hid_exit(void)
>>>> +{
>>>> +    hid_unregister_driver(&corsairpsu_driver);
>>>> +}
>>>> +
>>>> +/* When compiled into the kernel, initialize after the hid bus */
>>>> +late_initcall(corsairpsu_hid_init);
>>>> +module_exit(corsairpsu_hid_exit);
>>>>     MODULE_LICENSE("GPL");
>>>>   MODULE_AUTHOR("Wilken Gottwalt <wilken.gottwalt@posteo.net>");
>>>
>>>
>>> Woops! Just saw that the same fix was sent yesterday. Please disregard, sorry!
>>>
>>> Aleksa
>>
>> It is fine. I just start to wonder if there was a change in the subsystem. I
>> used the driver as built-in in the past for several months and never had that
>> issue. And now it is a real flood of reports.
>>
> 
> Maybe there was a change in the build order, or some subtle change
> in driver registration code. Question though is _when_ this changed.
> It would be great if someone could bisect it. For example, bus registration
> code has been changed significantly in v6.3. I am copying linux-input
> and the hid maintainers for feedback.

The late_initcall() was also needed in 2020. when corsair-cpro was added in
40c3a4454225 ("hwmon: add Corsair Commander Pro driver").

There was also discussion on the list about it:

https://lore.kernel.org/all/3864498.z6qT3ff8q6@marius/

nzxt-smart2 (from the tail of 2021.) also has a comment about the message.

(Just providing references.)

Aleksa

> 
> Either case, I now have two patches and at least the first one was actually
> tested, but no Reviewed-by: or Tested-by: for either of them. While that is
> of course a formality, it would still be useful to show that it is not just
> a random change.
> 
> Thanks,
> Guenter
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (corsair-psu) Fix failure to load when built-in to kernel
  2023-12-08 16:52       ` Aleksa Savic
@ 2023-12-08 18:34         ` Guenter Roeck
  0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2023-12-08 18:34 UTC (permalink / raw)
  To: Aleksa Savic, Wilken Gottwalt
  Cc: linux-hwmon, Jean Delvare, linux-kernel, linux-input, Jiri Kosina,
	Benjamin Tissoires

On 12/8/23 08:52, Aleksa Savic wrote:
> On 2023-12-08 16:43:07 GMT+01:00, Guenter Roeck wrote:
>> On 12/8/23 05:57, Wilken Gottwalt wrote:
>>> On Fri, 8 Dec 2023 14:11:44 +0100
>>> Aleksa Savic <savicaleksa83@gmail.com> wrote:
>>>
>>>> On 2023-12-08 14:07:10 GMT+01:00, Aleksa Savic wrote:
>>>>> When built-in to the kernel, the corsair-psu driver fails to register with
>>>>> the following message:
>>>>>
>>>>> "Driver 'corsair-psu' was unable to register with bus_type 'hid'
>>>>> because the bus was not initialized."
>>>>>
>>>>> Fix this by initializing the driver after the HID bus using
>>>>> late_initcall(), as hwmon is built before HID.
>>>>>
>>>>> Fixes: d115b51e0e56 ("hwmon: add Corsair PSU HID controller driver")
>>>>> Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
>>>>> ---
>>>>>    drivers/hwmon/corsair-psu.c | 15 ++++++++++++++-
>>>>>    1 file changed, 14 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
>>>>> index 904890598c11..48831a528965 100644
>>>>> --- a/drivers/hwmon/corsair-psu.c
>>>>> +++ b/drivers/hwmon/corsair-psu.c
>>>>> @@ -899,7 +899,20 @@ static struct hid_driver corsairpsu_driver = {
>>>>>        .reset_resume    = corsairpsu_resume,
>>>>>    #endif
>>>>>    };
>>>>> -module_hid_driver(corsairpsu_driver);
>>>>> +
>>>>> +static int __init corsairpsu_hid_init(void)
>>>>> +{
>>>>> +    return hid_register_driver(&corsairpsu_driver);
>>>>> +}
>>>>> +
>>>>> +static void __exit corsairpsu_hid_exit(void)
>>>>> +{
>>>>> +    hid_unregister_driver(&corsairpsu_driver);
>>>>> +}
>>>>> +
>>>>> +/* When compiled into the kernel, initialize after the hid bus */
>>>>> +late_initcall(corsairpsu_hid_init);
>>>>> +module_exit(corsairpsu_hid_exit);
>>>>>      MODULE_LICENSE("GPL");
>>>>>    MODULE_AUTHOR("Wilken Gottwalt <wilken.gottwalt@posteo.net>");
>>>>
>>>>
>>>> Woops! Just saw that the same fix was sent yesterday. Please disregard, sorry!
>>>>
>>>> Aleksa
>>>
>>> It is fine. I just start to wonder if there was a change in the subsystem. I
>>> used the driver as built-in in the past for several months and never had that
>>> issue. And now it is a real flood of reports.
>>>
>>
>> Maybe there was a change in the build order, or some subtle change
>> in driver registration code. Question though is _when_ this changed.
>> It would be great if someone could bisect it. For example, bus registration
>> code has been changed significantly in v6.3. I am copying linux-input
>> and the hid maintainers for feedback.
> 
> The late_initcall() was also needed in 2020. when corsair-cpro was added in
> 40c3a4454225 ("hwmon: add Corsair Commander Pro driver").
> 
> There was also discussion on the list about it:
> 
> https://lore.kernel.org/all/3864498.z6qT3ff8q6@marius/
> 
> nzxt-smart2 (from the tail of 2021.) also has a comment about the message.
> 
> (Just providing references.)
> 

Ah yes, thanks for the reminder. We actually had a similar problem with
watchdog drivers and worked around it by deferring watchdog driver registration
until the watchdog core is initialized. That is of course just a kludge.
No idea if a clean(er) solution is even possible.

Guenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-08 18:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-08 13:07 [PATCH] hwmon: (corsair-psu) Fix failure to load when built-in to kernel Aleksa Savic
2023-12-08 13:11 ` Aleksa Savic
2023-12-08 13:57   ` Wilken Gottwalt
2023-12-08 15:43     ` Guenter Roeck
2023-12-08 16:52       ` Aleksa Savic
2023-12-08 18:34         ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox