drivers: Add conftest test for class_create

In Linux v6.4, the module pointer argument is removed from the
class_create() function. Add a test to the conftest script that checks
if this argument for the class_create() function has been removed and
use the definition created by conftest to select which version of the
function is used.

Bug 4183168
Bug 4221847

Change-Id: I440e4b318001886cd0319bb3499ba33178475e8c
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2989020
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Jon Hunter
2023-10-02 10:56:59 +01:00
committed by mobile promotions
parent 86dafc35bb
commit ce678a37b1
21 changed files with 100 additions and 33 deletions

View File

@@ -18,7 +18,6 @@
#include <linux/poll.h>
#include <linux/slab.h>
#include <linux/sync_file.h>
#include <linux/version.h>
#include "include/uapi/linux/host1x-fence.h"
@@ -436,10 +435,10 @@ static int host1x_uapi_init(struct host1x_uapi *uapi)
if (err)
return err;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0))
uapi->class = class_create(THIS_MODULE, "host1x-fence");
#else
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
uapi->class = class_create("host1x-fence");
#else
uapi->class = class_create(THIS_MODULE, "host1x-fence");
#endif
if (IS_ERR(uapi->class)) {
err = PTR_ERR(uapi->class);

View File

@@ -3,6 +3,8 @@
* Copyright (c) 2022-2023, NVIDIA Corporation. All rights reserved.
*/
#include <nvidia/conftest.h>
#include <linux/clk.h>
#include <linux/debugfs.h>
#include <linux/dma-fence.h>
@@ -112,10 +114,10 @@ static struct device *nvhost_client_device_create(struct platform_device *pdev,
struct device *dev;
int err;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0))
pdata->nvhost_class = class_create(THIS_MODULE, pdev->dev.of_node->name);
#else
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
pdata->nvhost_class = class_create(pdev->dev.of_node->name);
#else
pdata->nvhost_class = class_create(THIS_MODULE, pdev->dev.of_node->name);
#endif
if (IS_ERR(pdata->nvhost_class)) {
dev_err(&pdev->dev, "failed to create class\n");

View File

@@ -3,6 +3,8 @@
* Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
*/
#include <nvidia/conftest.h>
#include <asm/types.h>
#include <linux/bitfield.h>
#include <linux/bits.h>
@@ -22,7 +24,6 @@
#include <linux/pm.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/version.h>
#include <uapi/media/cam_fsync.h>
@@ -911,10 +912,10 @@ static int cam_fsync_find_and_add_groups(struct cam_fsync_controller *controller
*/
static int cam_fsync_chrdev_init(struct cam_fsync_controller *controller)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0)
controller->cam_fsync_class = class_create(THIS_MODULE, CAM_FSYNC_CLASS_NAME);
#else
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
controller->cam_fsync_class = class_create(CAM_FSYNC_CLASS_NAME);
#else
controller->cam_fsync_class = class_create(THIS_MODULE, CAM_FSYNC_CLASS_NAME);
#endif
if (IS_ERR(controller->cam_fsync_class))
return PTR_ERR(controller->cam_fsync_class);

View File

@@ -8,6 +8,8 @@
* platform.
*/
#include <nvidia/conftest.h>
#include <asm/ioctls.h>
#include <linux/cdev.h>
#include <linux/device.h>
@@ -601,7 +603,7 @@ EXPORT_SYMBOL(isp_channel_drv_unregister);
*/
int isp_channel_drv_init(void)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
isp_channel_class = class_create("capture-isp-channel");
#else
isp_channel_class = class_create(THIS_MODULE, "capture-isp-channel");

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2017-2022 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2017-2023 NVIDIA Corporation. All rights reserved.
/**
* @file drivers/media/platform/tegra/camera/fusa-capture/capture-vi-channel.c
@@ -8,6 +8,8 @@
* platform.
*/
#include <nvidia/conftest.h>
#include <asm/ioctls.h>
#include <linux/cdev.h>
#include <linux/device.h>
@@ -743,7 +745,7 @@ EXPORT_SYMBOL(vi_channel_drv_unregister);
*/
int vi_channel_drv_init(void)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
vi_channel_class = class_create("capture-vi-channel");
#else
vi_channel_class = class_create(THIS_MODULE, "capture-vi-channel");

View File

@@ -4,6 +4,8 @@
* cam_cdi_tsc.c - tsc driver.
*/
#include <nvidia/conftest.h>
#include <asm/types.h>
#include <linux/bitfield.h>
#include <linux/bits.h>
@@ -22,7 +24,6 @@
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/version.h>
#define DEVICE_NAME "cdi_tsc"
#define CLASS_NAME "cdi_tsc_class"
@@ -555,7 +556,7 @@ static int cdi_tsc_probe(struct platform_device *pdev)
return majorNumber;
}
/*Create a class for the device*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
tsc_charClass = class_create(CLASS_NAME);
#else
tsc_charClass = class_create(THIS_MODULE, CLASS_NAME);

View File

@@ -1,5 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2015-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#include <nvidia/conftest.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/module.h>
@@ -1875,7 +1878,11 @@ static int cdi_mgr_probe(struct platform_device *pdev)
}
/* poluate sysfs entries */
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
cdi_mgr->cdi_class = class_create(cdi_mgr->devname);
#else
cdi_mgr->cdi_class = class_create(THIS_MODULE, cdi_mgr->devname);
#endif
if (IS_ERR(cdi_mgr->cdi_class)) {
err = PTR_ERR(cdi_mgr->cdi_class);
cdi_mgr->cdi_class = NULL;

View File

@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2015-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2015-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#include <nvidia/conftest.h>
#include <linux/delay.h>
#include <linux/fs.h>
@@ -1116,7 +1118,11 @@ static int isc_mgr_probe(struct platform_device *pdev)
}
/* poluate sysfs entries */
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
isc_mgr->isc_class = class_create(isc_mgr->devname);
#else
isc_mgr->isc_class = class_create(THIS_MODULE, isc_mgr->devname);
#endif
if (IS_ERR(isc_mgr->isc_class)) {
err = PTR_ERR(isc_mgr->isc_class);
isc_mgr->isc_class = NULL;

View File

@@ -3,6 +3,8 @@
#define pr_fmt(fmt) "nvscic2c-pcie: endpoint: " fmt
#include <nvidia/conftest.h>
#include <linux/atomic.h>
#include <linux/cdev.h>
#include <linux/dma-fence.h>
@@ -1057,7 +1059,11 @@ endpoints_setup(struct driver_ctx_t *drv_ctx, void **endpoints_h)
if (ret < 0)
goto err;
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
eps_ctx->class = class_create(eps_ctx->drv_name);
#else
eps_ctx->class = class_create(THIS_MODULE, eps_ctx->drv_name);
#endif
if (IS_ERR_OR_NULL(eps_ctx->class)) {
ret = PTR_ERR(eps_ctx->class);
goto err;

View File

@@ -6,6 +6,8 @@
* secure buffer sharing use case across processes.
*/
#include <nvidia/conftest.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/string.h>
@@ -20,7 +22,6 @@
#include <linux/cred.h>
#include <linux/of.h>
#include <linux/fs.h>
#include <linux/version.h>
#ifdef CONFIG_TEGRA_VIRTUALIZATION
#include <soc/tegra/virt/syscalls.h>
@@ -696,7 +697,7 @@ static int nvsciipc_probe(struct platform_device *pdev)
ctx->dev = &(pdev->dev);
platform_set_drvdata(pdev, ctx);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
ctx->nvsciipc_class = class_create(MODULE_NAME);
#else
ctx->nvsciipc_class = class_create(THIS_MODULE, MODULE_NAME);

View File

@@ -3,6 +3,8 @@
* SPDX-License-Identifier: GPL-2.0
*/
#include <nvidia/conftest.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
@@ -737,7 +739,7 @@ static int nvvc_register_dev(nvvc_dev_t *nvvcdev)
goto err;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
nvvcdev->class = class_create("nvvc");
#else
nvvcdev->class = class_create(THIS_MODULE, "nvvc");

View File

@@ -12,6 +12,8 @@
*
*/
#include <nvidia/conftest.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
@@ -1025,7 +1027,7 @@ static int nvpps_probe(struct platform_device *pdev)
/* character device setup */
#ifndef NVPPS_NO_DT
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
s_nvpps_class = class_create("nvpps");
#else
s_nvpps_class = class_create(THIS_MODULE, "nvpps");
@@ -1240,7 +1242,7 @@ static int __init nvpps_init(void)
printk("%s\n", __FUNCTION__);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
s_nvpps_class = class_create("nvpps");
#else
s_nvpps_class = class_create(THIS_MODULE, "nvpps");

View File

@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#include <nvidia/conftest.h>
#include <linux/bitmap.h>
#include <linux/cdev.h>
#include <linux/dcache.h>
@@ -239,7 +241,7 @@ static int __init tegra_camchar_init(struct tegra_ivc_driver *drv)
}
tegra_camchar_major_number = MAJOR(start);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
tegra_camchar_class = class_create("camchar_class");
#else
tegra_camchar_class = class_create(THIS_MODULE, "camchar_class");

View File

@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved.
#include <nvidia/conftest.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/types.h>
@@ -11,7 +13,6 @@
#include <linux/kdev_t.h>
#include <linux/mailbox_client.h>
#include <linux/sched/signal.h>
#include <linux/version.h>
#include <uapi/linux/tegra-fsicom.h>
#include <linux/pm.h>
@@ -298,7 +299,7 @@ static int fsicom_register_device(void)
return result;
}
device_file_major_number = result;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
dev_class = class_create("fsicom_client");
#else
dev_class = class_create(THIS_MODULE, "fsicom_client");

