Skip to content

Commit

Permalink
Compatibility with Linux 6.2/6.3
Browse files Browse the repository at this point in the history
Closes torvalds#32

Based on !12 by @Iam_Tj
  • Loading branch information
cgrenz committed Aug 18, 2023
1 parent adf0ee1 commit baf6e57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 14 additions & 5 deletions ddcci/ddcci.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static unsigned int delay = 60;
static unsigned short autoprobe_addrs[127] = {0xF0, 0xF2, 0xF4, 0xF6, 0xF8};
static int autoprobe_addr_count = 5;

static bool module_initialized = false;
static dev_t ddcci_cdev_first;
static dev_t ddcci_cdev_next;
static dev_t ddcci_cdev_end;
Expand Down Expand Up @@ -931,7 +932,7 @@ ATTRIBUTE_GROUPS(ddcci_char_device);

/* DDC/CI bus */

static int ddcci_device_uevent(struct device *dev, struct kobj_uevent_env *env)
static int ddcci_device_uevent(CSTRUCT device *dev, struct kobj_uevent_env *env)
{
struct ddcci_device *device = to_ddcci_device(dev);
char model[ARRAY_SIZE(device->model)];
Expand Down Expand Up @@ -1011,7 +1012,7 @@ static void ddcci_device_release(struct device *dev)
kfree(device);
}

static char *ddcci_devnode(struct device *dev,
static char *ddcci_devnode(CSTRUCT device *dev,
umode_t *mode, kuid_t *uid, kgid_t *gid)
{
struct ddcci_device *device;
Expand All @@ -1021,7 +1022,7 @@ static char *ddcci_devnode(struct device *dev,
device->i2c_client->adapter->nr);
}

static char *ddcci_dependent_devnode(struct device *dev,
static char *ddcci_dependent_devnode(CSTRUCT device *dev,
umode_t *mode, kuid_t *uid, kgid_t *gid)
{
struct ddcci_device *device;
Expand Down Expand Up @@ -1065,7 +1066,7 @@ static struct device_type ddcci_dependent_type = {
* ddcci_verify_device - return parameter as ddcci_device, or NULL
* @dev: device, probably from some driver model iterator
*/
struct ddcci_device *ddcci_verify_device(struct device *dev)
struct ddcci_device *ddcci_verify_device(CSTRUCT device *dev)
{
if (unlikely(!dev))
return NULL;
Expand Down Expand Up @@ -1100,7 +1101,7 @@ int ddcci_register_driver(struct module *owner, struct ddcci_driver *driver)
int ret;

/* Can't register until after driver model init */
if (unlikely(WARN_ON(!ddcci_bus_type.p)))
if (unlikely(WARN_ON(!smp_load_acquire(&module_initialized))))
return -EAGAIN;

pr_debug("registering driver [%s]\n", driver->driver.name);
Expand Down Expand Up @@ -1672,8 +1673,14 @@ static int ddcci_detect(struct i2c_client *client, struct i2c_board_info *info)
}

/* I2C probe function */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
static int ddcci_probe(struct i2c_client *client)
{
const struct i2c_device_id *id = i2c_client_get_device_id(client);
#else
static int ddcci_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
#endif
int i, ret = -ENODEV, tmp;
unsigned char main_addr, addr;
struct ddcci_bus_drv_data *drv_data;
Expand Down Expand Up @@ -1858,6 +1865,7 @@ static int __init ddcci_module_init(void)
}

pr_debug("ddcci driver initialized\n");
smp_store_release(&module_initialized, true);

return 0;

Expand All @@ -1875,6 +1883,7 @@ static int __init ddcci_module_init(void)
static void __exit ddcci_module_exit(void)
{
struct device *dev;
smp_store_release(&module_initialized, false);

while (1) {
dev = bus_find_device(&ddcci_bus_type, NULL, NULL, ddcci_remove_helper);
Expand Down
8 changes: 7 additions & 1 deletion include/linux/ddcci.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
#include <linux/mod_devicetable.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 2, 0)
#define CSTRUCT const struct
#else
#define CSTRUCT struct
#endif

#define DDCCI_MODULE_PREFIX "ddcci:"

Expand Down Expand Up @@ -132,7 +138,7 @@ int ddcci_register_driver(struct module *owner, struct ddcci_driver *driver);
ddcci_register_driver(THIS_MODULE, driver)
void ddcci_del_driver(struct ddcci_driver *driver);

struct ddcci_device *ddcci_verify_device(struct device *dev);
struct ddcci_device *ddcci_verify_device(CSTRUCT device *dev);

#define module_ddcci_driver(__ddcci_driver) \
module_driver(__ddcci_driver, ddcci_add_driver, \
Expand Down

0 comments on commit baf6e57

Please sign in to comment.