static int slab_free_obj(kmem_cache_t *cachep, struct slab *slabp, void *objp) { if(cachep == NULL || slabp == NULL || objp == NULL) { return -1; } struct list_head *item = NULL; unsigned int objnr = obj_to_index(cachep, slabp, objp); if(objnr > cachep->obj_num) { return -2; } slab_bufctl(slabp)[objnr] = slabp->free; set_slab_free(slabp, objnr); dec_slab_use(slabp); /* move to the free list */ if(slabp->inuse == 0) { item = &(slabp->list); list_del(item); list_add(item, &(cachep->kmem_lists.free)); } inc_cache_free(cachep); return 0; }
int slab_free_obj(struct kmem_cache_t *cachep, struct slab *slabp, void *objp) { if(cachep == NULL || slabp == NULL || objp == NULL) return -1; struct list_head *item = NULL; unsigned int objnr = obj_to_index(cachep, slabp, objp); if(objnr > cachep->obj_num) return -2; slab_bufctl(slabp)[objnr] = slabp->free; slabp->free = objnr; slabp->inuse--; /* move to the free list */ if(slabp->inuse == 0) { item = &(slabp->list); list_del(item); list_add(item, &(cachep->lists.free)); } return 0; }