Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10480953ybi; Thu, 25 Jul 2019 00:03:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJXk566DoBOACavN+gJSUZGmqudo3O6pI7Fh2suIKyouNK6UkQjV0GobvpUGQCMUEwQs6S X-Received: by 2002:aa7:9a8a:: with SMTP id w10mr15100628pfi.66.1564038226649; Thu, 25 Jul 2019 00:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564038226; cv=none; d=google.com; s=arc-20160816; b=X/3Hw6Gio9WEi7RqKt76aLtSmOTa5r6F7dUgh2I99USOkvmecQ0iWQKMBWXRf9akQ3 Zx2jnX1hJrzofHTzr+koJrr7dzOTPXOAseSZ+m02Sxk4bldA9sHbjmt/tnyOy1sl+i3v hu0SypAzXoFVkGbRGNPLmEXdNA5K3U6YrehqalmOp9kM/TnMz0Fe1+wx2gZMVZXO4njE arKbdVZvxjCLrapt3eXMQISyZEwlCZS1jXpEs30XcL61BIIAPl+TBViZd3I9355ybBmm NgO1RpATEoR66oJattGAG+xv8mik2p4M9DWK12jBGtC3vIKmzyw6vuk+jzG2PlrPE6wd xgEg== 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=NPxGxJrKBhygfNx0sCKgEHGI5itGpdTJgMaY+NipwMY=; b=Cx15RFzCBeEknQ8uWI87an9VTCUdp/3SNaRDJq3YuSltkskNiC4JZydBbbDqNvc7Q5 EAi8v+E2ohonqaVNnrgcOlHGcD0LkMXciQJRcOqEBV5XpAiprcz96rrf/fM7kTHBGktt EZyQ1728+c2apdS5Qac0by+U2RCrgpTWNFsMpksg6F9bGg1qWs/TPB/wfiMmRZJu4q96 QAWyYnrcTEG7NJGtULmq9ICF+kOZdDL/z8ZWAjG/BoLZe4hmLsKpGWfitxuH0yodl2Us LBzvlcdVNwpVhm1mj5ntENbGha77dzZ2gxBlh6FkYSs7WmwmReIegKY18X27WFzj5pwG zYfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EhGwPSBp; 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 w4si16687734plz.323.2019.07.25.00.03.32; Thu, 25 Jul 2019 00:03:46 -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=EhGwPSBp; 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 S2387765AbfGYHBS (ORCPT + 99 others); Thu, 25 Jul 2019 03:01:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:34336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387726AbfGYHBQ (ORCPT ); Thu, 25 Jul 2019 03:01:16 -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 81A1422ADA; Thu, 25 Jul 2019 07:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564038076; bh=HVyIP4pqpAAyKHeHHpn/sATLGvpK5UjuHftXRZJkkuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EhGwPSBpAYPd9TJEL7PM0jy1QO5YZHn9ILZphK3OQ+tATvU+ExJTh1GdOcq6pCf87 rZFFQrjGuKZDgf2rmEjAcOwREVNHNIPdrCbSQEOIU+SzWRbjGUToGmmfBiAiMZ1wYa jIOAFd4QA2xsTV+W4Ubli9n6fb9eBN2LbVaJSFYY= 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.1 084/371] media: davinci: vpif_capture: fix memory leak in vpif_probe() Date: Wed, 24 Jul 2019 21:17:16 +0200 Message-Id: <20190724191731.166419727@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191724.382593077@linuxfoundation.org> References: <20190724191724.382593077@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 6216b7ac6875..a20cb6fff2ec 100644 --- a/drivers/media/platform/davinci/vpif_capture.c +++ b/drivers/media/platform/davinci/vpif_capture.c @@ -1384,6 +1384,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) @@ -1653,7 +1661,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))) { @@ -1700,7 +1708,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, @@ -1719,6 +1729,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