View File

@@ -1,8 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*/
#include <nvidia/conftest.h>
#include <soc/tegra/virt/hv-ivc.h>
#include <linux/module.h>
#include <linux/init.h>
@@ -489,7 +491,7 @@ static int __init setup_ivc(void)
return result;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
ivc_class = class_create("ivc");
#else
ivc_class = class_create(THIS_MODULE, "ivc");

View File

@@ -3,6 +3,8 @@
* Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*/
#include <nvidia/conftest.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/types.h>
@@ -421,7 +423,11 @@ static int tegra_hv_setup(struct tegra_hv_data *hvd)
return -ENODEV;
}
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
hvd->hv_class = class_create("tegra_hv");
#else
hvd->hv_class = class_create(THIS_MODULE, "tegra_hv");
#endif
if (IS_ERR(hvd->hv_class)) {
ERR("class_create() failed\n");
return PTR_ERR(hvd->hv_class);

View File

@@ -1,7 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*/
#include <nvidia/conftest.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/of.h>
@@ -1065,7 +1068,7 @@ static int tegra_hv_pm_ctl_probe(struct platform_device *pdev)
return ret;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
data->class = class_create(DRV_NAME);
#else
data->class = class_create(THIS_MODULE, DRV_NAME);

View File

@@ -3,6 +3,8 @@
#define pr_fmt(fmt) "%s:%s(): " fmt, KBUILD_MODNAME, __func__
#include <nvidia/conftest.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kdev_t.h>
@@ -368,7 +370,7 @@ static int tegra_hv_vcpu_yield_probe(struct platform_device *pdev)
}
major = MAJOR(vcpu_yield_pdev->vcpu_yield_dev);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
vcpu_yield_class =
class_create("tegra_hv_vcpu_yield");
#else

