Re: writing to driver failed

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

 



On Fri, Sep 24, 2010 at 6:38 AM, sri <bskmohan@xxxxxxxxx> wrote:

> static int eater_write(struct file *file, const char *buf, size_t lbuf,
> loff_t *ppos)

>         actual_data_allowed_to_write = MAXSIZE - *ppos;

>         if(actual_data_allowed_to_write == 0)

Perhaps <= 0 is what you should check here, just in case?

>         {
>                 printk("Device has no space to write. format it\n");
>                 return(actual_data_allowed_to_write);
>         }

As John noted, you might want to return -ENOMEM, or something like that.


>         //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;

I believe that "else" would be faster than having a second comparison.
  What happens when
(actual_data_allowed_to_write == lbuf)  ?

>         data_written=copy_from_user(eater_space + *ppos, /* to */ \
>                                 buf, /* from */ \
>                                 data_to_copy);
>

Did you want to check (data_to_copy == data_written) ?

-- 
Alison Chaiken
(650) 279-5600  (cell)
             http://www.exerciseforthereader.org/
The only real deadline in life is the one where you actually die. -- Eliot D.

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