[openib-general] more comments on cxgb3

Roland Dreier rdreier at cisco.com
Thu Feb 8 11:47:22 PST 2007


 > diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
 > index db2b0a8..98568ee 100644
 > --- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
 > +++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
 > @@ -99,6 +99,7 @@ static int iwch_dealloc_ucontext(struct 
 >  	struct iwch_dev *rhp = to_iwch_dev(context->device);
 >  	struct iwch_ucontext *ucontext = to_iwch_ucontext(context);
 >  	PDBG("%s context %p\n", __FUNCTION__, context);
 > +	free_mmaps(ucontext);
 >  	cxio_release_ucontext(&rhp->rdev, &ucontext->uctx);
 >  	kfree(ucontext);
 >  	return 0;
 > diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.h b/drivers/infiniband/hw/cxgb3/iwch_provider.h
 > index 1ede8a7..c8c07ee 100644
 > --- a/drivers/infiniband/hw/cxgb3/iwch_provider.h
 > +++ b/drivers/infiniband/hw/cxgb3/iwch_provider.h
 > @@ -199,6 +199,21 @@ struct iwch_mm_entry {
 >  	unsigned len;
 >  };
 >  
 > +static inline void free_mmaps(struct iwch_ucontext *ucontext)
 > +{
 > +	struct list_head *pos, *nxt;
 > +	struct iwch_mm_entry *mm;
 > +
 > +	spin_lock(&ucontext->mmap_lock);
 > +	list_for_each_safe(pos, nxt, &ucontext->mmaps) {
 > +		mm = list_entry(pos, struct iwch_mm_entry, entry);
 > +		list_del(&mm->entry);
 > +		kfree(mm);
 > +	}
 > +	spin_unlock(&ucontext->mmap_lock);
 > +	return;
 > +}

Since you only have one caller, I would suggest just open-coding the
deletion at the call-site (since that function is really too big to
inline if it ever grows another caller).  And I don't think you need
the locking either, since there better be no one else looking at the
context structure while you're in the process of freeing it.

Something like:

 	struct iwch_dev *rhp = to_iwch_dev(context->device);
 	struct iwch_ucontext *ucontext = to_iwch_ucontext(context);
	struct iwch_mm_entry *mm, *tmp;

 	PDBG("%s context %p\n", __FUNCTION__, context);
	list_for_each_entry_safe(mm, tmp, &ucontext->mmaps)
		kfree(mm);
 	cxio_release_ucontext(&rhp->rdev, &ucontext->uctx);
 	kfree(ucontext);
 	return 0;

 - R.




More information about the general mailing list