LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Problem with char driver write function - infinite loop (http://www.linuxquestions.org/questions/linux-kernel-70/problem-with-char-driver-write-function-infinite-loop-761292/)

Cherubim 10-12-2009 02:12 AM

Problem with char driver write function - infinite loop
 
Hello,

I've a problem with a really simple write function in my first char driver.
The function is as follows:

Code:

...
static char hello_world[]="Hello World\n";
...
static ssize_t driver_write (struct file *instanz, const char *user, size_t count,
 loff_t *offset ) {

  int nc = 0;
  if (count > strlen(hello_world)+1) return strlen(hello_world)+1-count;

  return copy_from_user(hello_world,user,count);
  }

If I try wo write on the associated Device, the write call works but it seems that is produces an infinite loop.
So the write function seems to be call infinite times.
By the printk in the write function i can see that behavior.

The failure goes from a simple echo > /dev/device to an C program using fwrite.

I'm grateful for each hint.

Thanks,
Johannes S.

Cherubim 10-13-2009 01:08 AM

Problem fixed.. I'be to return the values of the written bytes and not of the not written.
Correct is:

Code:

 
...
  nc = copy_from_user(hello_world,user,count);
  return count-nc;
  }



All times are GMT -5. The time now is 03:32 PM.