- 論壇徽章:
- 0
|
本帖最后由 p0w3r 于 2015-12-12 16:45 編輯
[已解決]
大概是因爲(wèi) 結(jié)構(gòu)裏面是常量, 但是我要賦值給他變量 ,因爲(wèi)不可以這樣子 .
需要在程序裏面, 調(diào)用這個(gè)結(jié)構(gòu)之前進(jìn)行賦值. 希望有老司機(jī)解釋得更明白,易懂
比如 如下代碼 .
- struct miscdevice gpio_dev = {
- .minor = MISC_DYNAMIC_MINOR,
- .name = NULL,
- .fops = &gpio_fops,
- } ;
- gpio_dev.name = data.label;
- ret = misc_register(&gpio_dev);
- if (ret) {
- printk("Error: cannot register misc.\n");
- return ret;
- }
復(fù)制代碼
以下是miscdevice 頭文件的內(nèi)容 .- struct device;
- struct miscdevice {
- int minor;
- const char *name;
- const struct file_operations *fops;
- struct list_head list;
- struct device *parent;
- struct device *this_device;
- const char *nodename;
- umode_t mode;
- };
- extern int misc_register(struct miscdevice *misc);
- extern int misc_deregister(struct miscdevice *misc);
復(fù)制代碼make[1]: Warning: File `../gpio-reset3g/gpio-reset3g.c' has modification time 26 s in the future
CC [M] ../gpio-reset3g/gpio-reset3g.o
../gpio-reset3g/gpio-reset3g.c:73:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
const char gpio_dev.name;
^
../gpio-reset3g/gpio-reset3g.c:84:9: error: initializer element is not constant
.name = data.label,
^
../gpio-reset3g/gpio-reset3g.c:84:9: error: (near initialization for 'gpio_dev.name')
make[1]: *** [../gpio-reset3g/gpio-reset3g.o] Error 1
make: *** [_module_../gpio-reset3g] Error 2
以下是我自己的驅(qū)動(dòng)代碼 , 由於.name 成員我想用dts 傳進(jìn)來(lái)的值進(jìn)行賦值,但是我按下面這樣子編譯出現(xiàn)以上的錯(cuò)誤 .- struct file_operations gpio_fops = {
- .owner = THIS_MODULE,
- .open = gpio_open,
- .release = gpio_release,
- .unlocked_ioctl = gpio_ioctl,
- };
- struct miscdevice gpio_dev = {
- .minor = MISC_DYNAMIC_MINOR,
- .name = data.label,
- .fops = &gpio_fops,
- };
- ret = misc_register(&gpio_dev);
復(fù)制代碼 上面 .name 右邊的 data.label 是以下這樣一個(gè)結(jié)構(gòu) .- struct gpio_data {
- int gpio_num;
- const char *label;
- } data;
復(fù)制代碼 |
|