LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   lodable kernel module doubt... (https://www.linuxquestions.org/questions/programming-9/lodable-kernel-module-doubt-773922/)

Devika99 12-07-2009 02:50 AM

lodable kernel module doubt...
 
I had written a driver and it was working fine on FC11...

Then i tried that program on FC8 and observed that it hangs/crashes sometime after insertng the module (insmod) OR
at times after removing the module and again trying to insert the module...

Not sure what is wrong...the program or something else...

Can any1 plz help me??

Aquarius_Girl 12-07-2009 03:01 AM

Why don't u put some code for display ? It may be possible for someone to help u after that !!

Devika99 12-07-2009 03:10 AM

Here's the program...
// PCI driver

#define OUR_PCI_VENDER_ID 0x10b5
#define OUR_PCI_DEVICE_ID 0x9054

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/stat.h>
#include <linux/slab.h>
#include <asm/system.h>
#include <asm/io.h>
#include <linux/types.h>


Quote:

struct pci_card_driver {
void *mm_addr;
struct pci_dev *ppdev;
};

static struct pci_device_id our_pci_id_tb[] = {
{ OUR_PCI_VENDER_ID, OUR_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
},
{ 0, }
};
MODULE_DEVICE_TABLE (pci, our_pci_id_tb);
Quote:

static int init_module_probe(struct pci_dev *pdev, const struct pci_device_id *notused)
{
struct pci_card_driver *pci_ptr;
unsigned long mmio_start, mmio_end, mmio_len, mmio_flags, data, data1, data2, data3, data4, data_out, data5, k1;
int err;
u32 val;

pci_ptr = kmalloc(sizeof(*pci_ptr), GFP_KERNEL);
if (!pci_ptr)
return -ENOMEM;
memset(pci_ptr,0,sizeof(*pci_ptr));
pci_ptr ->ppdev =pdev;

err=pci_enable_device(pdev);
if(err)
{
printk(KERN_ERR "err: Cannot enable the device \n");
goto error;
}

else printk("Device enabled\n");

mmio_start = pci_resource_start(pdev, 2);
mmio_end = pci_resource_end(pdev, 2);
mmio_len = pci_resource_len(pdev, 2);
mmio_flags = pci_resource_flags(pdev, 2);

if(pci_request_regions(pdev, "pci_device"))
{
printk("Could not get PCI region\n");
err= -EBUSY;
goto err_disable;
}

pci_ptr ->mm_addr = NULL;

pci_set_drvdata(pdev,pci_ptr);

pci_ptr ->mm_addr = ioremap(mmio_start, mmio_len);

if(!(pci_ptr->mm_addr))
{
printk("Could not ioremap\n");
err= -EIO;
goto err_release_mem;
}

else
{
printk(" The ioaddr is %x \n", pci_ptr -> mm_addr);
printk(" ioaddress obtained \n");

val= readl(pci_ptr->mm_addr + 0x0000100C);
printk(" My value obtained is %u32 \n ", val);

return 0;

}

err_release_mem:
pci_release_regions(pdev);
pci_set_drvdata(pdev, NULL);
err_disable:
pci_disable_device(pdev);
error:
kfree(pci_ptr);
return err;
}
Quote:

static void __devexit remove_pci(struct pci_dev *pdev)
{
struct pci_card_driver *pci_ptr = pci_get_drvdata(pdev);
if (!pci_ptr)
{
printk("<1> sum BUG error");
BUG();
}
iounmap(pci_ptr->mm_addr);
pci_release_regions(pdev);
pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
kfree(pci_ptr);
}
Quote:

static struct pci_driver our_pci_driver = {
.name = "pci_device",
.probe = init_module_probe,
.remove = __devexit_p(remove_pci),
.id_table = our_pci_id_tb,
};
Quote:

static int __init pci_init(void)
{
printk(KERN_INFO "pci device_init\n");
return pci_register_driver(&our_pci_driver);
}


static void __exit pci_cleanup(void)
{
printk(KERN_INFO "pci device_cleanup\n");
pci_unregister_driver(&our_pci_driver);
}

module_init(pci_init);
module_exit(pci_cleanup);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Linux device driver for PCI card");

Aquarius_Girl 12-07-2009 03:14 AM

Does dmesg say anything special ? and it will be better if u edit u r post and put your code in the CODE tags !

Devika99 12-07-2009 03:18 AM

nop... nothng...it shows that the device has been initialized after insmod... and if i remove the module ,then it shows that module is exited....but after the thing crashes(hangs), nothing works...only way to get out is to reset the PC...n after that i m back to square 1..

Aquarius_Girl 12-07-2009 03:25 AM

Till u don't get a perfect answer, What u can do is to comment out the code where u have allocated memory with kmalloc and see if that memory allocation was the cause of the hanging ?

Devika99 12-07-2009 03:31 AM

But kmalloc worked perfectly fine when i used FC11....What can be the probable reason for this...

Aquarius_Girl 12-07-2009 03:34 AM

Is there some big kernel version difference between fedora 8 and fedora 11 ? Ok I agree this is a dumb question, I shall get back to you if I could find something on this !

Devika99 12-07-2009 03:41 AM

i don't know... for FC8 was 2.6.xx... dont remember about which FC11 i had....

Devika99 12-07-2009 04:35 AM

alright...thanks...


All times are GMT -5. The time now is 04:48 PM.