Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2693997pxy; Mon, 3 May 2021 06:06:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd1grJ/z3YN6x1YIK3M3DhF6GdIVwMAZWsJZzT25VVSlPUGxFsH88HI13DmEXxtuSovMlv X-Received: by 2002:aa7:8d03:0:b029:259:f2ed:1849 with SMTP id j3-20020aa78d030000b0290259f2ed1849mr19340531pfe.30.1620047202906; Mon, 03 May 2021 06:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620047202; cv=none; d=google.com; s=arc-20160816; b=CJv0TK7QC8kaLeEA1SSGzTgfCWGtZCUB9GVPL97val7miQNuWqEEwbmScKJUIQ8xe4 xR0xKu/NLRDhidKdDejFDYt7V/7DqvzFj8wXkrAEEEo3T+rqw2gCehvd42Cp0GEghm37 67MMSuqmUbiwRlhYuQ5qyYLZ31gYUQHQQr9I0FWHjGkUx/taF/EQUSvYTbWkrUo7FGKg pnVUAC7Euilh7WRPgWQq9smByh8ophkTf0eWK3Wha/dBwDWLT1NxGWggYUB9Q0BRvpf0 QHXIp+5Lg4U1xSApdiJaZLfucoA+v4VBNiLcKtOy+HNKQYMvBBKaIii1hg7Of7TCCvJ0 /p4g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gECqRURbdBUxeT81dgahNvgbzzDUGulkMsRRtBJqujc=; b=CWNFU8ViRLDEoR0DtmTIEPMIcbfwq5/aK/C3ookauzofWpf3jCQ9M/Ck6i813MdFPV zJVPcHWvivca+JnoH31o1sATVcXF8WvTBLxVDnAYLF62NPIuTXUbT9Q2Y1uJ4tHy1jny Y96N/Yik+PFYJdduROT3LdwGmsudkzL+QQLOdTATSiN7BUOPCMw8eCAVxJzGAXMJ6ROE w7r0tqG0uj9nU19cbSkKHbpqghqQjK3XweLuzTfYXQMxpkJUdzsq4K4fqtP2L3/zPBS0 a/c/1fMfhb9DchAlubvHKagHs/Nq06B+XBRJt/jewpbJZnwC+6tCfoPe6Jb3lVVHKuZH +gVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nmDGoiGu; 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 o34si18167175pgm.209.2021.05.03.06.06.27; Mon, 03 May 2021 06:06: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=nmDGoiGu; 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 S233728AbhECMAr (ORCPT + 99 others); Mon, 3 May 2021 08:00:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:34696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233705AbhECMA3 (ORCPT ); Mon, 3 May 2021 08:00:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 520B86137D; Mon, 3 May 2021 11:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620043176; bh=f+J85lZkGvA2uJMgWYEZNfvAuLMP8vHjqMAx3ZpNd3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nmDGoiGupb9SxpQHhWs2kjjyw9DqoaHmzRtAuH60hRObu6Ki89af126SOhmNy4eJw v6Ml2A9kMhwCuAe60zaeEW2H+5qdfDlhZxxCZ9OWxigFoOW5j+0VoOj7gRp5cENsZc BdtcuD4zYuSkUv02XgmlaDA0+YrV9Zap4+5DvkWs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Atul Gopinathan , Jens Axboe , Peter Rosin , stable , Greg Kroah-Hartman Subject: [PATCH 27/69] cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom Date: Mon, 3 May 2021 13:56:54 +0200 Message-Id: <20210503115736.2104747-28-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503115736.2104747-1-gregkh@linuxfoundation.org> References: <20210503115736.2104747-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Atul Gopinathan 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 Signed-off-by: Greg Kroah-Hartman --- drivers/cdrom/gdrom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c index 7f681320c7d3..6c4f6139f853 100644 --- a/drivers/cdrom/gdrom.c +++ b/drivers/cdrom/gdrom.c @@ -830,6 +830,8 @@ static int remove_gdrom(struct platform_device *devptr) if (gdrom_major) unregister_blkdev(gdrom_major, GDROM_DEV_NAME); unregister_cdrom(gd.cd_info); + kfree(gd.cd_info); + kfree(gd.toc); return 0; } @@ -861,7 +863,6 @@ static void __exit exit_gdrom(void) { platform_device_unregister(pd); platform_driver_unregister(&gdrom_driver); - kfree(gd.toc); } module_init(init_gdrom); -- 2.31.1