usb-skeleton.c query

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

 



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.

Shouldnt it be dev = kmalloc(sizeof(struct usb_skel), GFP_KERNEL)
instead of dev = kmalloc( sizeof(*dev), GFP_KERNEL)?

Or am i missing something here?

2. What does le16_to_cpu(...)  does?
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.

Any pointers or links will be appreciated.

TIA

Pradeep

--
play the game

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