martinezjavier / ldd3

Linux Device Drivers 3 examples updated to work in recent kernels
http://examples.oreilly.com/9780596005900/
Other
2.35k stars 905 forks source link

Not compiling on Ubuntu 21.10 kernel version 5.14.16 #70

Closed Karcsii closed 2 years ago

Karcsii commented 2 years ago

Screenshot from 2021-11-05 19-37-05

QuantumForge commented 2 years ago

I think this error occurs because struct tty_operations must have changed. I am using kernel 5.14.9. In the kernel source tree include/linux/tty_driver.h take a look at the definition of struct tty_operations and note that the member write_room is of type pointer to function returning unsigned int:

struct tty_operations {
        struct tty_struct * (*lookup)(struct tty_driver *driver, struct file *filp, int idx);
        int  (*install)(struct tty_driver *driver, struct tty_struct *tty);
        void (*remove)(struct tty_driver *driver, struct tty_struct *tty);
        int  (*open)(struct tty_struct * tty, struct file * filp);
        void (*close)(struct tty_struct * tty, struct file * filp);
        void (*shutdown)(struct tty_struct *tty);
        void (*cleanup)(struct tty_struct *tty);
        int  (*write)(struct tty_struct * tty,
                      const unsigned char *buf, int count);
        int  (*put_char)(struct tty_struct *tty, unsigned char ch);
        void (*flush_chars)(struct tty_struct *tty);
        unsigned int (*write_room)(struct tty_struct *tty);

tty/tiny_tty.c assigns the function tiny_write_room to the member write_room of the struct tty_operations named serial_ops, but tiny_write_room is defined as returning int, not unsigned int which is required by the definition of struct tty_operations.

To get past this error you can simply change the return type of tiny_write_room from static int to static unsigned int at line 196 of tiny/tiny_tty.c like this:

static unsigned int tiny_write_room(struct tty_struct *tty)

It should compile. Unfortunately there are more compiler errors with sbull.c in the build chain after this that need to be addressed.

dwalkes commented 2 years ago

To get past this error you can simply change the return type of tiny_write_room from static int to static unsigned int at line 196 of tiny/tiny_tty.c like this:

Thanks @QuantumForge would you like to send a pull request with this change?