virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: KY Srinivasan <kys@microsoft.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"devel@linuxdriverproject.org" <devel@linuxdriverproject.org>,
	"virtualization@lists.osdl.org" <virtualization@lists.osdl.org>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Hank Janssen <hjanssen@microsoft.com>
Subject: Re: [PATCH ]:Staging: hv: Allocate the vmbus irq dynamically
Date: Tue, 15 Feb 2011 09:25:00 -0800	[thread overview]
Message-ID: <20110215172500.GC18437@suse.de> (raw)
In-Reply-To: <FB42D5CCD7B5934EB1827DB5ED9B850E07085DA1@TK5EX14MBXC104.redmond.corp.microsoft.com>

On Tue, Feb 15, 2011 at 04:53:41PM +0000, KY Srinivasan wrote:
> > > @@ -518,19 +534,23 @@ static int vmbus_bus_init(void)
> > >  	}
> > >
> > >  	/* Get the interrupt resource */
> > > -	ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
> > > -			  driver->name, NULL);
> > > -
> > > -	if (ret != 0) {
> > > -		DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d",
> > > -			   vmbus_irq);
> > > -
> > > +get_irq_again:
> > > +	vmbus_irq = vmbus_get_irq();
> > > +	if ((vmbus_irq < 0) || (prev_irq == vmbus_irq)) {
> > > +		printk(KERN_WARNING "VMBUS_DRV: Failed to allocate IRQ\n");
> > >  		bus_unregister(&vmbus_drv_ctx->bus);
> > > -
> > >  		ret = -1;
> > 
> > Please provide a "real" error code.
> 
> Will do.
> > 
> > >  		goto cleanup;
> > >  	}
> > > -	vector = VMBUS_IRQ_VECTOR;
> > > +	prev_irq = vmbus_irq;
> > > +
> > > +	ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
> > > +			  driver->name, NULL);
> > > +
> > > +	if (ret != 0)
> > > +		goto get_irq_again;
> > 
> > You just set up the potential for an endless loop.  You almost _never_
> > want to goto backwards in a function.  Please don't do this.
> 
> The loop is not endless. We need to take care of two conditions here:
> 1) From the point we selected an irq line to the point where we call
> request_irq(), it is possible that someone else could have requested
> the same line and so we need to close this window.
> 2) request_irq() may fail for reasons other than the fact that we
> may have lost the line that we thought we got.
> 
> So, while we loopback, we check to see if the irq line we got is the same 
> that we got before (refer to the check soon after the call
> to vmbus_get_irq()). This check would ensure that we would not loop
> endlessly.

That's very subtle, and easy to overlook.  So please don't do it.  Make
it obvious that you will not constantly loop, and again, don't call goto
backwards.  goto is for error handling only, unless you are writing
scheduler code, and you aren't doing that here.

Please rework your logic before resending this.

thanks,

greg k-h

  parent reply	other threads:[~2011-02-15 17:25 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-15 15:15 [PATCH ]:Staging: hv: Allocate the vmbus irq dynamically K. Y. Srinivasan
2011-02-15 15:59 ` Greg KH
2011-02-15 16:53   ` KY Srinivasan
2011-02-15 16:59     ` Hank Janssen
2011-02-15 17:22       ` Greg KH
2011-02-15 17:28         ` Hank Janssen
2011-02-15 19:09         ` Hank Janssen
2011-02-15 19:33           ` Greg KH
2011-02-15 17:25     ` Greg KH [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-02-15 19:55 [PATCH]: Staging: " K. Y. Srinivasan
2011-02-18 21:14 ` Greg KH
2011-02-18 22:00   ` KY Srinivasan
2011-02-18 22:07     ` Greg KH
2011-02-18 22:16       ` KY Srinivasan
2011-02-18 22:29         ` Greg KH
2011-02-19  0:56           ` KY Srinivasan
2011-02-19  1:02             ` Greg KH
2011-02-19  1:19               ` KY Srinivasan
2011-02-19 10:23 ` Thomas Gleixner
2011-02-19 14:34   ` KY Srinivasan
2011-02-19 15:12     ` Thomas Gleixner
2011-02-19 16:46       ` KY Srinivasan
2011-02-20 16:15         ` Thomas Gleixner
2011-02-21  3:43           ` KY Srinivasan
2011-02-21  3:50             ` Greg KH
2011-02-21 11:02             ` Thomas Gleixner
2011-02-21 14:40               ` KY Srinivasan
2011-02-21 14:51                 ` Thomas Gleixner
2011-02-21 15:43                   ` Greg KH
2011-02-23 19:16                   ` Greg KH
2011-02-23 19:22                     ` KY Srinivasan
2011-02-19  1:26 K. Y. Srinivasan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110215172500.GC18437@suse.de \
    --to=gregkh@suse.de \
    --cc=devel@linuxdriverproject.org \
    --cc=haiyangz@microsoft.com \
    --cc=hjanssen@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).