[Suzaku-en:00501] Re: uartlite problems again

Yasushi SHOJI email@hidden
Thu Nov 15 16:36:34 JST 2007


At Wed, 14 Nov 2007 20:43:00 +0100,
Muis, A. wrote:
> 
> shouldnt you free your kbuf in your write function?

that should be it. as the back trace is pointing out it's getting OOM.

> Call backtrace:
> C008ACF4 C0034FF4 C00026FC 10000380 30025D44 30025D90 00000000
> __alloc_pages: 0-order allocation failed (gfp=0xf0/0)

0-order means a page (4kb), which is the smallest allocation size.

> ssize_t fpga_write(struct file *filp, unsigned char *buf, size_t
> count, loff_t *f_pos)
> {
>         unsigned char *kbuf, *ptr;
>         kbuf = kmalloc(count, GFP_KERNEL);
> 
>         int ret = copy_from_user(kbuf, buf, count);
> 
>         void* location = ioremap(FPGA_BASE, (long)count);

you have ioremaped in fpga_init(), so you dont need to do it
again. plus, count is the size of valid byte in the buf from
userland.  so ioremapping with count size is wrong.

>         int i;
> 
>         for(i = *f_pos; i < count + *f_pos; i++)
>         {
>                 writeb(kbuf[i - *f_pos], location + i);
>         }

	/* here you need to free the kbuf */
	kfree(kbuf);

>         iounmap(location);
>         return 0;
> }
> 
> struct file_operations fpga_fops = {
	/* dont you need open? */
	.open = fpga_open,
>     .owner = THIS_MODULE,
>     .read  = fpga_read,
>     .write = fpga_write,
> 
> };
> 
> static int fpga_init(void)
> {
>         int result = register_chrdev(250, "fpga", &fpga_fops);
>        // int result = register_chrdev_region(
>         io_base = ioremap(FPGA_BASE, FPGA_MAX - FPGA_BASE);
>         printk(" **Driver FPGA cargado**: %d\n",result);
>         return 0;
> }
> 
> static void fpga_exit(void)
> {
>         printk("Closing register driver.\n");
> }


better to cleanup what you have done in the init().  iounmap() and
unregister from char dev will be good.
-- 
          yashi



More information about the suzaku-en mailing list