2014-04-11 2 views
0

과제에서 나는 카드 더미를위한 장치 드라이버를 만들어야합니다. 그러나 구조체의 배열에 kmalloc 사용하여 문제가 있습니다. 갑판 및 크기 (52)의 나는 지금까지 다음 한 구조체의 배열 (분명히 그것은 불완전) :장치 드라이버에서 kmalloc 사용

#include <linux/slab.h>   // kmalloc() 
#include <linux/fs.h>   // everything 
#include <linux/errno.h>  // error codes 
#include <linux/types.h>  // ssize_t 
#include <linux/fcntl.h>  // O_ACCMODE 
#include <linux/miscdevice.h> 
#include <asm/uaccess.h>  // copy_to_user copy_from_user 

MODULE_LICENSE("GPL"); 

struct card{ 
    char num; 
    char suit; 
}; 

struct card deck[52]; 

static int __init_deck(void){ 
    int i; 
    int returnValue; 
    for(i = 0; i < 52; i++){ 
     deck[i] = kmalloc(sizeof(struct card), GFP_KERNEL); // error here 
     if(!deck[i]){ // error here 
      printk(KERN_ERR "Unable to allocate memory."); 
     } 
    } 

    return returnValue; 
} 

나는 시도하고 시도하고 제 error: wrong type argument to unary exclamation mark에 대한 error: incompatible types when assigning to type ‘struct card’ from type ‘void *’의 메이크 파일을 사용하여 컴파일 할 때이 오류가 둘째. 내가 kmalloc 하나 고정되면 두 번째가 사라질 것이라고 가정하지만, 내가 잘못하고 어떻게 수정 해야할지 모르겠다.

답변

2

오류에주의하십시오. 포인터 유형을 struct card에 지정하려고합니다. card*의 배열을 원했던 것 같습니다.

struct card *deck[52]; 

그렇지 않으면 동적 할당이 필요하지 않습니다. 이미 52 유효한 card 개체가 있습니다.

+0

오른쪽, 구조체 포인터 배열, 감사합니다! – user3268401

관련 문제