Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3560940pxb; Mon, 24 Jan 2022 12:14:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJz50wAG/1trxhKnrsvpwovg2eSXPIX21MGP6Elbh0+1KSxvpM27s0CSPTXaVkBlfIu7GQOU X-Received: by 2002:a62:3003:0:b0:4c1:6983:f1c3 with SMTP id w3-20020a623003000000b004c16983f1c3mr15067594pfw.20.1643055283806; Mon, 24 Jan 2022 12:14:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055283; cv=none; d=google.com; s=arc-20160816; b=QmybJzmK1PuM262AlpKemdWUnd09Wx2vi7wtjUurq/2rAunGyukKdYTHY9DGiBQBlM mleThxTLNUGBo7hnN8VaevOQvl7C3DyU4r/v2bWDePlX9RQ+taS6XcSVeGsgrn0/DhWP ExpRPBCYE1OXPx9r2mhHPOjloB+2yuOXGZsE+OcrX71JE8KSFF4IOCTYOr+psLNxdYGD Ul6c5GQIgROwJAzyu6RCEpjFOVzOg8AM0T8AlPbafS6GzgkCdA1U5+CDAnvCoUTSsjZS kZuuqPFKIFP186qPnY67LbCFomgdtdTJr6K2ukPDzXLQ2d9wN5UzyDX6aG6gJ44PZCq/ gBzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=57wrvu/TtD1ANv+PQ2riqMlOKICGFWq/LZzMvESCKms=; b=mljcPA3q1BtWeP+jCHJaOHUp8TKXPg6rezQSAMUfClYGoNhdsfpBJAKgvTyXnoasap AdttLO5MKnD72LOmQVMZyPPm6V8kaaH2DrWlfk1vEsVzlFVgMpDJmwkiwoTeSewfJBas ACS81vBgVRiJpPKReWqP3LTzfn6Fmsn/owTHff3Bzt4aPFKs0uN9bg8h1wNXcG2ATGjo NKKDWvCf7ZbPJiZ39TuUyb9xK/NGfE3o4XwG23/pl4IgYM3nLagO9sHnlFUjKTzJiKxx rCfI0FDpdUKJ4whh+UGNJT4cfPzXR1WbAQcubzrTfoS3Z/8HNauxd1ep2D+7R5tEsmk2 1ntg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VLys8Cu7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si303235pjz.24.2022.01.24.12.14.31; Mon, 24 Jan 2022 12:14:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VLys8Cu7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344932AbiAXTSA (ORCPT + 99 others); Mon, 24 Jan 2022 14:18:00 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:60874 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346074AbiAXTFD (ORCPT ); Mon, 24 Jan 2022 14:05:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 01C34B81215; Mon, 24 Jan 2022 19:05:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10983C340E5; Mon, 24 Jan 2022 19:04:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051100; bh=T7KWPVUlwwGeP3+Ec471D8gVEnDQ0SQYVaxxQ4HTt44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VLys8Cu7gsPs+jGEeW2h7gnUWY+/3UVB0+CqLKpH3Q3UhdQL5mLRS4lp5u/BkSktC Jkxdxl9KMVLPKKnNi/5iNsnSfaFYmjEz9sEKAoNKEhivYxW6KWuIxGk8/Tv+TLU/OD 3Wt/43dgp2w9LP8DIWX35NRu7iC8EIAEm2LZbNYM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , Dongliang Mu , syzkaller , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.14 037/186] media: em28xx: fix memory leak in em28xx_init_dev Date: Mon, 24 Jan 2022 19:41:52 +0100 Message-Id: <20220124183938.318318966@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit 22be5a10d0b24eec9e45decd15d7e6112b25f080 ] In the em28xx_init_rev, if em28xx_audio_setup fails, this function fails to deallocate the media_dev allocated in the em28xx_media_device_init. Fix this by adding em28xx_unregister_media_device to free media_dev. BTW, this patch is tested in my local syzkaller instance, and it can prevent the memory leak from occurring again. CC: Pavel Skripkin Fixes: 37ecc7b1278f ("[media] em28xx: add media controller support") Signed-off-by: Dongliang Mu Reported-by: syzkaller Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/em28xx/em28xx-cards.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c index 9747e23aad271..b736c027a0bd0 100644 --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c @@ -3386,8 +3386,10 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, if (dev->is_audio_only) { retval = em28xx_audio_setup(dev); - if (retval) - return -ENODEV; + if (retval) { + retval = -ENODEV; + goto err_deinit_media; + } em28xx_init_extension(dev); return 0; @@ -3417,7 +3419,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, dev_err(&dev->intf->dev, "%s: em28xx_i2c_register bus 0 - error [%d]!\n", __func__, retval); - return retval; + goto err_deinit_media; } /* register i2c bus 1 */ @@ -3433,9 +3435,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, "%s: em28xx_i2c_register bus 1 - error [%d]!\n", __func__, retval); - em28xx_i2c_unregister(dev, 0); - - return retval; + goto err_unreg_i2c; } } @@ -3443,6 +3443,12 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev, em28xx_card_setup(dev); return 0; + +err_unreg_i2c: + em28xx_i2c_unregister(dev, 0); +err_deinit_media: + em28xx_unregister_media_device(dev); + return retval; } /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */ -- 2.34.1