From ed3fdebc3353bc64609786a18ea9944cd55c42a8 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Mon, 18 Sep 2023 14:33:18 +0100 Subject: [PATCH] thermal: max77851: Fix build for pre-Linux v6.1 kernels The max77851 driver is failing to build for Linux kernels v5.16 to v6.0 and the following error is seen ... drivers/thermal/max77851_thermal.c:173:30: error: implicit declaration of function 'devm_thermal_of_zone_register'; did you mean 'devm_thermal_zone_of_sensor_register'? [-Werror=implicit-function-declaration] thermal->tz_device = devm_thermal_of_zone_register(&pdev->dev, 0, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The function devm_thermal_of_zone_register() was introduced in Linux kernel v6.1 and not v5.16. Instead of relying on kernel version to determine if this function is present using the conftest.sh script which checks the kernel that is being compiled to see if this function is present or not. This is also beneficial for working with 3rd party Linux kernels that may have back-ported upstream changes into their kernel and so the kernel version checks do not work either. Bug 200749982 Change-Id: I8d5e70d2d39497d7f513c82cd3a45312b2bc016a Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2980925 --- drivers/thermal/max77851_thermal.c | 27 ++++++++++++++------------- scripts/conftest/Makefile | 2 +- scripts/conftest/conftest.sh | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/max77851_thermal.c b/drivers/thermal/max77851_thermal.c index c44c7ddd..2b4d5289 100644 --- a/drivers/thermal/max77851_thermal.c +++ b/drivers/thermal/max77851_thermal.c @@ -4,6 +4,8 @@ * Junction temperature thermal driver for Maxim Max77851. */ +#include + #include #include #include @@ -13,7 +15,6 @@ #include #include #include -#include #include @@ -43,16 +44,16 @@ struct max77851_therm_info { int irq_tjalarm2; }; -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) -static int max77851_thermal_read_temp(void *data, int *temp) -#else +#if defined(NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT) static int max77851_thermal_read_temp(struct thermal_zone_device *data, int *temp) +#else +static int max77851_thermal_read_temp(void *data, int *temp) #endif { -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) - struct max77851_therm_info *thermal = data; -#else +#if defined(NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT) struct max77851_therm_info *thermal = data->devdata; +#else + struct max77851_therm_info *thermal = data; #endif unsigned int val; int ret; @@ -74,10 +75,10 @@ static int max77851_thermal_read_temp(struct thermal_zone_device *data, int *tem return 0; } -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) -static const struct thermal_zone_of_device_ops max77851_thermal_ops = { -#else +#if defined(NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT) static const struct thermal_zone_device_ops max77851_thermal_ops = { +#else +static const struct thermal_zone_of_device_ops max77851_thermal_ops = { #endif .get_temp = max77851_thermal_read_temp, }; @@ -166,11 +167,11 @@ static int max77851_thermal_probe(struct platform_device *pdev) max77851_thermal_init(thermal); -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) - thermal->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, +#if defined(NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT) + thermal->tz_device = devm_thermal_of_zone_register(&pdev->dev, 0, thermal, &max77851_thermal_ops); #else - thermal->tz_device = devm_thermal_of_zone_register(&pdev->dev, 0, + thermal->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, thermal, &max77851_thermal_ops); #endif if (IS_ERR(thermal->tz_device)) { diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index 5863a050..fc5491dc 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -88,7 +88,7 @@ endef # provided by the module-specific Kbuild files. # -NV_CONFTEST_FUNCTION_COMPILE_TESTS ?= +NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_thermal_of_zone_register NV_CONFTEST_GENERIC_COMPILE_TESTS ?= NV_CONFTEST_MACRO_COMPILE_TESTS ?= NV_CONFTEST_SYMBOL_COMPILE_TESTS ?= diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index 73f11bd2..aa2480a9 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -6293,6 +6293,23 @@ compile_test() { compile_check_conftest "$CODE" "NV_CRYPTO_PRESENT" "" "symbols" ;; + devm_thermal_of_zone_register) + # + # Determine whether devm_thermal_of_zone_register is present. + # + # devm_thermal_of_zone_register was added in commit 3fd6d6e2b4e8 + # ("thermal/of: Rework the thermal device tree initialization") in + # v6.1 (2022-08-17) + # + CODE=" + #include + void conftest_devm_thermal_of_zone_register(void) { + devm_thermal_of_zone_register(); + }" + + compile_check_conftest "$CODE" "NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT" "" "functions" + ;; + # When adding a new conftest entry, please use the correct format for # specifying the relevant upstream Linux kernel commit. #