- 论坛徽章:
- 0
|
本帖最后由 p0w3r 于 2015-12-12 16:45 编辑
[已解決]
大概是因爲 結構裏面是常量, 但是我要賦值給他變量 ,因爲不可以這樣子 .
需要在程序裏面, 調用這個結構之前進行賦值. 希望有老司機解釋得更明白,易懂
比如 如下代碼 .
- 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;
- }
复制代码
以下是miscdevice 頭文件的內容 .- 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);
复制代码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
以下是我自己的驅動代碼 , 由於.name 成員我想用dts 傳進來的值進行賦值,但是我按下面這樣子編譯出現以上的錯誤 .- 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);
复制代码 上面 .name 右邊的 data.label 是以下這樣一個結構 .- struct gpio_data {
- int gpio_num;
- const char *label;
- } data;
复制代码 |
|