Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3526629pxj; Mon, 24 May 2021 08:40:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAT2+vvv2rDld9YB8kBzk9c1hbcVQ674IvIxhUhkaRGuSA3eTv/fE5HNfVSuO7wehQ4N6z X-Received: by 2002:a17:907:76e8:: with SMTP id kg8mr22513895ejc.130.1621870845770; Mon, 24 May 2021 08:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621870845; cv=none; d=google.com; s=arc-20160816; b=I4NukkmTLzVkGot6VRgZL5GgnVxiPkpexGHF5Wzu6rzpYxBZRL7/D1bhYm5nqabT/n 5GumRCmk7Lw4jlyl0Hv8usP95Be9vXmfIA/gGREukfWoSzDfGie5cHFMrZUSIAPs2AxL uFugfqXQf4wRJSL8MrJmISI6Ti0p94vcQIHWHiztZVEViFqmoRDddYGviyGF+U1YZbgu Rfz619rIIWWAQRrI5cy30cQr5kfl1zOsIYfWvw0MTIlFywo5ZfYrRq8kfh6uSsiYd7Po UFESQeBLpl0u4t9mWzUPhabOopQwjSDtbyobNl5ck2sswYY1ccxIE6Zp8vSWX+DkGt0+ t59w== 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=1nYbNep97YzEvASEhGvUh5vxyicv8OISK8X9tYeT6jY=; b=ifwo9eLuZs5Z/tG10c/47D4pEtpBLlciLAvZoj2143ceZowS2DQk3Ezo14VvH/7u3i zlzcW7qF451pYl0gWTLkYIBm1UUCJ4bNmr3wjFzai6eTJXGMp9oTe8MTYW51g6MjdK6b JtqiKSisOiiwhSU134eYOKVhhXpiPWdDzVWwxLwq9EfYuvDpcJ7x69BcAz0r5z2iixc6 1bSrirrH40FVJVu+gXE57NKOR6V+8e2vU/ES52CXNP5DcqcdzlV97yxdS5Tb42X64e5p i+icXWFomqh47W++L58P/2kChdI8qeYIBw1HS4OZwOhdlklF8+OXKBeLgu+9on3qqgK2 EHsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gVMSlDV8; 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 s12si13239682edu.237.2021.05.24.08.40.23; Mon, 24 May 2021 08:40:45 -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=gVMSlDV8; 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 S234114AbhEXPi4 (ORCPT + 99 others); Mon, 24 May 2021 11:38:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:51622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233072AbhEXPfI (ORCPT ); Mon, 24 May 2021 11:35:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8F81B613FE; Mon, 24 May 2021 15:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870349; bh=XNHfIXa8t0pA/6xQpixIYGs+1qBhbJw9btNSV41bm/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gVMSlDV8ed/esbOBZNJg/V/9Gs0hH5f6bRw1mcW9JygaCoeQl9jW1WMFjAOSgGPFJ Wl6JkuouAVIRnCoOZi1405gb0ThjfUqSjtZ/rRQ5p6mluVW0MvmVDqR1JB6cmafgnc xBO1JwfAxE7i7Y9aSxe5tU1QDkIHxp1AVlnPe1dg= 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.9 22/36] cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom Date: Mon, 24 May 2021 17:25:07 +0200 Message-Id: <20210524152324.880475059@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.158146731@linuxfoundation.org> References: <20210524152324.158146731@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 @@ -850,6 +850,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; } @@ -881,7 +883,6 @@ static void __exit exit_gdrom(void) { platform_device_unregister(pd); platform_driver_unregister(&gdrom_driver); - kfree(gd.toc); } module_init(init_gdrom);