Re: Open return value - segmentation fault

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

 



On 9/9/05, Vijay Ram Chitrapu (RCVIJAYD) <cvijay@xxxxxxxxxxxxxxxxxx> wrote:
> Hi,
> I am sorry, i need to make a small correction. I am returning 1 in open
> when the segmentation faul occurs. If the return value is 0 it doesnt.
> Sorry for the mistake.
> 
> 
> On Fri, 9 Sep 2005, Vijay Ram Chitrapu (RCVIJAYD) wrote:
> 
> > Hi all,
> >   I have a query regarding the file descriptor obtained from the open
> > call. I have written a dummy driver code which has open, ioclt and release
> > file operations to it. In the open, i am returning 0. In the user space
> > when i open the device , i get an fd as 3. When i perform an ioctl with
> > the same fd  to the device, a segmentation fault of NULL pointer derefence
> > is thrown. I have tried return 1 in the open and everything worked well.
> > Can anyone please tell me in what way is the return value of open related
> > to the file descriptor.
> > The code is below for reference..
> >
> > static struct file_operations this_fops = {
> >       open:this_open,
> >       ioctl:this_ioctl,
> >       release:this_release,
> > };
> >
> > int this_open (struct inode *ino, struct file *fp)
> > {
> >  printk("<1> in open");
> >  return 0;
> > }
> >
> > int this_ioctl(struct inode * ino, struct file *fp, unsigned int cmd,
> > unsigned long len)
> > {
> >   printk("<1> in ioctl function);
> >   return 1;
> > }
> >
> >

The return 0 from the open/release is for success and other then
return 0 is the error .... so if you return 1 then the fd you got in
user space is not valid as the device failed to open ....

And the file desriptor is actually the internal representation of the
file with in the kernel .... and when you open the device it actually
initializes and fills the things related to device and other too if
needed by driver ....

You can consult Linux Device Driver 3rd Edition ... chapter 3  ...
page 58 for that  ....


-- 
Fawad Lateef

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           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