Re: [Outreachy kernel] Re: [PATCH v6] staging: unisys: visorhba: Convert module from IDR to XArray

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

 



On Tue, May 04, 2021 at 02:00:01PM +0300, Dan Carpenter wrote:
> On Tue, May 04, 2021 at 12:07:44PM +0200, Fabio M. De Francesco wrote:
> > -static void setup_scsitaskmgmt_handles(struct idr *idrtable, spinlock_t *lock,
> > -				       struct uiscmdrsp *cmdrsp,
> > +static int setup_scsitaskmgmt_handles(struct xarray *xa, struct uiscmdrsp *cmdrsp,
> >  				       wait_queue_head_t *event, int *result)
> >  {
> > -	/* specify the event that has to be triggered when this */
> > -	/* cmd is complete */
> > -	cmdrsp->scsitaskmgmt.notify_handle =
> > -		simple_idr_get(idrtable, event, lock);
> > -	cmdrsp->scsitaskmgmt.notifyresult_handle =
> > -		simple_idr_get(idrtable, result, lock);
> > +	int ret;
> > +	u32 id;
> > +
> > +	/* specify the event that has to be triggered when this cmd is complete */
> > +	ret = xa_alloc_irq(xa, &id, event, xa_limit_32b, GFP_KERNEL);
> > +	if (ret == 0)
> > +		cmdrsp->scsitaskmgmt.notify_handle = id;
> > +	else
> > +		return ret;
> 
> Reverse the condition.  Always do error handling, not success handling.
> Try keep the success path at one tab indent and the failure path at two
> tab indents.
> 
> 	ret = xa_alloc_irq(xa, &id, event, xa_limit_32b, GFP_KERNEL);
> 	if (ret)
> 		return ret;
> 	cmdrsp->scsitaskmgmt.notify_handle = id;
> 
> 	ret = xa_alloc_irq(xa, &id, result, xa_limit_32b, GFP_KERNEL);
> 	if (ret) {
> 		xa_erase(xa, cmdrsp->scsitaskmgmt.notify_handle);

umm.  When you put these things right next to each other, it's obvious
that should be xa_erase_irq().

> > -static void cleanup_scsitaskmgmt_handles(struct idr *idrtable,
> > +static void cleanup_scsitaskmgmt_handles(struct xarray *xa,
> >  					 struct uiscmdrsp *cmdrsp)
> >  {
> > -	if (cmdrsp->scsitaskmgmt.notify_handle)
> > -		idr_remove(idrtable, cmdrsp->scsitaskmgmt.notify_handle);
> > -	if (cmdrsp->scsitaskmgmt.notifyresult_handle)
> > -		idr_remove(idrtable, cmdrsp->scsitaskmgmt.notifyresult_handle);
> > +	xa_erase(xa, cmdrsp->scsitaskmgmt.notify_handle);
> > +	xa_erase(xa, cmdrsp->scsitaskmgmt.notifyresult_handle);

If this code were even run, assuming the appropriate lockdep options
were enabled, xarray would point out that you were taking a lock with
interrupts enabled that was previously taken with interrupts disabled.
That's a good thing!  Because before, this code was deleting entries
from the IDR with _no_ locking.

So these should both be xa_erase_irq().

> > @@ -1096,8 +1085,6 @@ static void visorhba_remove(struct visor_device *dev)
> >  	scsi_remove_host(scsihost);
> >  	scsi_host_put(scsihost);
> >  
> > -	idr_destroy(&devdata->idr);
> 
> Do we not have to call xa_destroy()?

Correct.  We covered this in earlier iterations of this series and I
don't feel like typing out the explanation again.





[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux