Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3541236pxj; Mon, 24 May 2021 09:00:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4qP6hwEisH3IqWcMa4+PTk+8H0m62603a/2ZS8/C2lunsSNNmjeF+t9gHYlLBLyeTd9LW X-Received: by 2002:a02:cc37:: with SMTP id o23mr24863184jap.35.1621872042520; Mon, 24 May 2021 09:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872042; cv=none; d=google.com; s=arc-20160816; b=RE/0z2Ldh63OK5/qLvP3EwW7hcHY44QH9G/SOFb/WlC0O8D4HRY4xfp7tb+JUU20YM gqXsTm5JuvkKqQ3KOoi9bkw4w+GqsnyHpBVoXXk3254M52NfSi0qBdxiVBIxnZpk4D2k xUkzVzsdDf123MtaAxEygI/KGgBYXhOJn4Zd8C45eYJ8cavV6S+Kc63bY7kP31BrOVnD b3oC3lWr1osgkGB0yDiUE8/6H6quLjDHjJRrknNlrKC4l53qv5LTe/C+xkDY7dlg3zW9 gAiEs81WFFRnTQtXsiYrteepb1lTYovYkc7oGfa4XP3ceSmXxj9x3Z1Ah7ZgEgT7NpMI /EIQ== 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=q6P0Z/5QldDixC0fEfGvuOv0NDEzr2/LnLJFHhyUgzq8X1cW4HIgRhkgbtznwfz3wI 4gRaC1IFnnF0iZTVcZCmu1swYHiIKVZKjemE4ylKiF3P1T5WPDROjaOERLoZ1Wf9uwmC H1MMRKDnNhLHKYwTXKydfXwlrM7ZLRcSQmZ6lsvl4OOTCMz5OaehlOpHJnbgqjWYJS7k kZVc0+BVAw/BnJE3zaQ0Jih6GhQdqIfqbfHof/27i73V/dV1+Qku5AA41jbN33bfq7+b lyQJ0MTzWhl9dvV/kv8Wqqf59Yp2guvEJaCBhIPvibSh9uW4G9mOIkiiTleW6k3UG81a /sng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cHxzWeu1; 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 o1si15457695jat.48.2021.05.24.09.00.28; Mon, 24 May 2021 09:00: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=cHxzWeu1; 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 S235786AbhEXQBI (ORCPT + 99 others); Mon, 24 May 2021 12:01:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:39020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235477AbhEXPzJ (ORCPT ); Mon, 24 May 2021 11:55:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0A29461936; Mon, 24 May 2021 15:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870892; bh=l5znzEEp+drGCc3MSCCVnVpCS2tcza2eGBpHeaiJtnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cHxzWeu1+5vaIHuKO0cJVk9QecZ3NCIeuwI/2oeLBCZbmzbFGlpi/cAy4cZ4Wex3x qJYo6ItHWBKW01ogVlszXYRz/hRd5La25jGzAgGZ3KYhkUfYmnnuDjExQIt3rxaxHK SRQoNJRV4jNdLXEZVJbf1+3pnKpYnZILuKCNWcHQ= 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.10 081/104] cdrom: gdrom: deallocate struct gdrom_unit fields in remove_gdrom Date: Mon, 24 May 2021 17:26:16 +0200 Message-Id: <20210524152335.539642737@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152332.844251980@linuxfoundation.org> References: <20210524152332.844251980@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);