Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

char: tpm: Fix possible memory leak in tpm_bios_measurements_open()

In tpm_bios_measurements_open(), get_device() is called on the device
embedded in struct tpm_chip. In the error path, however, put_device() is
not called. This results in a reference count leak, which prevents the
device from being properly released. This commit makes sure to call
put_device() when the seq_open() call fails.

Cc: stable@vger.kernel.org # +v4.18
Fixes: 9b01b5356629 ("tpm: Move shared eventlog functions to common.c")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

authored by

Joe Hattori and committed by
Jarkko Sakkinen
5d8e2971 22a40d14

+2
+2
drivers/char/tpm/eventlog/common.c
··· 47 47 if (!err) { 48 48 seq = file->private_data; 49 49 seq->private = chip; 50 + } else { 51 + put_device(&chip->dev); 50 52 } 51 53 52 54 return err;