Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10479090ybi; Thu, 25 Jul 2019 00:01:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvedeziLVV5z9ZL75XZo/uORaNNMd1vxtSTtQUbd6TQsgHHnNSkQXU8RU0ScnWjKdRcLQ1 X-Received: by 2002:a17:902:8205:: with SMTP id x5mr90973217pln.279.1564038118798; Thu, 25 Jul 2019 00:01:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564038118; cv=none; d=google.com; s=arc-20160816; b=WNL7jhGKP8LQib3VHqKoOIPArZAV0PuzJB2iuHIleqN3nZA5r2SGAF9UP5eghnjVyB bxNeREIMKWrmuIzAsE0Wk508wf7w8TQ5MQHIpSpgcdm/bnyjcMaYr55pkyel3mP0Uw5i Z0DhGREsKdl62C/dHAutAFPPFOQCvjfVemiQ4D3Y5o5fRqPvhfcdDQz0eQyjSXG2sjUT jCIsaVFK/4GZmJ5DxrEtJzJhgsBMjocuA3PmO/4Dg7d7J4BrdG0thii2veeONS7I2dc2 FMdFd8NucjAf8fL/R9ZMHl9ZZEbK1hHI8qZCbYETObjkz1ypLVejlbMsoTLX3vqOnUr4 ruLQ== 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=OBSLuAzReyHltz5DmDkOVz+b4pt1Yktrvjgp5AWeC6E=; b=L5dR0D/fWfMrvMN2pKRRuPh7lCGdZdTmXG76sEDnPpSPJGrNSWyxJKyhq5X+3mgPSr U9FvS3qs4G+zdQBhMsiywNLkxfox7QRQp+flU05w1dd0BqsME61wdw0ljpa7jhTSClIr Q/wrfOr/HvhnLMna6m7ahukdIzr68JSoeQNwZA+psIRqQcwShc6kdWzYMBHjwfY9WcZI QmBRA5fNZ7QQNhZxE21vW3qmdI1Q4VijgSfzhkCzUnIl9kBV8zSWRYiuNhnSiQzC28sF hfu+BVJP+lr8CC4+VlHoELQi4maQ+oZ2ThA7V4CzEvOGopnK/8UZH1wxzBhc75YdnXT8 a8dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kycfTpfB; 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 g7si14009068plp.171.2019.07.25.00.01.44; Thu, 25 Jul 2019 00:01:58 -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=kycfTpfB; 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 S1728850AbfGYHBI (ORCPT + 99 others); Thu, 25 Jul 2019 03:01:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:34168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbfGYHBI (ORCPT ); Thu, 25 Jul 2019 03:01:08 -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 B13ED22ADA; Thu, 25 Jul 2019 07:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564038067; bh=ugyMF2EfQY4MlJK2bPQNjgsKvD78Jc/idypvrZesNVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kycfTpfBmvARacsQG9IVBCWiyzC6Ue2lqAtycEGURBprWehi/vMk9WajY3/tRS+LC 9z09gLWKcGOdHBvybm1zEuIfPqt1QBd2T3VYK4GRwmvzZj50fetoxyWCTdJD0a3/4N 9E4TVy3DJwlZmLdqJ6lQY7mpm9VHSMJPZPiZC/24= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Young Xiao <92siuyang@gmail.com>, "Lad, Prabhakar" , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.2 091/413] media: davinci: vpif_capture: fix memory leak in vpif_probe() Date: Wed, 24 Jul 2019 21:16:22 +0200 Message-Id: <20190724191741.555720549@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 64f883cd98c6d43013fb0cea788b63e50ebc068c ] If vpif_probe() fails on v4l2_device_register() and vpif_probe_complete(), then memory allocated at initialize_vpif() for global vpif_obj.dev[i] become unreleased. The patch adds deallocation of vpif_obj.dev[i] on the error path. Signed-off-by: Young Xiao <92siuyang@gmail.com> Acked-by: Lad, Prabhakar Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/davinci/vpif_capture.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c index 61809d2050fa..f0f7ef638c56 100644 --- a/drivers/media/platform/davinci/vpif_capture.c +++ b/drivers/media/platform/davinci/vpif_capture.c @@ -1376,6 +1376,14 @@ static int initialize_vpif(void) return err; } +static inline void free_vpif_objs(void) +{ + int i; + + for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) + kfree(vpif_obj.dev[i]); +} + static int vpif_async_bound(struct v4l2_async_notifier *notifier, struct v4l2_subdev *subdev, struct v4l2_async_subdev *asd) @@ -1645,7 +1653,7 @@ static __init int vpif_probe(struct platform_device *pdev) err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); if (err) { v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); - goto cleanup; + goto vpif_free; } while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { @@ -1692,7 +1700,9 @@ static __init int vpif_probe(struct platform_device *pdev) "registered sub device %s\n", subdevdata->name); } - vpif_probe_complete(); + err = vpif_probe_complete(); + if (err) + goto probe_subdev_out; } else { vpif_obj.notifier.ops = &vpif_async_ops; err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev, @@ -1711,6 +1721,8 @@ static __init int vpif_probe(struct platform_device *pdev) kfree(vpif_obj.sd); vpif_unregister: v4l2_device_unregister(&vpif_obj.v4l2_dev); +vpif_free: + free_vpif_objs(); cleanup: v4l2_async_notifier_cleanup(&vpif_obj.notifier); -- 2.20.1