From patchwork Mon Feb 7 16:56:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 5794 Return-path: Envelope-to: mchehab@pedra Delivery-date: Mon, 07 Feb 2011 14:57:38 -0200 Received: from mchehab by pedra with local (Exim 4.72) (envelope-from ) id 1PmUPC-00062m-1q for mchehab@pedra; Mon, 07 Feb 2011 14:57:38 -0200 Received: from casper.infradead.org [85.118.1.10] by pedra with IMAP (fetchmail-6.3.17) for (single-drop); Mon, 07 Feb 2011 14:57:38 -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 1PmUOn-0005Pl-Jx; Mon, 07 Feb 2011 16:57:14 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754207Ab1BGQ5K (ORCPT + 1 other); Mon, 7 Feb 2011 11:57:10 -0500 Received: from mail-ew0-f46.google.com ([209.85.215.46]:39558 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754070Ab1BGQ5J (ORCPT ); Mon, 7 Feb 2011 11:57:09 -0500 Received: by ewy5 with SMTP id 5so2411036ewy.19 for ; Mon, 07 Feb 2011 08:57:07 -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:mime-version :content-type:content-disposition:user-agent; bh=7+xHQXxH6itOiLgfRS6ceDGN9Ril2CtlqC1qTimGRII=; b=jlOV9KUa/5KX0Au1G3LsJ3u+GYemEyv2kKHUbhg9VjkgjlvzOiS2wYe4Ndzlo+M7We C+9OMC5/AV15n5nztXE1GrY8MIf2oNEOBl0XoAD3NJsW+KPbqMxT4nzVpBvUI4+N3F9n b/g15UAwhtbFItl1xTSD/GybzcmXOPbGFkYjo= 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=vLiXpGo9lhd1jgVjfi11rdTDrkdNWlsyxzBx1rkaHwbqUbvgngQlGkDlx8jULaI00Z aOSeWyRqFs1IKa6/zX5+pdut2SJj7V6XkUaFPxKVRLwHBCnUjyu9ShqTJ++Q2ysvdv0i 76a9goUL9wTxx1jxtY+9xljhcJAakdo1iZ21I= Received: by 10.223.96.73 with SMTP id g9mr4551519fan.24.1297097827766; Mon, 07 Feb 2011 08:57:07 -0800 (PST) Received: from bicker ([212.49.88.34]) by mx.google.com with ESMTPS id n7sm1289267fam.11.2011.02.07.08.57.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 07 Feb 2011 08:57:05 -0800 (PST) Date: Mon, 7 Feb 2011 19:56:50 +0300 From: Dan Carpenter To: Mauro Carvalho Chehab Cc: Manu Abraham , Andreas Regel , Oliver Endriss , linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] [media] stv090x: handle allocation failures Message-ID: <20110207165650.GF4384@bicker> MIME-Version: 1.0 Content-Disposition: inline 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. Signed-off-by: Dan Carpenter --- Compile tested only. I'm not very familiar with this code. -- 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..85101e8 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,8 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, return &state->frontend; +err_remove: + remove_dev(state->internal); error: kfree(state); return NULL;