From patchwork Tue Feb 15 10:10:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 5886 Return-path: Envelope-to: mchehab@pedra Delivery-date: Tue, 15 Feb 2011 12:04:54 -0200 Received: from mchehab by pedra with local (Exim 4.72) (envelope-from ) id 1PpLWP-00070n-O0 for mchehab@pedra; Tue, 15 Feb 2011 12:04:54 -0200 Received: from casper.infradead.org [85.118.1.10] by pedra with IMAP (fetchmail-6.3.17) for (single-drop); Tue, 15 Feb 2011 12:04:53 -0200 (BRST) Received: from vger.kernel.org ([209.132.180.67]) by casper.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1PpHrf-00050x-8t; Tue, 15 Feb 2011 10:10:35 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753993Ab1BOKKd (ORCPT + 1 other); Tue, 15 Feb 2011 05:10:33 -0500 Received: from mail-bw0-f46.google.com ([209.85.214.46]:65409 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753868Ab1BOKKb (ORCPT ); Tue, 15 Feb 2011 05:10:31 -0500 Received: by bwz15 with SMTP id 15so270139bwz.19 for ; Tue, 15 Feb 2011 02:10:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=vOkdjUK3VQTHuLwfVFtbKM3U14fmHEJETa1UtGmwxVM=; b=AWAN76yV4M2ew29JlI+4qjouX8IXROdPZyIyUgxpg4bHKIuEiqQMdGjEFG2lazi9xq wi01MbArVHWEsYAFU9uCLu6DHUX6b/BuHh/ysneKO4BQyQqjLCdIhgdyVjwlltCbUmEF klYlnnXQ5ICZVS2sCmrkQX2mz2nhztT6KNcyA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=OtIjo1YH+MELTwHd7yIuInKAN3YW4bRY+0xtZuKIhRm3YOnOAAzpVgEE5E6Z+6Qkkb P1WB0AaRDnRpQ/9PAiLJqoBLdHDPArovyglToFZX62fa1/aKtnfoZ2LusNH2SMRNZ5mD xaYNr9rDB2BofRFVAdZSHeUo6DEnBeFsQQ7lA= Received: by 10.204.51.11 with SMTP id b11mr4802455bkg.129.1297764629313; Tue, 15 Feb 2011 02:10:29 -0800 (PST) Received: from bicker ([212.49.88.34]) by mx.google.com with ESMTPS id z18sm2459194bkf.20.2011.02.15.02.10.20 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Feb 2011 02:10:27 -0800 (PST) Date: Tue, 15 Feb 2011 13:10:08 +0300 From: Dan Carpenter To: Oliver Endriss Cc: Mauro Carvalho Chehab , Manu Abraham , Andreas Regel , linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch v2] [media] stv090x: handle allocation failures Message-ID: <20110215101008.GO4384@bicker> References: <20110207165650.GF4384@bicker> <201102150300.19650@orion.escape-edv.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <201102150300.19650@orion.escape-edv.de> User-Agent: Mutt/1.5.20 (2009-06-14) Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Sender: kmalloc() can fail so check whether state->internal is NULL. append_internal() can return NULL on allocation failures so check that. Also if we hit the error condition later in the function then there is a memory leak and we need to call remove_dev() to fix it. Also Oliver Endriss pointed out an additional leak that I missed in the first version of this patch. Signed-off-by: Dan Carpenter Acked-by: Oliver Endriss --- v2: Fix the leak Oliver noticed. -- 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/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c index d3362d0..41d0f0a 100644 --- a/drivers/media/dvb/frontends/stv090x.c +++ b/drivers/media/dvb/frontends/stv090x.c @@ -4783,7 +4783,13 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, } else { state->internal = kmalloc(sizeof(struct stv090x_internal), GFP_KERNEL); + if (!state->internal) + goto error; temp_int = append_internal(state->internal); + if (!temp_int) { + kfree(state->internal); + goto error; + } state->internal->num_used = 1; state->internal->mclk = 0; state->internal->dev_ver = 0; @@ -4796,7 +4802,7 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, if (stv090x_setup(&state->frontend) < 0) { dprintk(FE_ERROR, 1, "Error setting up device"); - goto error; + goto err_remove; } } @@ -4811,6 +4817,9 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, return &state->frontend; +err_remove: + remove_dev(state->internal); + kfree(state->internal); error: kfree(state); return NULL;