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:
> Hi all,
> I've another problem with list_head. This problem is different from the
> previous one I've encountered (I've resolved it).
> I've now the following code:
> 
> 
> 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;

this should be a pointer as your are returning it at the end of this function.

>     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);
>         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);
>     }
> 
>     return md;

here is the bug, you are retun the local structure, what does this
mean .... is it right, I dont think so.

-Gaurav

> }
> 
> 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.
> Thanks.
> Vincenzo Mallozzi.
> 
> 
> 
> 
> 
> ___________________________________
> Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
> http://mail.yahoo.it
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
>

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