我正在使用內核3.13.0編寫Linux設備驅動程序,我很困惑,爲什麼我得到這個警告。爲什麼會出現不兼容的指針類型警告?
warning: initialization from incompatible pointer type [enabled by default]
.read = read_proc,
^
warning: (near initialization for ‘proc_fops.read’) [enabled by default]
據我可以告訴我的proc函數的file_operations設置是相同的設備功能。我可以讀寫/ dev/MyDevice,沒有任何問題,也沒有任何警告。 proc寫函數不會引發警告,只會引發讀取。我做錯了什麼?
/*****************************************************************************/
//DEVICE OPERATIONS
/*****************************************************************************/
static ssize_t dev_read(struct file *pfil, char __user *pBuf, size_t
len, loff_t *p_off)
{
//Not relevant to this question
}
static ssize_t dev_write(struct file *pfil, const char __user *pBuf,
size_t len, loff_t *p_off)
{
//Not relevant to this question
}
static struct file_operations dev_fops =
{ //None of these cause a warning but the code is identical the proc code below
.owner = THIS_MODULE,
.read = dev_read,
.write = dev_write
};
/*****************************************************************************/
//PROCESS OPERATIONS
/*****************************************************************************/
static int read_proc(struct file *pfil, char __user *pBuf, size_t
len, loff_t *p_off)
{
//Not relevant to this question
}
static ssize_t write_proc(struct file *pfil, const char __user *pBuf,
size_t len, loff_t *p_off)
{
//Not relevant to this question
}
struct file_operations proc_fops =
{
.owner = THIS_MODULE,
.write = write_proc,
.read = read_proc, //This line causes the warning.
};
編輯:所以答案是,我是一個白癡沒有看到「int」與「ssize_t」。謝謝大家! Codenheim和Andrew Medico大致在同一時間得到了正確的答案,但我選擇了Medico's,因爲它對未來的訪問者來說更迂腐和明顯。
也不是這樣。不警告的函數返回** s ** size_t。 – 2014-10-31 16:22:12
@AndrewMedico - 這是一個錯字。我首先將它作爲size_t讀取,但重點仍然相同。 – codenheim 2014-10-31 16:24:18