thermal: netlink: Improve the initcall ordering
authorDaniel Lezcano <daniel.lezcano@linaro.org>
Fri, 17 Jul 2020 16:42:16 +0000 (18:42 +0200)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Tue, 21 Jul 2020 08:40:08 +0000 (10:40 +0200)
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 <m.szyprowski@samsung.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
Link: https://lore.kernel.org/r/20200717164217.18819-1-daniel.lezcano@linaro.org
drivers/thermal/thermal_core.c
drivers/thermal/thermal_netlink.c
drivers/thermal/thermal_netlink.h

index 750a89f0c20a50e5cad7154abc96ba141ef1c63f..d2e5a223377af0b6f34466c05f367048eaa4206a 100644 (file)
@@ -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)
index 9299e7975f31f24f3904a8657f1c030fadba3445..af7b2383e8f6b1fc2e3863ec419bdb77ff307e10 100644 (file)
@@ -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);
index 0ec28d105da5bead54b90115938f3c9f2e241f1d..828d1dddfa98b5677628748542bea40c7d7e71bd 100644 (file)
@@ -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);
@@ -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;