Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0ebf519 authored by Johan Hovold's avatar Johan Hovold Committed by Alexander Shishkin
Browse files

stm class: Fix device leak in open error path



Make sure to drop the reference taken by class_find_device() also on
allocation errors in open().

Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Fixes: 7bd1d409 ("stm class: Introduce an abstraction for...")
Cc: stable@vger.kernel.org # v4.6+
Signed-off-by: default avatarAlexander Shishkin <alexander.shishkin@linux.intel.com>
parent a25f0944
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -361,7 +361,7 @@ static int stm_char_open(struct inode *inode, struct file *file)
	struct stm_file *stmf;
	struct device *dev;
	unsigned int major = imajor(inode);
	int err = -ENODEV;
	int err = -ENOMEM;

	dev = class_find_device(&stm_class, NULL, &major, major_match);
	if (!dev)
@@ -369,8 +369,9 @@ static int stm_char_open(struct inode *inode, struct file *file)

	stmf = kzalloc(sizeof(*stmf), GFP_KERNEL);
	if (!stmf)
		return -ENOMEM;
		goto err_put_device;

	err = -ENODEV;
	stm_output_init(&stmf->output);
	stmf->stm = to_stm_device(dev);

@@ -382,9 +383,10 @@ static int stm_char_open(struct inode *inode, struct file *file)
	return nonseekable_open(inode, file);

err_free:
	kfree(stmf);
err_put_device:
	/* matches class_find_device() above */
	put_device(dev);
	kfree(stmf);

	return err;
}