LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 10-12-2009, 02:12 AM   #1
Cherubim
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Rep: Reputation: 0
Question 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.

Last edited by Cherubim; 10-12-2009 at 02:30 AM. Reason: typo
 
Old 10-13-2009, 01:08 AM   #2
Cherubim
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Original Poster
Rep: Reputation: 0
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;
  }
 
  


Reply

Tags
char, device, driver, function, write


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RHEL 5 Install Problem - Infinite Reboot Loop aramsey Linux - Enterprise 4 09-19-2008 04:22 AM
Apache mod_rewrite CondRewrite infinite loop problem jika Linux - Server 2 05-01-2007 07:25 AM
Infinite Loop ewt3y Programming 3 08-16-2005 09:48 AM
infinite loop beginner_84 Programming 5 08-15-2004 02:32 AM
facing problem in increment operator of set :infinite LOOP ashwinipahuja Programming 0 06-03-2004 12:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration