Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3532815pxj; Mon, 24 May 2021 08:49:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmAXJwbasSZntZfsZA6fTOJuLYLzsRlFGCxfu9SgXpC0UrAtr77FsLIfNsh81UmypI4lcG X-Received: by 2002:a92:d8c8:: with SMTP id l8mr15774248ilo.197.1621871370820; Mon, 24 May 2021 08:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621871370; cv=none; d=google.com; s=arc-20160816; b=RHu2gt4aRTo/JkYEadkfXhUDO6GZVzuxK+gSf0QL3/dAh/YM/4nD+kSeBkZ9Nl2KIS c+iT5uiY9pWtoCr/Ss+lRA0/uv4QgxmzXhIpz0BIIOtZuxIv45+LneRfbKE/QTgcW47h UWZWUt/jUBMe8wfeOV6O27N663cAgEsbmy/F2nEZE8V2G5cwewEXUoKFkQ3n9jMFh3h4 qL9Eq3zzYdDnEfEvkLm79adj/X0CQBRvaA3BDTP6T1TJTC/YIRihmnkeHI+rlYGzrYKv 9ymHiaInxpP4Xh8gHwO6wqSZtWgxIfUUDUIk2LwNSt4wEeiPuAZHJWXLXW5B2FjUnloQ 7BsQ== 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=r1A6fhtHz3adBouJGXk4FvyQPmFvVziR1toet32p3KkYTiJSHhvA6D2hES53mLt4G6 QET4kWzH9EMUsGZ/wD1K9KxAWsIFyG1UePsRkAsGy+1m5wBStHY5VX7nsudYZWubxmmx zMarbS2oLlZEQc5qqialz6XgZtQSN2ilpJRJz6790s225eEkQrzA8T0tGRBSXdfJubSU VmhiVVtWO4AvMrfkWwH0SNlakJkPh6IWYt5vHbWjxdaLlR4Umnto2dz61lsMVdvaAfW/ PcniYxRKPHdEi2nVObUJwS9jHdk7/Z7OdK0bOHc0XlIsA6BCLAcu1uaUcKd3HTMVNBRf 8k9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ewn9HMw5; 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 l8si15726294iln.109.2021.05.24.08.49.08; Mon, 24 May 2021 08:49:30 -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=ewn9HMw5; 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 S233859AbhEXPrx (ORCPT + 99 others); Mon, 24 May 2021 11:47:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:56946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234129AbhEXPnI (ORCPT ); Mon, 24 May 2021 11:43:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6F4486144D; Mon, 24 May 2021 15:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870520; bh=col2W/90IZRbqSa1kiiJsi0Aix/u3sIohvPjvSJJyCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ewn9HMw5HFo8A63NUMAWj09n5hLNFVLNwsmX1Q7B7avsguYuh5H5t072yFn6zkUVt JcIwB5ZPG64U5Fgsfuwn3qUpIpcf1+4d2Sld74mrJoLukU7aQnHGe3k4mHsOccP5TC yd+8H6VWVZ1bj4lGlKFxuD2ylxkGd16RvvUeufpU= 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.19 33/49] cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom Date: Mon, 24 May 2021 17:25:44 +0200 Message-Id: <20210524152325.451268720@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.382084875@linuxfoundation.org> References: <20210524152324.382084875@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);