Re: what`s wrong?

From: Andreas Dilger (adilger@clusterfs.com)
Date: Wed Apr 24 2002 - 11:40:56 EST


On Apr 24, 2002 18:06 +0200, il boba wrote:
> Is there anybody that can help me understand what`s wrong with this code?

Yes, easily spotted a major problem without even reading the whole
thing.

> #define BUFSIZ 8192
>
> int init_module()
> {
> int err_frame[BUFSIZ];

The entire kernel stack is only 8kB in size. You have already killed
a bunch of random memory by allocating this much memory on the stack.
You allocated 4*8192 = 32kB on the stack here.

> #if CONFIG_MODVERSIONS==1
> #define MODVERSIONS
> #include <linux/modversions.h>
> #endif

You shouldn't do things like this. Rather have a makefile which sets
the correct defines.

> int init_err_frame(int err_frame[]) {
> int i, k = 0, j = 0;
> char buffer[BUFSIZ];

Another 8kB on the stack here - further random corruption.

> struct file * f =
> filp_open("/usr/src/kernel-source-2.2.19/pinux/misc/err_file", 0, 0); /* i
> want it only readable */

More clear to add "O_RDONLY" to filp_open, even though it is still 0.

> if (f == '\0'){
> printk ("errore nell' APERTURA del file d'errore");
> return -1;
> }

How about "if (f == NULL)"?

> if ((generic_file_read(f, buffer, BUFSIZ, &f->f_pos)) < 0 ){

Calling generic_file_read() may work in some cases, but not others. It
depends on the filesystem. Use "f->f_op->read" instead.

Cheers, Andreas

--
Andreas Dilger
http://www-mddsp.enel.ucalgary.ca/People/adilger/
http://sourceforge.net/projects/ext2resize/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Apr 30 2002 - 22:00:09 EST