struct i2c_driver initialization of ‘int (*)(struct i2c_client *)’ from incompatible pointer type Kernel Device driver

I am trying to write a driver for my i2с device. But I got a dead-end problem, which I could not solve with the help of Google for several days.

In general, I simplified the code to a minimum to understand where exactly the error is.

#include <linux/i2c.h>
#include <linux/module.h>

static int my_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    pr_info("Probe function calledn");
    // Add your probe implementation here
    return 0; // Return 0 on success
}

static int my_i2c_remove(struct i2c_client *client)
{
    pr_info("Remove function calledn");
    // Add your remove implementation here
    return 0; // Return 0 on success
}

static const struct i2c_device_id my_id_table[] = {
    { "my_i2c_device", 0 },
    { }
};
MODULE_DEVICE_TABLE(i2c, my_id_table);

static struct i2c_driver my_i2c_driver = {
    .driver = {
        .name = "my_i2c_driver",
        .owner = THIS_MODULE,
    },
    .probe = my_i2c_probe,
    .remove = my_i2c_remove,
    .id_table = my_id_table,
};

static int __init my_init(void)
{
    return i2c_add_driver(&my_i2c_driver);
}

static void __exit my_exit(void)
{
    i2c_del_driver(&my_i2c_driver);
}

module_init(my_init);
module_exit(my_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("Sample I2C Driver");

The constant error I get:

sudo make 
make -C /lib/modules/6.6.37-v8+/build M=/home/pi/ForestBox/driver modules
make[1]: Entering directory '/home/pi/linux-4251c6ff2aa870ca9782abc0ecdf60eac3ba22ab'
  CC [M]  /home/pi/ForestBox/driver/RTC_PCF_Driver.o
/home/pi/ForestBox/driver/RTC_PCF_Driver.c:29:14: error: initialization of ‘int (*)(struct i2c_client *)’ from incompatible pointer type ‘int (*)(struct i2c_client *, const struct i2c_device_id *)’ [-Werror=incompatible-pointer-types]
   29 |     .probe = my_i2c_probe,
      |              ^~~~~~~~~~~~
/home/pi/ForestBox/driver/RTC_PCF_Driver.c:29:14: note: (near initialization for ‘my_i2c_driver.probe’)
/home/pi/ForestBox/driver/RTC_PCF_Driver.c:30:15: error: initialization of ‘void (*)(struct i2c_client *)’ from incompatible pointer type ‘int (*)(struct i2c_client *)’ [-Werror=incompatible-pointer-types]
   30 |     .remove = my_i2c_remove,
      |               ^~~~~~~~~~~~~
/home/pi/ForestBox/driver/RTC_PCF_Driver.c:30:15: note: (near initialization for ‘my_i2c_driver.remove’)
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:243: /home/pi/ForestBox/driver/RTC_PCF_Driver.o] Error 1
make[2]: *** [/home/pi/linux-4251c6ff2aa870ca9782abc0ecdf60eac3ba22ab/Makefile:1921: /home/pi/ForestBox/driver] Error 2
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/home/pi/linux-4251c6ff2aa870ca9782abc0ecdf60eac3ba22ab'
make: *** [Makefile:5: all] Error 2

Here is the kernel version

pi@raspberrypi:~/ForestBox/driver $ uname -r
6.6.37-v8+

GCC version

pi@raspberrypi:~/ForestBox/driver $ gcc --version
gcc (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I understand what the error is about, and that the signatures must match. and it seems to me that they are the same.

I tried to do the same on another fresh OS but same device and got the same error

I suspect there is a bug with the versions, but how can I check?

New contributor

Mykola Grodskyi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật