Hi every body, i'm writing device driver for buttons of mini2440. I would like to pass a number from kernel to user space, but it seems impossible my code: 1 int i = 1988; 2 char *p = "Hello, world!"; 3 char a[14]="saranghe"; 4 5 p=(char*)&i; 6 strcpy(a, p); 7 8 err = copy_to_user(buff, &a, sizeof(a)); ---------------------------------------------------- when i load this driver into mini2440 and see the result, i used "cat /dev/nutnhan" ("nutnhan" is my driver). I espect "1988", but it display abundant of code and the last line is "segmentation fault"! if i delete line 6th (strcpy(a,p)), it works fine with displaying "saranghe" if i delete only line 5th (p=(char*)&i;), it still works fine with displaying "Hello, world!" :( who knows this problem, please help me. Thanks.
writing device driver
Sorry this is maybe not correct forum to ask. This is general question in programming not friendly arm related. Anyway this line is wrong: p=(char*)&i; - you assign to pointer p address of variable i and cast to char pointer. You need to use function which convert int to string. Try replace with : snprintf(a, sizeof(a), "%d", i); thanks, marek
hi you can use a function copy_to_user it copies kernel space data to user space. can u post your driver here
Thanks your reply. I wrote my own itoa function in device driver and it worked fine. Im sorry, i could not post my driver here because it's so long and messy, too. If you want to know any section, tell me.