Skip to content

Commit d2a89b5

Browse files
committed
thermal: netlink: Improve the initcall ordering
The initcalls like to play joke. In our case, the thermal-netlink initcall is called after the thermal-core initcall but this one sends a notification before the former is initialized. No issue was spotted, but it could lead to a memory corruption, so instead of relying on the core_initcall for the thermal-netlink, let's initialize directly from the thermal-core init routine, so we have full control of the init ordering. Reported-by: Marek Szyprowski <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Tested-by: Marek Szyprowski <[email protected]> Reviewed-by: Amit Kucheria <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c62e7ac commit d2a89b5

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

drivers/thermal/thermal_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,10 @@ static int __init thermal_init(void)
16401640
{
16411641
int result;
16421642

1643+
result = thermal_netlink_init();
1644+
if (result)
1645+
goto error;
1646+
16431647
mutex_init(&poweroff_lock);
16441648
result = thermal_register_governors();
16451649
if (result)

drivers/thermal/thermal_netlink.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,7 @@ static struct genl_family thermal_gnl_family __ro_after_init = {
641641
.n_mcgrps = ARRAY_SIZE(thermal_genl_mcgrps),
642642
};
643643

644-
static int __init thermal_netlink_init(void)
644+
int __init thermal_netlink_init(void)
645645
{
646646
return genl_register_family(&thermal_gnl_family);
647647
}
648-
core_initcall(thermal_netlink_init);

drivers/thermal/thermal_netlink.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/* Netlink notification function */
88
#ifdef CONFIG_THERMAL_NETLINK
9+
int __init thermal_netlink_init(void);
910
int thermal_notify_tz_create(int tz_id, const char *name);
1011
int thermal_notify_tz_delete(int tz_id);
1112
int thermal_notify_tz_enable(int tz_id);
@@ -23,6 +24,11 @@ int thermal_notify_cdev_delete(int cdev_id);
2324
int thermal_notify_tz_gov_change(int tz_id, const char *name);
2425
int thermal_genl_sampling_temp(int id, int temp);
2526
#else
27+
static inline int thermal_netlink_init(void)
28+
{
29+
return 0;
30+
}
31+
2632
static inline int thermal_notify_tz_create(int tz_id, const char *name)
2733
{
2834
return 0;

0 commit comments

Comments
 (0)