Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3583647pxb; Mon, 24 Jan 2022 12:49:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxRgFC5xHCAt1UOS0R5eyM9xrGnUqpJV/gEDNkVGf2E2pe8GnGjnLraBgk+JXMJ+NivMQX X-Received: by 2002:a17:903:230c:b0:14b:4c2d:e1fa with SMTP id d12-20020a170903230c00b0014b4c2de1famr6383081plh.24.1643057342431; Mon, 24 Jan 2022 12:49:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057342; cv=none; d=google.com; s=arc-20160816; b=o8lykVHpb/Ua4ioAeRj2wSkBddVKeiWBXbBgPmTRz+NPdto2cqg6JpI4Gyhnl++Ziq Fy7GVQrsb4GsYqeb9SmCi7KZ5uYRPhK729fFTmkWeSDLVeL0G241EUl2tHXip4xO4sJp fY0VMCvkFGpLHubuxks0DwXUagnFjw2ZetrClWilE+tVg5AvZNjmAndY62erpTBE0ogH 93St/b4/NpmbwOocBozB1wAlIT3RgAWXtYctWJIAxLC8koJUyEuzh1Ki6259/8QV+A9M R6CgTdxVkuqRbGJlS3lXjMbOIhMy1fOxGb5C4XMoPz8lxzu1G6uITa7ettyw+Hs53WnB XC5w== 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=6ZRRgPuoiZSWALNIjN4LE4zZ8WAQAeInMrNQdELNCh4=; b=O+RnFwhd3eFp/XZ5Pp8fpkpOEqdfKeLGhzoaowfdaznJTuQ8EXIuKU9t+v2j4TMCb8 xBSOCSYR9Nhna7GvWWmSkS9spod/luiQR4MDt1sMSDBG95pA2GidzQOmGM3886FmE4l0 MTOLHvzyl+0FzS/Etzx26pts3baJmMGRPWz5bviXgfzSXa2LAfIACHgohXlx3rXJ/+Kf JuigW3XCP4HAMzVHkl0xp71lFxOGsqEJhsyRDEWxGoaAh4DjMs5K+n09bb0D7TFQTP7w iAmUiCqiZ0HcccTifXaUCmsFCxjD3ftqmvQIe05cTO/vnpRvJGxFg3PDd7Atoez+tBDj F6AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MqzU+wtm; 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 d184si13224331pfa.118.2022.01.24.12.48.39; Mon, 24 Jan 2022 12:49:02 -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=MqzU+wtm; 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 S1353509AbiAXUDF (ORCPT + 99 others); Mon, 24 Jan 2022 15:03:05 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:54262 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345185AbiAXT0g (ORCPT ); Mon, 24 Jan 2022 14:26:36 -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 dfw.source.kernel.org (Postfix) with ESMTPS id DD54A614DC; Mon, 24 Jan 2022 19:26:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C39EDC340EE; Mon, 24 Jan 2022 19:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052395; bh=bfB2/RcW2K+xexjn5NVIMB7nOFtsU1aTuXcNAlD80bY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MqzU+wtmBNolgyk/XqOY5A1m9sJYf2czZjn3E+pLtUWGZ132sT5b9hC+4JLBXLx1e uIRE+pEheD0DhfCx2tlV0VeBM02AnKzbScyQPtqU2wwEp2XDCWaPU8yJ0uQz00ABEb bdD0HCH1kgy46lNgUJ9aikcZ5VloWGUTf7ZcsJFI= 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 5.4 044/320] media: em28xx: fix memory leak in em28xx_init_dev Date: Mon, 24 Jan 2022 19:40:28 +0100 Message-Id: <20220124183955.247242999@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@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 3e96b4b711d75..bfca9d0a1fe15 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