linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Vishnu Dasa <vdasa@vmware.com>
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	Jorgen Hansen <jhansen@vmware.com>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"acking@vmware.com" <acking@vmware.com>,
	"dtor@vmware.com" <dtor@vmware.com>,
	Pv-drivers <Pv-drivers@vmware.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH 3/3] VMCI: Fix some error handling paths in vmci_guest_probe_device()
Date: Thu, 24 Feb 2022 13:03:30 +0300	[thread overview]
Message-ID: <20220224100330.GO3943@kadam> (raw)
In-Reply-To: <85DB8130-D600-464E-9717-1A0AFE795EA7@vmware.com>

On Thu, Feb 24, 2022 at 06:53:10AM +0000, Vishnu Dasa wrote:
> 
> > On Feb 11, 2022, at 12:06 PM, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> > 
> > Le 11/02/2022 à 15:09, Dan Carpenter a écrit :
> >> On Thu, Feb 10, 2022 at 11:27:34PM +0100, Christophe JAILLET wrote:

> >> Whatever...  But where this really
> >> hurts is with:
> >> Alloc:
> >> 	if (vmci_dev->exclusive_vectors) {
> >> 		error = request_irq(pci_irq_vector(pdev, 1), ...
> >> Free:
> >> 	free_irq(pci_irq_vector(pdev, 1), vmci_dev);
> >> No if statement.  It works because it's the last allocation but it's
> >> confusing and fragile.
> > 
> > Agreed.
> 
> Sorry, I hope I'm not missing something obvious or misunderstanding the point.
> But I don't think the problem implied here exists?
> 
> If 'request_irq(pci_irq_vector(pdev, 0), ...' fails we goto err_disable_msi and there
> is no free_irq in this path.  If 'request_irq(pci_irq_vector(pdev, 1), ...' fails then we
> goto err_free_irq and we do 'free_irq(pci_irq_vector(pdev, 0), vmci_dev)'.  Note that
> this is for the previous one without the check for vmci_dev->exclusive_vectors.

It's not a bug, but it's bad style.

Ideally the allocation code and the free code should mirror each other
as much as possible.  If there is an if statement in the allocation code
we should copy that same if statement into the free code.  Even if we
can leave the if statement out, we should still include it for
readability.

Also if we add another allocation at the end of the function then we
will have to add the if statement back.  Maybe the person who adds the
if statement will forget.  So it's fragile.

regards,
dan carpenter


  reply	other threads:[~2022-02-24 10:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10 22:26 [PATCH 0/3] VMCI: Various fixes Christophe JAILLET
2022-02-10 22:27 ` [PATCH 1/3] VMCI: Fix the description of vmci_check_host_caps() Christophe JAILLET
2022-02-17  7:08   ` Vishnu Dasa
2022-02-10 22:27 ` [PATCH 2/3] VMCI: No need to clear memory after a dma_alloc_coherent() call Christophe JAILLET
2022-02-17  7:10   ` Vishnu Dasa
2022-02-10 22:27 ` [PATCH 3/3] VMCI: Fix some error handling paths in vmci_guest_probe_device() Christophe JAILLET
2022-02-11 14:09   ` Dan Carpenter
2022-02-11 20:06     ` Christophe JAILLET
2022-02-24  6:53       ` Vishnu Dasa
2022-02-24 10:03         ` Dan Carpenter [this message]
2022-02-24 16:08           ` Vishnu Dasa
2022-02-24  0:43   ` Vishnu Dasa

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=20220224100330.GO3943@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=Pv-drivers@vmware.com \
    --cc=acking@vmware.com \
    --cc=arnd@arndb.de \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dtor@vmware.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhansen@vmware.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vdasa@vmware.com \
    /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).