On Sat, Sep 25, 2010 at 12:46 AM, John Mahoney <jmahoney@xxxxxxxx> wrote:
On Fri, Sep 24, 2010 at 9:38 AM, sri <bskmohan@xxxxxxxxx> wrote:
Also, copy_from_user returns the number of bytes which could NOT be written.> My driver write routine is not working properly.
> As a result, when I do echo "123" > /dev/eater, the process is stopping and
> the control goes into an infinite loop.
> lsmod showed my driver was in use by 2 processes.
> Now if i want to forcefully remove my driver module from kernel, how to do
> that?
>
> Below is the write routine:
> static int eater_write(struct file *file, const char *buf, size_t lbuf,
> loff_t *ppos)
> {
> ÂÂÂÂÂÂÂ int actual_data_allowed_to_write;
> ÂÂÂÂÂÂÂ int data_written;
> ÂÂÂÂÂÂÂ int data_to_copy=0;
>
> ÂÂÂÂÂÂÂ printk("requested bytes to write: %d\n", lbuf);
>
> ÂÂÂÂÂÂÂ actual_data_allowed_to_write = MAXSIZE - *ppos;
>
> ÂÂÂÂÂÂÂ printk("allowed bytes to write: %d\n",
> actual_data_allowed_to_write);
>
> ÂÂÂÂÂÂÂ if(actual_data_allowed_to_write == 0)
> ÂÂÂÂÂÂÂ {
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ printk("Device has no space to write. format it\n");
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return(actual_data_allowed_to_write);
> ÂÂÂÂÂÂÂ }
>
> ÂÂÂÂÂÂÂ //if available space can accommodate data to write
> ÂÂÂÂÂÂÂ if(actual_data_allowed_to_write > lbuf)
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ data_to_copy=lbuf;
> ÂÂÂÂÂÂÂ //if available space can't accommodate date to write
> ÂÂÂÂÂÂÂ if(actual_data_allowed_to_write < lbuf)
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ data_to_copy=actual_data_allowed_to_write;
>
> ÂÂÂÂÂÂÂ printk("data_to_copy: %d\n", data_to_copy);
>
> ÂÂÂÂÂÂÂ data_written=copy_from_user(eater_space + *ppos, /* to */ \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ buf, /* from */ \
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ data_to_copy);
SO
data_written = data_to_copy - data_written;
> ÂÂÂÂÂÂÂ //update device memory with new position
> ÂÂÂÂÂÂÂ *ppos += data_to_copy;
> ÂÂÂÂÂÂÂ printk("\nWrote %d bytes\n", data_written);
>
> ÂÂÂÂÂÂÂ return(data_written);
> }
>
> Appreciate any help.
>
> /Sri.
>
--
--
ÂKrishna Mohan B