module -- comiple warning.... copy_from_user() , copy_to_user(), verify_area ..
HI,
I want to compile test.c -- it is very simple module programming...
I don't know why copy_from_user() , copy_to_user(), verify_area is
warning...
what's wrong....
=== test.c===
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include "ioctl_test.h"
#define DEV_NAME "testdev"
#define DEV_MAJOR 240
ssize_t ioctltest_read (struct file *fp, char *buf, size_t count , loff_t
*f_ops)
{
verify_area (VERIFY_WREITE, (void *)buf , count );
return some_count;
}
int ioctltest_open (struct inode *inode, struct file *filp)
{
return 0;
}
int ioctltest_release (struct inode *inode, struct file *filp)
{
return 0;
}
int ioctltest_ioctl (struct inode *inode, struct file *filp, unsigned int
cmd, unsigned long arg)
{
char kbuf[128] = {0,};
switch( cmd )
{
case WRITE :
...
..
copy_from_user ( (void *)&kbuf, (const void *) arg, size );
case READ :
..
..
strcpy ( kbuf , "test" );
copy_to_user ( (void *) arg, (const void *)
&kbuf, 4 );
break;
}
return 0;
}
struct file_operations ioctltest_fops =
{
.owner = THIS_MODULE,
.ioctl = ioctltest_ioctl,
.open = ioctltest_open,
.release = ioctltest_release,
};
int ioctltest_init(void)
{
int result;
result = register_chrdev( DEV_MAJOR, DEV_NAME, &ioctltest_fops);
if (result < 0) return result;
return 0;
}
void ioctltest_exit(void)
{
unregister_chrdev( DEV_MAJOR, DEV_NAME );
}
module_init(ioctltest_init);
module_exit(ioctltest_exit);
MODULE_LICENSE("Dual BSD/GPL");
==== Makefile =========
obj-m := test.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.ko
rm -rf *.mod.*
rm -rf .*.cmd
rm -rf *.o
==== when I compile ...
/root/work/test/src/m_src/test.c:618: warning: ignoring return value of
`copy_from_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c: In function `test_ioctl':
/root/work/test/src/m_src/test.c:666: warning: ignoring return value of
`copy_from_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c:677: warning: ignoring return value of
`copy_from_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c:687: warning: ignoring return value of
`copy_from_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c:695: warning: ignoring return value of
`copy_from_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c:717: warning: ignoring return value of
`copy_to_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c:728: warning: ignoring return value of
`copy_to_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c:732: warning: ignoring return value of
`copy_from_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c:740: warning: ignoring return value of
`copy_from_user', declared with attribute warn_unused_result
/root/work/test/src/m_src/test.c:745: warning: ignoring return value of
`copy_to_user', declared with attribute warn_unused_result
Building modules, stage 2.
MODPOST 1 modules
WARNING: "verify_area" [/root/work/test/src/m_src/test.ko] undefined!
CC /root/work/test/src/m_src/test.mod.o
LD [M] /root/work/test/src/m_src/test.ko
make[1]: Leaving directory `/usr/src/linux-2.6.20'
Thanks...
Re: module -- comiple warning.... copy_from_user() , copy_to_user(), verify_area ..
google-rambo88 <rambo88@gmail.com> wrote:[color=blue]
> I want to compile test.c -- it is very simple module programming...
> I don't know why copy_from_user() , copy_to_user(), verify_area is
> warning...[/color]
[color=blue]
> ==== when I compile ...[/color]
[color=blue]
> /root/work/test/src/m_src/test.c:618: warning: ignoring return value of
> `copy_from_user', declared with attribute warn_unused_result[/color]
The functions copy_from_user() and copy_to_user() have a return
value that is very important to check in order to figure out if
copying data to or from userspace succeeded, and they thus
obviously have been defined with the "warn_unused_result"
attribute. Thus you always will get a warning if you discard
their return values. Check it in your code as you should and
these warnings will go away.
[color=blue]
> WARNING: "verify_area" [/root/work/test/src/m_src/test.ko] undefined![/color]
The verify_area() isn't needed anymore since kernel version
2.2 (or 2.1, if you include experimental kernels) and thus in
newer kernels the function doesn't exist. Checks are done
automatically in copy_to_user() and copy_from_user().
Please note that the interface and the way modules are written
has changed quite a bit since 2.0 kernels, so you definitely
should get the documentation for the kernel series you are pro-
gramming for, see for example
[url]http://lwn.net/Kernel/LDD3/http://lwn.net/Kernel/LDD3/[/url]
Moreover, for the discussion of programming kernel modules
there's the group <comp.os.linux.development.system> while
this group is more about discussions of application program-
ming.
Regards, Jens
--
\ Jens Thoms Toerring ___ [email]jt@toerring.de[/email]
\__________________________ [url]http://toerring.de[/url]