Hi everybody,

Im trying to read a file from kernel using the below code:

#include <linux/module.h> // Needed by all modules
#include <linux/kernel.h> // Needed for KERN_INFO
#include <linux/fs.h> // Needed by filp
#include <asm/uaccess.h> // Needed by segment descriptors

int init_module(void)
{
// Create variables
struct file *f;
char *buffer;
mm_segment_t fs;
int ret;

printk(KERN_INFO "My module is loaded\n");
buffer = kmalloc(128, (GFP_ATOMIC));
memset(buffer, 0x00, 12;
//printk(KERN_INFO "buf:%s\n",buffer);


f = filp_open("/etc/Wireless/RT2870STA/RT2870STA.dat", O_RDONLY, 0);
if ((int)f == -2 || !f->f_op || !f->f_op->read)
printk(KERN_INFO "Error opening file\n");

if(f == NULL)
printk(KERN_ALERT "filp_open error!!.\n");
else{
// Get current segment descriptor
fs = get_fs();
// Set segment descriptor associated to kernel space
//set_fs(KERNEL_DS);
set_fs(get_ds());
// Read the file
ret=access_ok( VERIFY_WRITE, buffer, 128 );
printk(KERN_INFO "buffer write permission: %d\n",ret);
ret=access_ok( VERIFY_WRITE, f, 128 );
printk(KERN_INFO "file read permission: %d\n",ret);
ret=f->f_op->read(f, buffer, 2, &f->f_pos);
printk(KERN_INFO "Readed bytes %d\n",ret);
//printk(KERN_INFO "buf:%s\n",buffer);
// Restore segment descriptor
set_fs(fs);
// See what we read from file
//printk(KERN_INFO "buf:%s\n",buffer);
}
filp_close(f,NULL);
kfree(buffer);
return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "My module is unloaded\n");
}

When I compile it for my debian i386 everything works OK

dmesg output:

My module is loaded
buffer write permission: 1
file read permission: 1
Readed bytes 2

The problem appears when I cross-compile for an embedded PowerPC with kernel 2.6.16.11

Makefile
obj-m += module.o
all:
make ARCH=powerpc CROSS_COMPILE=/opt/eldk/usr/bin/ppc-linux- -C /usr/src/linux-2.6.16.11 M=/home/ricardo/modulo_kernel/ modules

clean:
make ARCH=powerpc CROSS_COMPILE=/opt/eldk/usr/bin/ppc-linux- -C /usr/src/linux-2.6.16.11 M=/home/ricardo/modulo_kernel/ clean

function f->f_op->read returns -14 and I cant read the file

this is my dmesg output:

My module is loaded
buffer write permission: 1
file read permission: 1
Readed bytes -14

Anybody can help me with this?