Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3550631pxj; Mon, 24 May 2021 09:10:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxq0c8vhuQcK5Pu5ZdnCRGDJidU13eIEm1XFIMbz3hdsk++MrnR0ZIRIzqjndJgR3RyWrlU X-Received: by 2002:a5d:9d16:: with SMTP id j22mr14900378ioj.92.1621872633989; Mon, 24 May 2021 09:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872633; cv=none; d=google.com; s=arc-20160816; b=SO5YhXiZKhyZZeDr5KGHJ8p4FNM4Tcz2cDYlgnYolGT/xFcG9iwpaPzKBnDWCVDEom yiH+c+RnERtA2Ogls/VcgFcjOL1WBULI4JOHl2X/ZnlfkX1jSDrlwgkHgMXJvRWUAUDd uM8Ib9eoc+56P3ufV00i/9raBDj9wFdVLy76AtM4Kf3uYYQKnHcafmKUJaAyMWHr2OZa SjneCwjXO6qYnui6rzMtvHI1pV3gANdtfhZ+bJpWgLFlgX0KDAHwHufj5G9PvdI85CXn 4sATqfXSUVLdnAKjb7LvjWsK9s0FP1e+/QJ0kldJkg7zsoO7V9YW1r2hl98dIl+B9WyY UFGw== 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=mPAQALWKdFsf+Lca+h+JQDdabjMiEei08ts3ygypwYo=; b=DWz30W6yr6RdUwO5DLMoP3Yd79Un/5JFNcNwJhBiUC3d3MbX8b9JaBuJQNe7qmVp3m nF7Sa2I9O+NrPHKasJpDnSWyG58eCzNr1KuWqvYebjEOpdxeOWW5XFviiW9JVGEP7DF/ 5qGAXGmV+deYOB8BRPvcxDvnIb53dmqYGRUb3qpTxp+y3DNb44igSeDIPBUfuylKnJp/ WJP90MSYpxCe07HVq+DrlZyDw45G9GCVO6rYQrPbnyYAFa3LDRNKNL8re2XbNbh3bKdU ztb7o74jbHuz7CMokARWea8GuGJsPvCDa905B1KrwrP3KzIUrh0yBPhrBMA2cXjxZmmJ Yurg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y+xmWVwn; 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 n9si14197392jaj.15.2021.05.24.09.10.21; Mon, 24 May 2021 09:10:33 -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=y+xmWVwn; 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 S238592AbhEXQKN (ORCPT + 99 others); Mon, 24 May 2021 12:10:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:46618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234058AbhEXQCV (ORCPT ); Mon, 24 May 2021 12:02:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 65F2F6199B; Mon, 24 May 2021 15:47:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621871228; bh=l5znzEEp+drGCc3MSCCVnVpCS2tcza2eGBpHeaiJtnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y+xmWVwnzcFz3iEi0hZxlOSyQKt8dnxbIIdvTjsRcpKZmdLDiDmJduRWuEgBvEu4/ 61yGaNkopuoiOM/1NOG7m65flaVFPb0jVt6Y9Xg0+PIsnQSkb0qtb8Q1eneP2NwOn3 J8V4aoSK1U7aUE5HgoMwDW9IRmGXOZoi11U4zr8I= 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.12 104/127] cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom Date: Mon, 24 May 2021 17:27:01 +0200 Message-Id: <20210524152338.367982185@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152334.857620285@linuxfoundation.org> References: <20210524152334.857620285@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 @@ -831,6 +831,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; } @@ -862,7 +864,6 @@ static void __exit exit_gdrom(void) { platform_device_unregister(pd); platform_driver_unregister(&gdrom_driver); - kfree(gd.toc); } module_init(init_gdrom);