From patchwork Thu Aug 12 07:46:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 4213 Return-path: Envelope-to: mchehab@pedra Delivery-date: Thu, 12 Aug 2010 11:03:06 -0300 Received: from mchehab by pedra with local (Exim 4.72) (envelope-from ) id 1OjYN6-0004vT-0H for mchehab@pedra; Thu, 12 Aug 2010 11:03:05 -0300 Received: from bombadil.infradead.org [18.85.46.34] by pedra with IMAP (fetchmail-6.3.17) for (single-drop); Thu, 12 Aug 2010 11:03:03 -0300 (BRT) Received: from vger.kernel.org ([209.132.180.67]) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1OjSV5-0002e4-CV; Thu, 12 Aug 2010 07:46:55 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758857Ab0HLHqk (ORCPT + 1 other); Thu, 12 Aug 2010 03:46:40 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:54960 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758819Ab0HLHqi (ORCPT ); Thu, 12 Aug 2010 03:46:38 -0400 Received: by wwj40 with SMTP id 40so1197578wwj.1 for ; Thu, 12 Aug 2010 00:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=VLqvfO0i9EqQqpymQcB+Nn53+BN8BcLydkBSMnuaWJM=; b=mDrgljVayzysiHR/WU9AReDsEz4gaP6YDYNyLyGqWRUoSmngRZjcJ2B+O3iQKkkjVU OyY8T13JrWcSo2U1MSp4EzCXIelUH/1BtbpG5DyjeyEm2Ia3EjvBzK0L2sQHpyNmBTSg VCy25mtgZCyqXM4/gfoUjYcfIJvj1feIM4yVk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=Ccd2izhj7LXoQx80jxI3iWIcaRoomUHQa0kFpqQp7BFdBGa/1mkwHdKAWq9sZZhORp qoO/Quzsune72sM3q0f5vR5vsmu4TKJtFMmFmztJhNETJu/tFvclep4KnoTLFDKiJ8dy MCKzTGyCC6JdalrDDDaXrZT3zo2zrPYyfCoVs= Received: by 10.216.10.11 with SMTP id 11mr6381483weu.64.1281599196887; Thu, 12 Aug 2010 00:46:36 -0700 (PDT) Received: from bicker ([205.177.176.130]) by mx.google.com with ESMTPS id v44sm619743weq.4.2010.08.12.00.46.27 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 12 Aug 2010 00:46:36 -0700 (PDT) Date: Thu, 12 Aug 2010 09:46:11 +0200 From: Dan Carpenter To: Maxim Levitsky Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] IR: ene_ir: problems in unwinding on probe Message-ID: <20100812074611.GI645@bicker> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Sender: Mauro Carvalho Chehab There were a couple issues here. If the allocation failed for "dev" then it would lead to a NULL dereference. If request_irq() or request_region() failed it would release the irq and the region even though they were not successfully aquired. Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe linux-media" 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/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c index 5447750..8e5e964 100644 --- a/drivers/media/IR/ene_ir.c +++ b/drivers/media/IR/ene_ir.c @@ -781,21 +781,24 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) /* allocate memory */ input_dev = input_allocate_device(); + if (!input_dev) + goto err_out; ir_props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL); + if (!ir_props) + goto err_input_dev; dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL); - - if (!input_dev || !ir_props || !dev) - goto error; + if (!dev) + goto err_ir_props; /* validate resources */ error = -ENODEV; if (!pnp_port_valid(pnp_dev, 0) || pnp_port_len(pnp_dev, 0) < ENE_MAX_IO) - goto error; + goto err_dev; if (!pnp_irq_valid(pnp_dev, 0)) - goto error; + goto err_dev; dev->hw_io = pnp_port_start(pnp_dev, 0); dev->irq = pnp_irq(pnp_dev, 0); @@ -804,11 +807,11 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) /* claim the resources */ error = -EBUSY; if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME)) - goto error; + goto err_dev; if (request_irq(dev->irq, ene_isr, IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev)) - goto error; + goto err_region; pnp_set_drvdata(pnp_dev, dev); dev->pnp_dev = pnp_dev; @@ -816,7 +819,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) /* detect hardware version and features */ error = ene_hw_detect(dev); if (error) - goto error; + goto err_irq; ene_setup_settings(dev); @@ -889,20 +892,22 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) error = -ENODEV; if (ir_input_register(input_dev, RC_MAP_RC6_MCE, ir_props, ENE_DRIVER_NAME)) - goto error; - + goto err_irq; ene_printk(KERN_NOTICE, "driver has been succesfully loaded\n"); return 0; -error: - if (dev->irq) - free_irq(dev->irq, dev); - if (dev->hw_io) - release_region(dev->hw_io, ENE_MAX_IO); - input_free_device(input_dev); - kfree(ir_props); +err_irq: + free_irq(dev->irq, dev); +err_region: + release_region(dev->hw_io, ENE_MAX_IO); +err_dev: kfree(dev); +err_ir_props: + kfree(ir_props); +err_input_dev: + input_free_device(input_dev); +err_out: return error; }