Re: writing to driver failed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 24, 2010 at 9:38 AM, sri <bskmohan@xxxxxxxxx> wrote:
> 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);

Also, copy_from_user returns the number of bytes which could NOT be written.

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.
>

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux