Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9985054ybi; Wed, 24 Jul 2019 13:33:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBkG9lbLx+vpWfsFo8ZPTzrvgz6vNLwFWT+x8xMt83zz8K29X7o9Mmj9OLNp98Bo3nngyo X-Received: by 2002:a17:902:684f:: with SMTP id f15mr87648162pln.332.1564000421492; Wed, 24 Jul 2019 13:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000421; cv=none; d=google.com; s=arc-20160816; b=p6eFWe9HDQtnG169BxUYXuCkFPoXgvINtyS5MDh7JMgd4Ifqi0uNdIGFCGiOTa+TOq ENQtMfdbLbfxiswl/9FoOIUEFBZ5PmN4QKGI2aFuOrcGwje641P2ysxUsQVB0aoBJpm3 5ZJ0NRsf0zIPx5ABXQIJDmZtgKFHkWQx8Kr13ZcsPu07hccXk+7MU8YfIBNg9yRTOEsE 4GfJcA1nrB862nvBe48l54WjMDS2EHwV5ZGEFm94qsqGMF8BiTPhPOSQrqmrfSz2w+Dx pKKCKginXBYg+DEhM4pHaXpFGCQFrNARYdA+yesAOX+qC9peYyjIdYY0WpLDCPwNKfgP rOZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2QYyu4OmSeMC9s5Rs6+EJwgrVCFVvdA8P8EhWG05Q00=; b=QaXfclS4qLyW+otj4npIm/Qo3eLWderBM7ITsXk1PP2Wj/2cSxGlCplWPc2OIIKq8m wHo4QRuPmwSaqYZkKP8YdAl640btQioRhfhmRsvvjV+kp4Vx7a/I5JyJqUrLu0tgBtkS 5KAV/z+ByYRQUjEUZn9rT9QfHkeeowT/H1kHkRiCtkIFcQZZBC7B+u5RYEe61jL2qXjW 1y79qAZWVokOUR3mqD94k2lSqZXz6CZqHbvaXvms17jd5rMAEjKpyBWRBz3PvS3iGSl7 5g2h88wpQcmXdPfbcnpwx7tQc5d7B9fwDTqRFWiTdWa5/VY1PMTp35kzsJnlwHGwpLJT VZQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="a7z/0nLq"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j6si16999724pfi.240.2019.07.24.13.33.26; Wed, 24 Jul 2019 13:33:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="a7z/0nLq"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729307AbfGXUcL (ORCPT + 99 others); Wed, 24 Jul 2019 16:32:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:48524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388232AbfGXT3U (ORCPT ); Wed, 24 Jul 2019 15:29:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 00DBA229F4; Wed, 24 Jul 2019 19:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996560; bh=QtkRpwKIMS1MM1vlmnVIMgdWiexO38FlHliCMnS6Akc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a7z/0nLqQpT+cQLZiqoLzBQqjMf1O1E1EKPsIZKoUyrW/ElFUAsWd+39scZ0rkdbc QwAXib0wnafG1WacLFaDx//gk3JJHjk3aLsPD2m2FRMcmQw0xbFukepuREs15pyA5+ rLWyJcBAtanpVR0D2NtQoKciq0JCDm2sdvDPaiEE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.2 139/413] media: staging: davinci: fix memory leaks and check for allocation failure Date: Wed, 24 Jul 2019 21:17:10 +0200 Message-Id: <20190724191744.967613995@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit a84e355ecd3ed9759d7aaa40170aab78e2a68a06 ] There are three error return paths that don't kfree params causing a memory leak. Fix this by adding an error return path that kfree's params before returning. Also add a check to see params failed to be allocated. Signed-off-by: Colin Ian King Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/staging/media/davinci_vpfe/dm365_ipipe.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c index 30e2edc0cec5..b88855c7ffe8 100644 --- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c @@ -1251,10 +1251,10 @@ static int ipipe_s_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg) struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd); unsigned int i; int rval = 0; + struct ipipe_module_params *params; for (i = 0; i < ARRAY_SIZE(ipipe_modules); i++) { const struct ipipe_module_if *module_if; - struct ipipe_module_params *params; void *from, *to; size_t size; @@ -1265,25 +1265,30 @@ static int ipipe_s_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg) from = *(void **)((void *)cfg + module_if->config_offset); params = kmalloc(sizeof(*params), GFP_KERNEL); + if (!params) + return -ENOMEM; to = (void *)params + module_if->param_offset; size = module_if->param_size; if (to && from && size) { if (copy_from_user(to, (void __user *)from, size)) { rval = -EFAULT; - break; + goto error_free; } rval = module_if->set(ipipe, to); if (rval) - goto error; + goto error_free; } else if (to && !from && size) { rval = module_if->set(ipipe, NULL); if (rval) - goto error; + goto error_free; } kfree(params); } -error: + return rval; + +error_free: + kfree(params); return rval; } -- 2.20.1