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

Re: RE: Error in creating a slab cache.



On Thu, 09 Sep 2004 manish regmi wrote :
>>Hi,
>>  I have been trying to write a module that creates a slab cache and then add some objects to it through /proc/testing_slab and then trying to delete them and destroy the cache while unloading the module.
>>   I am having trouble using the list_* group of API's
>>I have used current_object as a global variable but its not retaining the value when used in another function and even the list that had been made using the list_add() is showing junk values.
>>  and when i am trying to unload it, it causes a kernel oops.
>>
>>I am attaching the code and Makefile along with this mail.
>>Please advice.
>>
>>Thanks and Regards,
>>Naren
>>
>
>HI,
>The problem is that you are using uninitialised memory.
>
>You must first allocate. use kalloc();
>you have used:
>struct list_head *p;
>  struct test_slab *tmp;
>
>global test_slab s seem to be allocated nowhere.
>
>and other places too.
>
>and another suggestion dont use such large arrays as local variable in kernel modules.
>The kernel stack is scarce (8k and 4k in x86). so use kmalloc.
>you have.
>char my_buffer[180];
>char mesg_ins[80];
>  char mesg_del[80];
>
>regards manish

Hi,
Thanks a lot manish for your suggestions, i am able to move ahead a little bit.. but the problem is still not solved. It seemed now that head and slab_object are sharing the same memory. How can that be possible when i am allocating using kmem_cache_alloc() ?

The code snippet is as follows:

       slab_object = kmem_cache_alloc(test_struct_cachep, GFP_KERNEL);
                        if (!slab_object)
                                return -ENOMEM;
               ==>      strcpy(slab_object->word, mesg_ins);
                        printk("HEAD points to :  %s\n",head->word);

after the strcpy both head->word and slab_object->word points to the same things while just before that strcpy() they both point to the different strings.

Sorry for being so naive. Please Advice.
The code is attached with this mail.

Thanks and Regards,
Naren

ps: Also while removing the module the kernel give an oops, i couldn't figure out the reason for that.

Attachment: problem.c
Description: Binary data

Attachment: Makefile
Description: Binary data