LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-06-2010, 11:09 PM   #1
shahzebihsan
LQ Newbie
 
Registered: Apr 2010
Posts: 1

Rep: Reputation: 0
Question Kernel module "read()" return value


Hi,

I wrote a character device driver for an Embedded Linux build (Kernel Revision 2.6.17.1) running on ARM9. In the module's "read()" function, I'm returning the number of bytes that were copied into the user buffer. I saw some module code samples online and in most cases the "read()" function is returning the number of bytes read.

The very strange behavior I saw in my case was, if I use a variable to return the value from the module's "read()" function, the user application reading from the module always saw "0".

For instance:

Code:
static int zlg7289_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
   int bytes = 0;
   
   // Read bytes, copy to user space using "put_user()"
   ...
   ...
   ...
   
   // Added this for debugging
   if(bytes) printk("Bytes: %d\n", bytes);

   return (bytes);
}
If I use the code given above, the user application always got back "0". In case I returned a hard-coded value, it worked fine, i.e.:

Code:
   .
   .
   .
   // Any number here works fine
   return (1);
Any explanation for this behavior?

Thanks!
- Shahzeb
 
Old 04-15-2010, 03:32 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,623
Blog Entries: 29

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Does your following code print the correct value ?
Code:
// Added this for debugging
   if(bytes) printk("Bytes: %d\n", bytes);
Also show how and where you are handling the variable which holds the return value of zlg7289_read !
 
  


Reply

Tags
character, device, driver, kernel, linux, module, number, read, return, value


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
rt61pci kernel module fails to load in -current "Invalid module format" Interject Slackware 6 03-20-2010 02:48 AM
What is the error "invalid module format" and "insert kernel module"? shayori Linux - Newbie 8 02-25-2010 04:48 AM
Problem "$value=`mpstat 1 1 | grep "Average"`;" Alias pipe return nothing adamlucansky Linux - General 8 09-25-2009 08:26 AM
"Invalid module format" after recompiling kernel without changing .config - why? kovlensky Linux - Kernel 5 09-10-2008 01:42 PM
kernel 2.6.0 debian "No module symbols loaded - kernel modules not enabled." toovato Linux - General 2 01-07-2004 08:56 PM


All times are GMT -5. The time now is 02:38 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration