LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   writing and reading driver value in ioctl (https://www.linuxquestions.org/questions/programming-9/writing-and-reading-driver-value-in-ioctl-857040/)

Vermidias 01-18-2011 08:42 AM

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?

Aquarius_Girl 01-18-2011 09:10 AM

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.

Vermidias 01-18-2011 09:32 AM

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???

Aquarius_Girl 01-18-2011 09:35 AM

That would obviously not make any difference, I was referring to: (int __user *)arg)
Did you check the value of EFAULT?

Vermidias 01-18-2011 09:41 AM

EFAULT is -1

Aquarius_Girl 01-18-2011 09:44 AM

Put EFAULT in Google and read the first link.

Vermidias 01-18-2011 09:59 AM

It says

"You should check your pointers are properly initialised."

ok so how to initialise a pointer properly?

Aquarius_Girl 01-18-2011 10:04 AM

<irrelevant deleted>

Vermidias 01-18-2011 10:14 AM

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);

Aquarius_Girl 01-18-2011 10:26 AM

Code:

void __user *argp = (void __user *)arg;
    int __user *p = argp;

from your link. (LINE 136)

Vermidias 01-19-2011 02:53 AM

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.

Vermidias 01-19-2011 04:07 AM

and it was so easy. SOLVED
Quote:

int WERT;

ret=ioctl(fd, WDIOC_SETTIMEOUT, &WERT)
ret=ioctl(fd, WDIOC_GETTIMEOUT, &WERT)

Aquarius_Girl 01-19-2011 04:10 AM

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


All times are GMT -5. The time now is 09:28 PM.