Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3527563pxj; Mon, 24 May 2021 08:42:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDYKqS5lRVP3ty27XO2hqGwb4Ue84GO5ZYXst+Q02AZohGtO31pCs///c1hSKXf3U6eftY X-Received: by 2002:a05:6e02:1c8e:: with SMTP id w14mr16553000ill.138.1621870927465; Mon, 24 May 2021 08:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621870927; cv=none; d=google.com; s=arc-20160816; b=D2eOeKeQoa+8xu1zvBkZlVXhUjCGcEB1cocu9plk2K2Mcfd/VV6WXn1sQq1OlouNMS RWPrOOCfCApPpP1Zab5qvTWjLHEKIYU/i/rEBUKYK1qqQUgkuM+m0DoahsqnniB8eu4/ sXZhJ38PhritLHaYW2cgedmPsR5rV6+LprmADQ6a7Q2pXV0eZtt/QkDjbBE9bh3Pb6N6 KjYT0lUmbq3/4K/CgjwCODhV3LC14aw/boLC+60fXAekV0kNRiUOnkaXBOGu0mgH6GUm peHTSf8M9eYQ+mOP7qvnZZzZ1McvvfG5gVgSunxtY32p/G8gpxH5bzBQ4MdY/+ChXn2r JTrA== 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=8FdtBjeJGfTBFspyvkZaiF+/3cA8REt4HW5unCmAdI8=; b=SykkHAPpXaTsrH217/LCu1UjUdZ3E/7zUlVH3ewSaD0v0Vi5nhQmYFNkImM+0xbHoT qqjHQQRNMzp8gstvmBVI0lsY6dMc4QKPLtTc5vt1gQSYNRiVKBvPIzs0VjNTWjPDPiuA ywVJLupIOB1lnmlmjEqSIIlm0Xdv07M/nNU4aegpjymE5uwu+RNjg7mYoDWKtVWBz2IL UggOxMpNm1+JKMoKwg5EZDITauq0wg25KtB9w5IET83Gbv5Vzg4zJrE0yvFnSaOm9G00 c5QcqP9Tp71YL/H27CtTcILuYyWKEV1f5rxs3UAn50B97g9C2yod6KnEyT83FfgJJ+Fw AaIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wvaut8df; 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 s18si13790552ilp.146.2021.05.24.08.41.53; Mon, 24 May 2021 08:42:07 -0700 (PDT) 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=wvaut8df; 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 S233339AbhEXPmw (ORCPT + 99 others); Mon, 24 May 2021 11:42:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:51396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233840AbhEXPi0 (ORCPT ); Mon, 24 May 2021 11:38:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C13F7613F7; Mon, 24 May 2021 15:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870414; bh=col2W/90IZRbqSa1kiiJsi0Aix/u3sIohvPjvSJJyCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wvaut8dftJrmFR+Q6HgUPNjlQ960Ffjp6GdUgC4sOG6yvRt48Fx42XjgLLUxjynkN YnqM//M2/808y5wZBi9oePY0PZluZ+KxOxKY3/EA8zUtcA+cvtwuaMa8ElIWbESXiE CoYDyWxbTxOTljPkkc3E4pX1/6ObVKDwWa497qqg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jens Axboe , Peter Rosin , Atul Gopinathan Subject: [PATCH 4.14 23/37] cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom Date: Mon, 24 May 2021 17:25:27 +0200 Message-Id: <20210524152324.963782296@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.199089755@linuxfoundation.org> References: <20210524152324.199089755@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: Atul Gopinathan commit d03d1021da6fe7f46efe9f2a7335564e7c9db5ab upstream. The fields, "toc" and "cd_info", of "struct gdrom_unit gd" are allocated in "probe_gdrom()". Prevent a memory leak by making sure "gd.cd_info" is deallocated in the "remove_gdrom()" function. Also prevent double free of the field "gd.toc" by moving it from the module's exit function to "remove_gdrom()". This is because, in "probe_gdrom()", the function makes sure to deallocate "gd.toc" in case of any errors, so the exit function invoked later would again free "gd.toc". The patch also maintains consistency by deallocating the above mentioned fields in "remove_gdrom()" along with another memory allocated field "gd.disk". Suggested-by: Jens Axboe Cc: Peter Rosin Cc: stable Signed-off-by: Atul Gopinathan Link: https://lore.kernel.org/r/20210503115736.2104747-28-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/cdrom/gdrom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/cdrom/gdrom.c +++ b/drivers/cdrom/gdrom.c @@ -857,6 +857,8 @@ static int remove_gdrom(struct platform_ if (gdrom_major) unregister_blkdev(gdrom_major, GDROM_DEV_NAME); unregister_cdrom(gd.cd_info); + kfree(gd.cd_info); + kfree(gd.toc); return 0; } @@ -888,7 +890,6 @@ static void __exit exit_gdrom(void) { platform_device_unregister(pd); platform_driver_unregister(&gdrom_driver); - kfree(gd.toc); } module_init(init_gdrom);