[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re: RE: Error in creating a slab cache.
On Sun, 12 Sep 2004 manish regmi wrote :
>>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.
>>
>
>hi,
>again head->word is not allocated. You are copying mesg_ins to it without allocating any space.
>strcpy(slab_object->word, mesg_ins);
>
>kmem_cache_alloc() only allocates space for sizeof(struct test_slab)
>You havent allocated for slab_object->data.
>use kmalloc here too.
>
>slab_object = kmem_cache_alloc(test_struct_cachep, GFP_KERNEL);
> if (!slab_object)
> return -ENOMEM;
> slab_object->word = kmalloc(20, GFP_KERNEL);
> strcpy(slab_object->word, mesg_ins);
> printk("HEAD points to : %s\n",head->word);
>
>But if you only want to point.use
>slab_object->word = &mesg_ins;
>
>slab_object = kmem_cache_alloc(test_struct_cachep, GFP_KERNEL);
> if (!slab_object)
> return -ENOMEM;
> slab_object->word = &mesg_ins;
> printk("HEAD points to : %s\n",head->word);
>
>more memory problems.
>Need more practices on pointers.:)
>
>regards manish
>
Hi,
Thanks a lot manish. Finally i was able to complete that program. And i guess you are right, I need a lot more practice in pointers.
Thanks and Regards,
Narinder