From patchwork Wed Feb 5 11:54:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Cox X-Patchwork-Id: 3585681 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 987A7C02DC for ; Wed, 5 Feb 2014 11:54:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D477D2016C for ; Wed, 5 Feb 2014 11:54:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0208320166 for ; Wed, 5 Feb 2014 11:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751532AbaBELyd (ORCPT ); Wed, 5 Feb 2014 06:54:33 -0500 Received: from earthlight.etchedpixels.co.uk ([81.2.110.250]:49133 "EHLO alan.etchedpixels.co.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751274AbaBELyc (ORCPT ); Wed, 5 Feb 2014 06:54:32 -0500 Received: from alan.etchedpixels.co.uk (localhost [127.0.0.1]) by alan.etchedpixels.co.uk (8.14.4/8.14.4/Debian-2.1ubuntu4) with ESMTP id s15BsYfb014448 for ; Wed, 5 Feb 2014 11:54:35 GMT Subject: [PATCH] pci: allocation check missing To: linux-pci@vger.kernel.org From: Alan Date: Wed, 05 Feb 2014 11:54:34 +0000 Message-ID: <20140205115412.14423.23707.stgit@alan.etchedpixels.co.uk> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/pci/msi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;