public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Amelie Delaunay <amelie.delaunay@foss.st.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [PATCH 01/14] stm class: Fix a double free in stm_register_device()
Date: Mon, 29 Apr 2024 15:08:55 +0300	[thread overview]
Message-ID: <20240429120908.3723458-2-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <20240429120908.3723458-1-alexander.shishkin@linux.intel.com>

From: Dan Carpenter <dan.carpenter@linaro.org>

The put_device(&stm->dev) call will trigger stm_device_release() which
frees "stm" so the vfree(stm) on the next line is a double free.

Fixes: 389b6699a2aa ("stm class: Fix stm device initialization order")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 drivers/hwtracing/stm/core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index 534fbefc7f6a..20895d391562 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -868,8 +868,11 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
 		return -ENOMEM;
 
 	stm->major = register_chrdev(0, stm_data->name, &stm_fops);
-	if (stm->major < 0)
-		goto err_free;
+	if (stm->major < 0) {
+		err = stm->major;
+		vfree(stm);
+		return err;
+	}
 
 	device_initialize(&stm->dev);
 	stm->dev.devt = MKDEV(stm->major, 0);
@@ -913,10 +916,8 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data,
 err_device:
 	unregister_chrdev(stm->major, stm_data->name);
 
-	/* matches device_initialize() above */
+	/* calls stm_device_release() */
 	put_device(&stm->dev);
-err_free:
-	vfree(stm);
 
 	return err;
 }
-- 
2.43.0


  reply	other threads:[~2024-04-29 12:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-29 12:08 [PATCH 00/14] stm class/intel_th: Updates for v6.10 Alexander Shishkin
2024-04-29 12:08 ` Alexander Shishkin [this message]
2024-04-29 12:08 ` [PATCH 02/14] stm class: Add source type Alexander Shishkin
2024-04-29 12:08 ` [PATCH 03/14] stm class: Propagate source type to protocols Alexander Shishkin
2024-04-29 12:08 ` [PATCH 04/14] stm class: sys-t: Improve ftrace source handling Alexander Shishkin
2024-04-29 12:08 ` [PATCH 05/14] intel_th: Constify the struct device_type usage Alexander Shishkin
2024-04-29 12:09 ` [PATCH 06/14] intel_th: Convert sprintf/snprintf to sysfs_emit Alexander Shishkin
2024-04-29 12:09 ` [PATCH 07/14] intel_th: Remove redundant initialization of pointer outp Alexander Shishkin
2024-04-29 12:09 ` [PATCH 08/14] intel_th: msu: Fix kernel-doc warnings Alexander Shishkin
2024-04-29 12:09 ` [PATCH 09/14] intel_th: pci: Add Granite Rapids support Alexander Shishkin
2024-04-29 12:09 ` [PATCH 10/14] intel_th: pci: Add Granite Rapids SOC support Alexander Shishkin
2024-04-29 12:09 ` [PATCH 11/14] intel_th: pci: Add Sapphire " Alexander Shishkin
2024-04-29 12:09 ` [PATCH 12/14] intel_th: pci: Add Meteor Lake-S support Alexander Shishkin
2024-04-29 12:09 ` [PATCH 13/14] intel_th: pci: Add Meteor Lake-S CPU support Alexander Shishkin
2024-04-29 12:09 ` [PATCH 14/14] intel_th: pci: Add Lunar Lake support Alexander Shishkin
2024-04-29 13:05 ` [PATCH 00/14] stm class/intel_th: Updates for v6.10 Alexander Shishkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240429120908.3723458-2-alexander.shishkin@linux.intel.com \
    --to=alexander.shishkin@linux.intel.com \
    --cc=amelie.delaunay@foss.st.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox