Re: Clearning concepts mentioned in Linux Device Drivers

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

 



Hi Dinesh,
                 Please see reply inline.
 
Cheers.
Simith
 
Dinesh Ahuja <mdlinux7@xxxxxxxxxxx> wrote:

I am going through a book Linux Device Driver and I
find it very interesting and playing with the sample
device drivers. This is the best way to learn a device
driver concepts.

It always better to understand each example quoted by
Author as It may concepts clear.


I have a query regarding scull_follow function which
is being called and defined in main.c [ example
downloaded from Net].

/* Follow the list
*/
Scull_Dev *scull_follow(Scull_Dev *dev, int n)
{
printk("<1> The Scull_follow has been called \n");
printk("<1> The value of n is::%d\n",n);
while (n--) {
printk("The while Loop in Scull_follow has been
called \n");

if (!dev->next) {
printk("<1> The next data is NULL in
scull_follow \n");
dev->next = kmalloc(sizeof(Scull_Dev),
GFP_KERNEL);
memset(dev->next, 0, sizeof(Scull_Dev));
}

dev = dev->next;
continue;
}
return dev;
}

In this case, author has allocated a memory through
kmalloc for scull_devices and as per my understanding
kmalloc gives a block of contigous memory, so from
where this link list came into picture.

scull_devices = kmalloc(scull_nr_devs *
sizeof(Scull_Dev), GFP_KERNEL);


As per we are not intializing a *next data member of
the Scull_Dev structure.

[Simith] Memsetting to 0 is initialising "next"  to NULL.


Could any one clear my concepts as why we want
scull_follow?

Regards
Dinesh



________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/

Yahoo! India Matrimony: Find your life partner online.


[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