Re: Re: Question abt piece of code in pci_Driver.c

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

 



On Fri, Feb 11, 2005 at 09:35:48AM -0000, rajesh  ms wrote:
> Hi,
> 
> > > 2)We are declaring const struct device_driver pointer and substracting
> > > the offset value (struct device_driver * is a member of struct
> > > pci_driver )and getting the address of struct pci_driver which may
> > > contain some data that is irrelevent to struct pci_driver. If this is
> > > the return value whether this will cause problems? How this is dealt
> > > in the code.
> >
> >Look at the definition of struct pci_driver.  It contains a struct
> >device_driver.  When passed a pointer to a struct device_driver, the
> >code "knows" that it is safe to treat it as a part of the struct
> >pci_driver.  So it moves backwards in memory to get the real pointer to
> >the struct pci_driver and everyone is happy.
> >
> >This convention is used a _lot_ in the driver model code in the kernel
> >to allow for "inheritance" in C.
> 
> Thanks Greg,
> But i am worried about the values that will be there in the pci_driver
> struct  before member struct device_driver. If they are used , I think
> it will cause troubles. Am i right? If so how it is handled?

I do not understand the question.  Please study how the pci_driver
struct is created, I think it will show that there isn't a problem here
(that, and the fact that the code is working :)

thanks,

greg k-h

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