From f2afbafcfd8436de96b2e95e6ebfbf034e12bc8e Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Fri, 8 Sep 2023 12:41:03 +0100 Subject: [PATCH] gpu: nvgpu: Use conftest to handle kernel version differences Instead of relying on kernel version to determine if the 'dev' member of the 'struct class' is const, 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: I5b3c886fa4bac7560c2c26534bed9f495d57195b Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2986637 (cherry picked from commit f9d48796dc2a292bb02a90677774a5568f9f1651) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2990696 Reviewed-by: Ankur Kishore GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/ioctl.c | 34 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl.c b/drivers/gpu/nvgpu/os/linux/ioctl.c index 92942edb3..86dbbb376 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl.c @@ -16,6 +16,10 @@ * along with this program. If not, see . */ +#if defined(CONFIG_NVIDIA_CONFTEST) +#include +#endif + #include #include @@ -222,10 +226,10 @@ static char *nvgpu_devnode(const char *cdev_name) return kasprintf(GFP_KERNEL, "nvhost-%s-gpu", cdev_name); } -#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)) -static char *nvgpu_pci_devnode(struct device *dev, umode_t *mode) -#else +#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG) /* Linux v6.2 */ static char *nvgpu_pci_devnode(const struct device *dev, umode_t *mode) +#else +static char *nvgpu_pci_devnode(struct device *dev, umode_t *mode) #endif { /* Special case to maintain legacy names */ @@ -238,39 +242,39 @@ static char *nvgpu_pci_devnode(const struct device *dev, umode_t *mode) dev_name(dev->parent), dev_name(dev)); } -#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)) -static char *nvgpu_devnode_v2(struct device *dev, umode_t *mode) -#else +#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG) /* Linux v6.2 */ static char *nvgpu_devnode_v2(const struct device *dev, umode_t *mode) +#else +static char *nvgpu_devnode_v2(struct device *dev, umode_t *mode) #endif { return kasprintf(GFP_KERNEL, "nvgpu/igpu0/%s", dev_name(dev)); } -#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)) -static char *nvgpu_pci_devnode_v2(struct device *dev, umode_t *mode) -#else +#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG) /* Linux v6.2 */ static char *nvgpu_pci_devnode_v2(const struct device *dev, umode_t *mode) +#else +static char *nvgpu_pci_devnode_v2(struct device *dev, umode_t *mode) #endif { return kasprintf(GFP_KERNEL, "nvgpu/dgpu-%s/%s", dev_name(dev->parent), dev_name(dev)); } -#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)) -static char *nvgpu_pci_igpu_devnode_v2(struct device *dev, umode_t *mode) -#else +#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG) /* Linux v6.2 */ static char *nvgpu_pci_igpu_devnode_v2(const struct device *dev, umode_t *mode) +#else +static char *nvgpu_pci_igpu_devnode_v2(struct device *dev, umode_t *mode) #endif { return kasprintf(GFP_KERNEL, "nvgpu/igpu-%s/%s", dev_name(dev->parent), dev_name(dev)); } -#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)) -static char *nvgpu_mig_fgpu_devnode(struct device *dev, umode_t *mode) -#else +#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG) /* Linux v6.2 */ static char *nvgpu_mig_fgpu_devnode(const struct device *dev, umode_t *mode) +#else +static char *nvgpu_mig_fgpu_devnode(struct device *dev, umode_t *mode) #endif { struct nvgpu_cdev_class_priv_data *priv_data;