From 02d724565b18a2fe792b2b15802d27fecc373cc4 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Tue, 26 Sep 2023 10:58:40 +0100 Subject: [PATCH] platform: tegra: rtcpu: Use conftest Instead of relying on kernel version to determine if the 'remove' callback for the 'bus_type' structure return an integer or void, add a compile time test to the conftest.sh script to determine this at compile time for the kernel being used. This is 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. Bug 4119327 Change-Id: I5457300619f5fb3b6afe61742bc6fce4cbefcd5d Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2985719 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/platform/tegra/rtcpu/ivc-bus.c | 10 ++++++---- scripts/conftest/Makefile | 1 + scripts/conftest/conftest.sh | 21 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/platform/tegra/rtcpu/ivc-bus.c b/drivers/platform/tegra/rtcpu/ivc-bus.c index 4698cea5..2ed87cba 100644 --- a/drivers/platform/tegra/rtcpu/ivc-bus.c +++ b/drivers/platform/tegra/rtcpu/ivc-bus.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +#include + #include #include #include @@ -388,10 +390,10 @@ static int tegra_ivc_bus_probe(struct device *dev) return ret; } -#if (KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE) -static void tegra_ivc_bus_remove(struct device *dev) -#else +#if defined(NV_BUS_TYPE_STRUCT_REMOVE_HAS_INT_RETURN_TYPE) /* Linux v5.15 */ static int tegra_ivc_bus_remove(struct device *dev) +#else +static void tegra_ivc_bus_remove(struct device *dev) #endif { if (dev->type == &tegra_ivc_channel_type) { @@ -408,7 +410,7 @@ static int tegra_ivc_bus_remove(struct device *dev) } -#if (KERNEL_VERSION(5, 15, 0) > LINUX_VERSION_CODE) +#if defined(NV_BUS_TYPE_STRUCT_REMOVE_HAS_INT_RETURN_TYPE) /* Linux v5.15 */ return 0; #endif } diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index 582242a0..1c708552 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -88,6 +88,7 @@ endef # provided by the module-specific Kbuild files. # +NV_CONFTEST_FUNCTION_COMPILE_TESTS += bus_type_struct_remove_has_int_return_type NV_CONFTEST_FUNCTION_COMPILE_TESTS += class_struct_devnode_has_const_dev_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_thermal_of_zone_register NV_CONFTEST_FUNCTION_COMPILE_TESTS += drm_aperture_remove_framebuffers_has_drm_driver_arg diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index 4d5015d7..8bd93e6a 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -6293,6 +6293,25 @@ compile_test() { compile_check_conftest "$CODE" "NV_CRYPTO_PRESENT" "" "symbols" ;; + bus_type_struct_remove_has_int_return_type) + # + # Determine if the 'remove' callback from the 'bus_type' structure + # has an integer return type. + # + # Commit fc7a6209d571 ("bus: Make remove callback return void") made + # the 'remove' callback return void instead of an integer in Linux + # v5.15. + # + CODE=" + #include + int conftest_bus_type_struct_remove_has_int_return_type(struct device *dev, + struct bus_type *bus) { + return bus->remove(dev); + }" + + compile_check_conftest "$CODE" "NV_BUS_TYPE_STRUCT_REMOVE_HAS_INT_RETURN_TYPE" "" "types" + ;; + class_struct_devnode_has_const_dev_arg) # # Determine if the 'class' structure devnode function pointer @@ -6515,7 +6534,7 @@ compile_test() { # function in Linux v6.0. # CODE=" - #include + #include #include #include int conftest_register_shrinker_has_fmt_arg(struct shrinker *s, const char *name) {