Re: Another different problem with list_head

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

 



On 8/31/05, Vincenzo Mallozzi <vinjunior@xxxxxxxx> wrote:
> 
> struct mtpmc_pages{
>    struct list_head list;
>    unsigned long addr;
>    char page[PAGE_SIZE];
> };
> 
> struct mtpmc_mm_struct{
>    .......
>    struct list_head pages_list;
> };
> 
> struct mtpmc_mm_struct  mtpmc_dump_memory_descriptor(struct mm_struct *mm)
> {
>    struct mtpmc_mm_struct md;
>    struct list_head *temp_list;
>    struct mtpmc_wrprotected_pages *wrpage;
>    pte_t *pte;
>    struct page *page;
>    struct mtpmc_pages *temp_page;
> 
>    INIT_LIST_HEAD(&md.pages_list);
>    for (each address "address" we need) do{
>        temp_page = (struct mtpmc_pages*) vmalloc(sizeof(struct mtpmc_pages));
>        INIT_LIST_HEAD(&temp_page->list);

the above INIT_LIST_HEAD is unnecessary as you are adding the
temp_page->list to md_pages_list (I m assuming this is the global
variable of list_head) and temp_page->list is it-self not a list's
head but only a element ....... And you might have to reconsider that
you need to do INIT_LIST_HEAD on the md_pages_list eaqch time when u
call mtpmc_dump_memory_descriptor function !!!!  it will remove the
previous list and you won't be able to free the memory associated with
the list (or u might be freeing the memory before calling
mtpmc_dump_memory_descriptor function again) ......

>        temp_page->addr = address;
>        mtpmc_read_page(address, temp_page->page);/*this fills the "page"
>                                                field" of temp_page */
>        list_add(&temp_page->list, &md.pages_list);

Consider this tooo that you are adding element to the start of the
list not to the end ....

>    }
> 
>    return md;
> }
> 

> void other_function()
> {
>    struct list_head *temp_list;
>    struct mtpmc_pages *temp_page;
>    struct mtpmc_mm_struct md =mtpmc_dump_memory_descriptor(mm);
> 
>    printk(KERN_DEBUG "mtpmc:listing addresses added\n");
>    list_for_each(temp_list, &md.pages_list){
>        temp_page = list_entry(temp_list, struct mtpmc_pages, list);
>        printk(KERN_DEBUG "mtpmc: temp_page->addr = %08lx\n",
>                                        temp_page->addr);
>    }
>    return;
> }
> 
> 
> The problem is in other_function function where I only scan the list created
> in the previous function.
> If I do this scanning within the mtpmc_dump_memory_descriptor function after
> the creation of the list, the right elements are printed but in
> other_function fuction are listed more elements that the ones I've inserted
> in. And then segfault.
> I don't know where is the problem as the list seems to be well filled.

Can u tell the sequence of calling the above two functions ??? Are u
implementing any locking for accessing the list and these functions
are called from different places ??? and make sure that md.pages_list
will be global to access from other_function ....


-- 
Fawad Lateef

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