[ltp] Segmentation fault in PCI module
sensors
linux-thinkpad@linux-thinkpad.org
Thu, 07 Oct 2004 13:49:08 +0000
Hi Matt Graham and Matthias
Thanks.......................
That silly mistake was making my life hell.
Now I have resolved the problem...............
But one more thing, with this method I am unable detect the PCI bridges,ISA bridges,UBS ect......
But when I do a lspci these things gets displayed.....
What will I have to do to detect these special PCI devices also....
Thanks................
>-----Original Message-----
>From: Matt Graham [mailto:danceswithcrows@usa.net]
>Sent: Thursday, October 7, 2004 11:06 AM
>To: linux-thinkpad@linux-thinkpad.org
>Subject: Re: [ltp] Segmentation fault in PCI module
>
>> I have written a piece of code to detect a pci device, but it is
>> causing segmentation fault. What might have gone wrong in the
>> code?
>
>> #include<linux/pci.h>
>/* snip */
>> int pci_init( void )
>> {
>> struct pci_dev *pci_device = NULL; /* initial */
>
>> if( !pci_present() ){
>> printk("\nPCI not supported\n");
>> return 0;
>> }
>> if(( pci_find_slot(1, PCI_DEVFN( 9, 0))) == NULL){
>> printk("\n Device not found\n");
>> return 0;
>> }
>> printk("\nVendor ID\t%x",pci_device->vendor);
>
>Hang on. Did you ever assign a value to pci_device between "initial" and when
>you printk() the vendor ID? If not, it'll still be NULL, and dereferencing
>NULL is an instant segfault. Confirm this with
>"printk("pci_device=%x\n",pci_device);" before you dereference pci_device.
>And you might want to get some more practice with userspace things before
>moving to kernel code. HTH,
>
>
>--
>Matt G / Dances With Crows
>There is no Darkness in Eternity/But only Light too dim for us to see
>"I backed up my brain to tape, but tar says the tape contains no data...."
>
>
>--
>The linux-thinkpad mailing list home page is at:
>http://mailman.linux-thinkpad.org/mailman/listinfo/linux-thinkpad
>