On Monday 16 October 2006 06:55, pradeep singh wrote: > Hi all > I was reading the sample code for usb-skeleton.c and i need to clear > somethings. > > 1. in skel_probe() > 247 struct usb_skel *dev = NULL; > ... > 254 /* allocate memory for our device state and initialize it */ > 255 dev = kmalloc(sizeof(*dev), GFP_KERNEL); > 256 if (dev == NULL) { > 257 err("Out of memory"); > 258 goto error; > 259 } > ... > > struct usb_skel *dev = NULL on line no. 247 but when we allocate > memory for it we didnt use it like > dev = kmalloc(sizeof(struct usb_skel), GFP_KERNEL) > instead we are using kmalloc(sizeof(*dev), GFP_KERNEL). Had it been > allocated initially and then using *dev somewhere is understandable. > but using *dev before allocating dev seems weird. sizeof(*dev) doesn't really dereference dev. It just returns the size of whatever dev would point to. > 2. What does le16_to_cpu(...) does? Converts a 2-byte (16-bit) number in little-endian to whatever byte order the CPU uses. > Is it necessary to use it here? > 278 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); > What is the significance of it. Tried going through source but couldnt > make out much. -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/