Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3538816pxj; Mon, 24 May 2021 08:57:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr2FYqAogK7yiopRTDzuWYUVNZYugnphiKfdvClMHZMBrqpqhKwCS2bLNr5P+Uaq0yuKqE X-Received: by 2002:a6b:3b4c:: with SMTP id i73mr16339032ioa.149.1621871862326; Mon, 24 May 2021 08:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621871862; cv=none; d=google.com; s=arc-20160816; b=KO/MM/6KdP/FvuCX4HS5FlrViYgFCkHPvPR/4SxEOyBTqq6U48g/U2IMCRZO2tibGA ENB5d8EcVt7O+F0YCU8Cg8ysYTvXt8F6tXtfZWXgpoy0EUXshYt4lGfKQdBHGQu0mw5c erhsYPXU7FRMKSNq16o57G4NmKd8CrcAv920b1Vgp8qHZ6vrinaN7Gb6JjvUts8NMALf W4O3FZWheX+HSoo4bvbxPd+1NVeKBtwJ7JLEDRLvtYfwXXNMUwVUAnCaYPF7j/PYxcsR kRBKmZQTRhW0sOusRhYUcYD83glqcDHbhaqgU5UMbWcKtvgL/7OeeM5LCgcIdic38Z0X Xg/A== 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=1xIQDJSd+hBaguzBJ1GPICq75c1EajV6RGuFzR9d6Ms=; b=wt4jd0B6HL/DB6iqize93J3NPum44wVOj5Io5CbNDIaQmXWMP3fNHrtp5fc1X6UpNe xJxutI/jiYj+NPj7kQQGeZkIOeF6Jf6bQutIgd+S74d9wbGnY4W35cCmSeWXxNuR+DLv naKkznGmDUXkDvjO191XLmZw0fgy/QGmR5lGGWj/0hf0M+oiWnPnOlQDI5ICmBYhgEQu BYSDPsNXHWi/vzhK124BbfYMzYp/RA4qWhVCmFuSpOnQAb0VLbf6bxkOzOqyqXj9UjrJ cuK5rfnnGGeHuk/+eEz8fs8u5LDzE/6UV0HOdvMZ1rkh8m0vdhyYK6h44/VamUhimpQR yLHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I8dUu9xb; 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 c15si13672549ilo.151.2021.05.24.08.57.27; Mon, 24 May 2021 08:57:42 -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=I8dUu9xb; 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 S233928AbhEXP4q (ORCPT + 99 others); Mon, 24 May 2021 11:56:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:35146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234671AbhEXPtZ (ORCPT ); Mon, 24 May 2021 11:49:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ED8E6614A5; Mon, 24 May 2021 15:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870673; bh=7bxPdXdHSvAGzjfXNcqShFJe4bgPO3O3GHqQc4vD0mI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I8dUu9xbCGHWLxYWjXpOnbCNBqV3lXio+PratXuXmhfh6D3QcHuGWqOyk3eb8P3P3 ctdcnn9DMoMmNs8dXG3spoWV8Szib8TVK9pMQ4mHxnqx1VwPVDKDIIeWnkv/3+PuPa iwY94ozMqhbqGdMYNPxZ6ihCalKQxyOD2HJMlWa4= 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 5.4 52/71] cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom Date: Mon, 24 May 2021 17:25:58 +0200 Message-Id: <20210524152328.150183268@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152326.447759938@linuxfoundation.org> References: <20210524152326.447759938@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 @@ -828,6 +828,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; } @@ -859,7 +861,6 @@ static void __exit exit_gdrom(void) { platform_device_unregister(pd); platform_driver_unregister(&gdrom_driver); - kfree(gd.toc); } module_init(init_gdrom);