Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3574740pxb; Mon, 24 Jan 2022 12:34:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJz154m4jEBQ3N625EObknL3eMC3DR3S3GeZMqQPj5RJ2D5soBacJxqpUueaG1RJ+RFWLpPI X-Received: by 2002:a17:902:c111:b0:14b:528d:3745 with SMTP id 17-20020a170902c11100b0014b528d3745mr5728339pli.38.1643056486557; Mon, 24 Jan 2022 12:34:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643056486; cv=none; d=google.com; s=arc-20160816; b=bf5NNMcVxdbK5dVMOdlvzT+tW+G06FILE3hN2wPCZ1qlQ3c1uG3clo78tJg1OHpVc7 Fj/RThRw6zCI6aY7cgKa18dWoQbyD/4D43iflA8WEkAI3XszAeF6ZyLTUJafRu4fQe1H d+ksjufcddXkAErtD95O+0HrN6rWq+m52eXksn6Y9MGhC2PPc4bPNaskOLt7oTtIxUkT tidq/Ct7ZB7NEdvO7yxgqtDfzoIeYUCxp3O8nNRUzUXaLSqTR+qv4miBirNqkvHEd1LR ujW33rTVR7tzD64xhXT3GpsFwZbCsxSDJWJ1tH7PY0oJDZUKJk6fKzsmUh8ElifJon6H LGHQ== 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=CM3sv+gHMHB6edbgEJewkooqs3JqDCMD5S5CMRVFBSY=; b=XlKAmLWllRoVaA9J2bt3Stny/8yp+caTTtIo/9MMJyuVkpz0GQVsco0OZqcWquhBE6 fhq22nho9Wm8r1QQEK7AMw6Z017LC8inG7qIh8pVpdPqWj5An1yZurLETm7wTvh7Y+az cufkZZlpkwuDq04SU8NagMNQSPHgxk/XvFs8NapjXmFxpAhm0QLIQx6Ur2l7J0Cz1+aU hK6Vf9eploXBPcS1jh6F/uGNofsT8RptfHaA8cJc7E8vqKBEUAbH2+NcsNzWwSeNwBBO D2qQIZ8NVzC89l1i3BPl8m0WVm6Qu9XrE7OX+STemXngskttcwaTEp2ZWdmwbhRaabf9 p6Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Mkg9+6ue; 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 1si13983521pgy.765.2022.01.24.12.34.25; Mon, 24 Jan 2022 12:34:46 -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=Mkg9+6ue; 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 S1348137AbiAXTnb (ORCPT + 99 others); Mon, 24 Jan 2022 14:43:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345683AbiAXTb3 (ORCPT ); Mon, 24 Jan 2022 14:31:29 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97428C028BE3; Mon, 24 Jan 2022 11:14:36 -0800 (PST) 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 54FC7B81235; Mon, 24 Jan 2022 19:14:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 696EFC340E5; Mon, 24 Jan 2022 19:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051674; bh=25Ko4hpiWyy/zvu15EXPbYLOPKyb4DyarnzWm4qNq5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mkg9+6uegJMj4yEP6PdvYLvLhWME6uMKRFscxs4aHZTIqXi5Zuz47cv7zRNMHcpB1 W+QWIYVbwDFZ6IEPkJ6m4olNjc0a9tGdJ5BTFUocw4BT9TRu/Zs92HfMT3OOvL9ezT m1GCDzHMaXCgKmhbvt1pesgWuvVSnocW7Rer/yw4= 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.19 051/239] media: em28xx: fix memory leak in em28xx_init_dev Date: Mon, 24 Jan 2022 19:41:29 +0100 Message-Id: <20220124183944.759591047@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@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 ec608f60d2c75..06da08f8efdb1 100644 --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c @@ -3515,8 +3515,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; @@ -3535,7 +3537,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 */ @@ -3551,9 +3553,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; } } @@ -3561,6 +3561,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; } static int em28xx_duplicate_dev(struct em28xx *dev) -- 2.34.1