Fixed it , was my silly mistake :( apologies to all. Shall be vigilant about such silly mistakes in future. Thank you On 10/18/06, pradeep singh <2500.pradeep@xxxxxxxxx> wrote:
hi all below is my code for he probe.Problem is it does not returns:( .What am i doing wrong? Moreover can somebody help me out with kref_init() and family for reference counting? Do i need to call kref_get() after i initialise my structure properly in probe or only kref_init() will do? ====== usbio.c=========== #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include "usbio.h" MODULE_LICENSE("GPL"); MODULE_AUTHOR("pradeep"); static int usbio_probe(struct usb_interface* iface,const struct usb_device_id* id ) { printk(KERN_DEBUG "usbio_probe called...\n"); int retvalue, i; size_t buf_size; struct usb_device* udev = interface_to_usbdev(iface); struct myusbio_device* dev = NULL; struct usb_host_interface* iface_desc = NULL; struct usb_endpoint_descriptor* endpoint = NULL; dev = kmalloc(sizeof(*dev), GFP_KERNEL); if(!dev) { printk(KERN_ERR "out of mem in %s ",__FUNCTION__); return -ENOMEM; } memset(dev, 0x00, sizeof(*dev)); kref_init(&dev->usbio_kref); printk(KERN_DEBUG "After memset in probe...\n"); iface_desc = iface->cur_altsetting; printk(KERN_DEBUG "Printing Debug information...\n \ iface_desc->desc.bNumEndpoints = %d, bAlternateSetting = %d",\ iface_desc->desc.bNumEndpoints,iface_desc->desc.bAlternateSetting); for( i = 0; iface_desc->desc.bNumEndpoints; i++ ) { endpoint = &iface_desc->endpoint[i].desc; if( !dev->bulk_in_endpointaddr && (endpoint->bEndpointAddress & USB_DIR_IN ) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { printk(KERN_DEBUG "Found a bulk in endpoint at i = %d:)\n", i); buf_size = endpoint->wMaxPacketSize; dev->bulk_in_size = buf_size; dev->bulk_in_endpointaddr = endpoint->bEndpointAddress; dev->bulk_in_buffer = kmalloc(buf_size, GFP_KERNEL); if(!dev->bulk_in_buffer) { printk(KERN_ERR "out of mem for bulk in buffer\n"); retvalue = -ENOMEM; goto ERROR; } } if( !dev->bulk_out_endpointaddr && !(endpoint->bEndpointAddress & USB_DIR_IN ) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { printk(KERN_DEBUG "Found a bulk out endpoint at i = %d\n", i); dev->bulk_out_endpointaddr = endpoint->bEndpointAddress; } printk(KERN_DEBUG "After finding the endpoints \n"); dev->usb_device = usb_get_dev(udev); usb_set_intfdata(iface, dev); printk(KERN_DEBUG "Registering the driver as a char device\n"); retvalue = usb_register_dev(iface, &usbio_class); if(retvalue) { usb_set_intfdata(iface, NULL); printk(KERN_ERR "Cannot register usb device as a char dev :("); goto ERROR; } // kref_get(&dev->usbio_kref); /*Do i need this?*/ //create sysfs attribs here for reading and writing to the port printk(KERN_DEBUG "Exiting probe...\n"); printk(KERN_DEBUG "usbio now bound to usbio-device-%d", iface->minor); return 0; ERROR: if(dev) { kref_put(&dev->usbio_kref, usbio_clean); } return retvalue; } static void usbio_clean(struct kref* ref) { struct myusbio_device* dev = NULL; dev = to_myusbio_device(ref); usb_put_dev(dev->usb_device); if(dev) { kfree(dev->bulk_in_buffer); kfree(dev); } } static void usbio_disconnect(struct usb_interface* iface) { printk(KERN_DEBUG "usbio_disconnect called ...\n"); struct myusbio_device* dev = NULL; int minor = iface->minor; int val; // lock_kernel(); dev = usb_get_intfdata(iface); usb_set_intfdata(iface, NULL); usb_deregister_dev(iface, &usbio_class); // unlock_kernel(); val = kref_put(&dev->usbio_kref,usbio_clean); printk(KERN_DEBUG "val fomr kref_put = %d", val); printk(KERN_DEBUG "Device with minor -%d is free now", minor); } static int usbio_open(struct inode* inode, struct file* filp) { printk(KERN_DEBUG "Entering %s", __FUNCTION__); return 0; /*TODO success*/ } static ssize_t usbio_read(struct file* filp, char __user* buf, size_t count, loff_t* f_pos) { printk(KERN_DEBUG "Entering %s", __FUNCTION__); /*TODO*/ return 0; } static int usbio_init(void) { printk(KERN_DEBUG "Inside usbio_init...\n"); int val; val = usb_register(&usbio_driver); if(val) { printk(KERN_ERR "usb_register failed with Error No. %d",val); } return val; } static void usbio_exit(void) { printk(KERN_DEBUG "exiting usbio module...\n"); usb_deregister(&usbio_driver); } module_init(usbio_init); module_exit(usbio_exit); What am i doing wrong in probe? Also open, read and write need to be implemented. Please ignore them, doubt is specific to probe only... It doesnot come out of the for loop itself. What may be the reason? Another doubt. Can i device have all 4 types of endpoints? If so, do i necessarily take care of all of these in my code? or shall i just worry about which endpoints i will use? Thank you -- play the game
-- play the game -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/