Skip to content

Commit

Permalink
stm class: Fix a double free in stm_register_device()
Browse files Browse the repository at this point in the history
[ Upstream commit 3df4638 ]

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: 389b669 ("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>
Link: https://lore.kernel.org/r/20240429130119.1518073-2-alexander.shishkin@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Dan Carpenter authored and gregkh committed Jun 12, 2024
1 parent fe43ef8 commit d782a2d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions drivers/hwtracing/stm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d782a2d

Please sign in to comment.