From a9ed3aa9b87ee41e8ab3ff471b1331c154767e45 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 26 Sep 2026 07:57:59 +1000 Subject: Merge tag 'drm-misc-fixes-2026-09-24' of https://gitlab.freedesktop.org/drm/misc/kernel into drm-fixes A number of fixes: - bridge: - samsung-dsim: fix GPIO lifetime - client: Null pointer dereference fix - imagination: error handling fix, page handling fix - nouveau: fix reference leaks, double-frees, out-of-bounds accesses, use-after-frees, don't reject config without SCDC, a number of workarounds - virtio: fix memory leak, reference leaks, null pointer dereference, add pixel blend mode, cache coherency fix Signed-off-by: Dave Airlie From: Maxime Ripard Link: https://patch.msgid.link/arU22zzqUGDEco1y@houat --- drivers/char/tpm/tpm-dev.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 drivers/char/tpm/tpm-dev.c (limited to 'drivers/char/tpm/tpm-dev.c') diff --git a/drivers/char/tpm/tpm-dev.c b/drivers/char/tpm/tpm-dev.c new file mode 100644 index 000000000..74488f0a7 --- /dev/null +++ b/drivers/char/tpm/tpm-dev.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2004 IBM Corporation + * Authors: + * Leendert van Doorn + * Dave Safford + * Reiner Sailer + * Kylene Hall + * + * Copyright (C) 2013 Obsidian Research Corp + * Jason Gunthorpe + * + * Device file system interface to the TPM + */ +#include +#include "tpm-dev.h" + +static int tpm_open(struct inode *inode, struct file *file) +{ + struct tpm_chip *chip; + struct file_priv *priv; + + chip = container_of(inode->i_cdev, struct tpm_chip, cdev); + + /* It's assured that the chip will be opened just once, + * by the check of is_open variable, which is protected + * by driver_lock. */ + if (test_and_set_bit(0, &chip->is_open)) { + dev_dbg(&chip->dev, "Another process owns this TPM\n"); + return -EBUSY; + } + + priv = kzalloc_obj(*priv); + if (priv == NULL) + goto out; + + tpm_common_open(file, chip, priv, NULL); + + return nonseekable_open(inode, file); + + out: + clear_bit(0, &chip->is_open); + return -ENOMEM; +} + +/* + * Called on file close + */ +static int tpm_release(struct inode *inode, struct file *file) +{ + struct file_priv *priv = file->private_data; + + tpm_common_release(file, priv); + clear_bit(0, &priv->chip->is_open); + kfree(priv); + + return 0; +} + +const struct file_operations tpm_fops = { + .owner = THIS_MODULE, + .open = tpm_open, + .read = tpm_common_read, + .write = tpm_common_write, + .poll = tpm_common_poll, + .release = tpm_release, +}; -- cgit v1.3.1