Problems with copy from user in write method

Submitted by Anonymous
on January 2, 2009 - 11:07am

Hi,

I'm developing a small driver for a lcd display, but I have some slight problems with my code.
copy_from_user fails sometimes when I write to my char device - it happens very often if I do something like:
date > /dev/lcd

then I get:
Copy from user failed! Value Thu Jan 1 01:45:38 MET 1970

The mean thing is that it does happen only sporadicaly -- any ideas?
My code attached below.

lcd_write(struct file *filp,const char __user *buf, size_t count, loff_t *f_pos)
{
    void **blubb;
    int i=0;
    *f_pos+=count;
    blubb=kmalloc((count+1)*sizeof(char *),GFP_KERNEL);
    if(blubb==NULL)
    {
        printk (KERN_EMERG "Kmalloc failed!\n");
    }
    else
    {
        if(copy_from_user(blubb[0],buf,count))
        {
            for (i=0; i< count;i++)
            {
                iowrite8(buf[i],(void*) data_mmap); 
                udelay(2000);
                g_addr+=1;
               if(g_addr != 0 && g_addr%0x10 ==0)
                {
                printk (KERN_EMERG "AH VOLL\n");
                g_addr^=0x40;
                g_addr&=0xC0;
                iowrite8(g_addr,(void*) cmd_mmap); 
                udelay(2000);
                
                }
            }
        }
        else
        {
            printk("Copy from user failed! Value %s count %d\n",buf,count);
        }
        kfree(blubb);
    }
    return count;
}

copy_from_user

on
January 3, 2009 - 6:05am

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.