LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-18-2011, 09:42 AM   #1
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Rep: Reputation: 2
writing and reading driver value in ioctl


I just want to read and write some values (integer) to my driver. I used put/get user but always getting errors.

driver
Quote:
int Wert;

static int device_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsinged long arg)
int ret;
{
switch(cmd)
{
case SETIT:
ret=get_user(WERT, (int __user *)arg);
return ret;

case GETIT:
ret=put_user(WERT, (int __user *)arg);
return ret;
}
return -3;}

C++

Quote:
int WERT

ret=ioctl(fd, SETIT, WERT)
ret=ioctl(fd, GETIT, WERT)
if i say in C++ WERT is 5 the value arg of the driver becomes 5 but not WERT
the returnvalue of get and put user is -1 so it failed. what did i wrong?

Last edited by Vermidias; 01-18-2011 at 11:18 AM.
 
Old 01-18-2011, 10:10 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Read this:
Quote:
and the result of dereferencing ptr must be assignable to x without a cast.
from here: http://oss.org.cn/ossdocs/gnu_linux/...api/r4222.html

Check the value of EFAULT.
 
Old 01-18-2011, 10:32 AM   #3
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Original Poster
Rep: Reputation: 2
i also tried

Quote:
int WERT, arg;
Wert *arg;

ret=ioctl(fd, SETIT, arg)
ret=ioctl(fd, GETIT, arg)
no diffrens...

how do i make WERT assignable???
 
Old 01-18-2011, 10:35 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
That would obviously not make any difference, I was referring to: (int __user *)arg)
Did you check the value of EFAULT?
 
Old 01-18-2011, 10:41 AM   #5
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Original Poster
Rep: Reputation: 2
EFAULT is -1
 
Old 01-18-2011, 10:44 AM   #6
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Put EFAULT in Google and read the first link.
 
Old 01-18-2011, 10:59 AM   #7
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Original Poster
Rep: Reputation: 2
It says

"You should check your pointers are properly initialised."

ok so how to initialise a pointer properly?
 
Old 01-18-2011, 11:04 AM   #8
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
<irrelevant deleted>

Last edited by TheIndependentAquarius; 01-18-2011 at 11:27 AM.
 
Old 01-18-2011, 11:14 AM   #9
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Original Poster
Rep: Reputation: 2
http://lxr.free-electrons.com/source...wdt.c?v=2.6.28

thats the origanal driver from AMD i want to use but i dont get it how to use the get and put !#$

133 static long geodewdt_ioctl(struct file *file, unsigned int cmd,
134 unsigned long arg)
135 {
136 void __user *argp = (void __user *)arg;
137 int __user *p = argp;
138 int interval;

...

180 case WDIOC_SETTIMEOUT:
181 if (get_user(interval, p))
182 return -EFAULT;
183
184 if (geodewdt_set_heartbeat(interval))
185 return -EINVAL;
186 /* Fall through */
187 case WDIOC_GETTIMEOUT:
188 return put_user(timeout, p);
 
Old 01-18-2011, 11:26 AM   #10
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Code:
void __user *argp = (void __user *)arg;
    int __user *p = argp;
from your link. (LINE 136)

Last edited by TheIndependentAquarius; 01-18-2011 at 11:28 AM.
 
Old 01-19-2011, 03:53 AM   #11
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Original Poster
Rep: Reputation: 2
even if i use the origanal code it doesnt work as it should.

I tried this

Quote:
int WERT, arg;
Wert *arg;

ret=ioctl(fd, WDIOC_SETTIMEOUT, arg)
ret=ioctl(fd, WDIOC_GETTIMEOUT, arg)
and this
Quote:
int WERT;

ret=ioctl(fd, WDIOC_SETTIMEOUT, WERT)
ret=ioctl(fd, WDIOC_GETTIMEOUT, WERT)
and this
Quote:
int WERT, arg;
Wert *arg;

ret=ioctl(fd, WDIOC_SETTIMEOUT, (void *)arg)
ret=ioctl(fd, WDIOC_GETTIMEOUT, (void *)arg)
and this
Quote:
int WERT, arg;
Wert *arg;

ret=ioctl(fd, WDIOC_SETTIMEOUT, (int *)arg)
ret=ioctl(fd, WDIOC_GETTIMEOUT, (int *)arg)
when i give a pointer to the modul there is no fault at return (returns 0) but i think my real problem is that i dont know how to point corectly at my value.
 
Old 01-19-2011, 05:07 AM   #12
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Original Poster
Rep: Reputation: 2
and it was so easy. SOLVED
Quote:
int WERT;

ret=ioctl(fd, WDIOC_SETTIMEOUT, &WERT)
ret=ioctl(fd, WDIOC_GETTIMEOUT, &WERT)
 
1 members found this post helpful.
Old 01-19-2011, 05:10 AM   #13
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Ahh, well yes, I was not observant enough Thanks for posting the solution.
 
  


Reply


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
[SOLVED] writing and reading driver value in ioctl Vermidias Linux - Kernel 1 01-19-2011 01:54 AM
Inappropriate ioctl for device while reading flags w1k0 Slackware 3 06-01-2009 08:45 PM
writing and reading at same time dideas Programming 16 11-13-2006 07:49 PM
"Inproper ioctl reading somedirs", dirs are readonly pingu Debian 5 05-17-2005 05:22 AM
C File reading and writing AbhishekSamuel Programming 3 05-03-2005 04:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:49 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration