linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan <gnomes@lxorguk.ukuu.org.uk>
To: linux-pci@vger.kernel.org
Subject: [PATCH] pci: allocation check missing
Date: Wed, 05 Feb 2014 11:54:34 +0000	[thread overview]
Message-ID: <20140205115412.14423.23707.stgit@alan.etchedpixels.co.uk> (raw)

If we fail to allocate the name, just drop nicely into the fail path

(as a footnote someone who works on this code more might want to shuffle
 the allocations about so the name and attributes are allocated and freed
 as one. There seems to be no reason to keep them separate)

Signed-off-by: Alan Cox <alan@linux.intel.com>
---
 drivers/pci/msi.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 18ca2497..9bdf290 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -544,9 +544,13 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
 		return -ENOMEM;
 	list_for_each_entry(entry, &pdev->msi_list, list) {
 		char *name = kmalloc(20, GFP_KERNEL);
+		if (!name)
+		        goto error_attrs;
 		msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL);
-		if (!msi_dev_attr)
+		if (!msi_dev_attr) {
+		        kfree(name);
 			goto error_attrs;
+                }
 		sprintf(name, "%d", entry->irq);
 		sysfs_attr_init(&msi_dev_attr->attr);
 		msi_dev_attr->attr.name = name;


             reply	other threads:[~2014-02-05 11:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05 11:54 Alan [this message]
2014-02-11 23:28 ` [PATCH] pci: allocation check missing Bjorn Helgaas

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=20140205115412.14423.23707.stgit@alan.etchedpixels.co.uk \
    --to=gnomes@lxorguk.ukuu.org.uk \
    --cc=linux-pci@vger.kernel.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).