Skip to content

Commit

Permalink
thermal: netlink: Improve the initcall ordering
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
dlezcano committed Jul 21, 2020
1 parent c62e7ac commit d2a89b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions drivers/thermal/thermal_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,10 @@ static int __init thermal_init(void)
{
int result;

result = thermal_netlink_init();
if (result)
goto error;

mutex_init(&poweroff_lock);
result = thermal_register_governors();
if (result)
Expand Down
3 changes: 1 addition & 2 deletions drivers/thermal/thermal_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,7 @@ static struct genl_family thermal_gnl_family __ro_after_init = {
.n_mcgrps = ARRAY_SIZE(thermal_genl_mcgrps),
};

static int __init thermal_netlink_init(void)
int __init thermal_netlink_init(void)
{
return genl_register_family(&thermal_gnl_family);
}
core_initcall(thermal_netlink_init);
6 changes: 6 additions & 0 deletions drivers/thermal/thermal_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/* Netlink notification function */
#ifdef CONFIG_THERMAL_NETLINK
int __init thermal_netlink_init(void);
int thermal_notify_tz_create(int tz_id, const char *name);
int thermal_notify_tz_delete(int tz_id);
int thermal_notify_tz_enable(int tz_id);
Expand All @@ -23,6 +24,11 @@ int thermal_notify_cdev_delete(int cdev_id);
int thermal_notify_tz_gov_change(int tz_id, const char *name);
int thermal_genl_sampling_temp(int id, int temp);
#else
static inline int thermal_netlink_init(void)
{
return 0;
}

static inline int thermal_notify_tz_create(int tz_id, const char *name)
{
return 0;
Expand Down

0 comments on commit d2a89b5

Please sign in to comment.