I'm reading LKM development manual and faced the following example when writing a device driver:
/*
* Prototypes - this would normally go in a .h file
*/
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
The thing I was confused by was that it is proposed to put static non-inline declarations into a header file. What is the reason for that?
If we are not supposed to use these functions related to the driver anywhere except than in the
struct file_operations fops = {
.open = device_open,
.release = device_release,
.read = device_read,
.write = device_write
};
static int init_module(void){
int register_result = register_chrdev(&fops);
//...
}
during module initialization then we can simply put their static definitions right here avoiding prototypes declaration. Otherwise they should (should?) be declared with external linkage.