View File

@@ -1,8 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*/
#include <nvidia/conftest.h>
#include <linux/compiler.h>
#include <linux/module.h>
#include <linux/init.h>
@@ -15,7 +17,6 @@
#include <soc/tegra/fuse.h>
#include <soc/tegra/virt/hv-ivc.h>
#include <uapi/linux/nvhvivc_mempool_ioctl.h>
#include <linux/version.h>
#include <linux/uaccess.h>
@@ -305,7 +306,7 @@ static int __init setup_ivc_mempool(void)
}
/* register ivc_user class with sysfs */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0)
#if defined(NV_CLASS_CREATE_HAS_NO_OWNER_ARG) /* Linux v6.4 */
ivc_mempool_class = class_create("tegra_uivc_mpool");
#else
ivc_mempool_class = class_create(THIS_MODULE, "tegra_uivc_mpool");

View File

@@ -89,6 +89,7 @@ endef
#
NV_CONFTEST_FUNCTION_COMPILE_TESTS += bus_type_struct_remove_has_int_return_type
NV_CONFTEST_FUNCTION_COMPILE_TESTS += class_create_has_no_owner_arg
NV_CONFTEST_FUNCTION_COMPILE_TESTS += class_struct_devnode_has_const_dev_arg
NV_CONFTEST_FUNCTION_COMPILE_TESTS += define_semaphore_has_number_arg
NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_thermal_of_zone_register

View File

@@ -6312,6 +6312,24 @@ compile_test() {
compile_check_conftest "$CODE" "NV_BUS_TYPE_STRUCT_REMOVE_HAS_INT_RETURN_TYPE" "" "types"
;;
class_create_has_no_owner_arg)
#
# Determine if the class_create() function has the 'owner' argument.
#
# Commit 1aaba11da9aa ("driver core: class: remove module * from
# class_create()") removed the owner argument for the class_create
# function in Linux v6.4.
#
CODE="
#include <linux/device.h>
#include <linux/device/class.h>
struct class *conftest_class_create_has_no_owner_arg(const char *name) {
return class_create(name);
}"
compile_check_conftest "$CODE" "NV_CLASS_CREATE_HAS_NO_OWNER_ARG" "" "types"
;;
class_struct_devnode_has_const_dev_arg)
#
# Determine if the 'class' structure devnode function pointer