[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210512071046.34941-8-guy.zadicario@intel.com>
Date: Wed, 12 May 2021 10:10:38 +0300
From: Guy Zadicario <guy.zadicario@...el.com>
To: gregkh@...uxfoundation.org, linux-kernel@...r.kernel.org
Cc: olof@...om.net, alexander.shishkin@...ux.intel.com,
andriy.shevchenko@...el.com, yochai.shefi-simchon@...el.com,
guy.zadicario@...el.com
Subject: [PATCH 07/15] misc: nnpi: Disallow host memory resource access if no NNP-I devices exist
There is no point allowing a user application to create host resources
on a system that does not equipped with any NNP-I devices.
Fail openning the nnpi_host character device when no NNP-I devices are
attached.
It is OK to do that check without any synchronization as a race would not
be an issue.
Signed-off-by: Guy Zadicario <guy.zadicario@...el.com>
Reviewed-by: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
---
drivers/misc/intel-nnpi/device.c | 5 +++++
drivers/misc/intel-nnpi/device.h | 2 ++
drivers/misc/intel-nnpi/host_chardev.c | 7 +++++++
3 files changed, 14 insertions(+)
diff --git a/drivers/misc/intel-nnpi/device.c b/drivers/misc/intel-nnpi/device.c
index 0f98398..a3c6a1d 100644
--- a/drivers/misc/intel-nnpi/device.c
+++ b/drivers/misc/intel-nnpi/device.c
@@ -13,6 +13,11 @@
static DEFINE_IDA(dev_ida);
+bool nnpdev_no_devices(void)
+{
+ return ida_is_empty(&dev_ida);
+}
+
/**
* nnpdev_init() - initialize NNP-I device structure.
* @nnpdev: device to be initialized
diff --git a/drivers/misc/intel-nnpi/device.h b/drivers/misc/intel-nnpi/device.h
index 7d7ef60..562bbc4 100644
--- a/drivers/misc/intel-nnpi/device.h
+++ b/drivers/misc/intel-nnpi/device.h
@@ -36,6 +36,8 @@ struct nnp_device_ops {
int (*cmdq_write_mesg)(struct nnp_device *nnpdev, u64 *msg, u32 size);
};
+bool nnpdev_no_devices(void);
+
/*
* Functions exported by the device framework module which are
* called by the lower layer NNP-I device driver module
diff --git a/drivers/misc/intel-nnpi/host_chardev.c b/drivers/misc/intel-nnpi/host_chardev.c
index 6048fda..fad5954 100644
--- a/drivers/misc/intel-nnpi/host_chardev.c
+++ b/drivers/misc/intel-nnpi/host_chardev.c
@@ -217,6 +217,13 @@ static int host_open(struct inode *inode, struct file *f)
if (!is_host_file(f))
return -EINVAL;
+ /*
+ * No point to serve host resource creation while no
+ * NNP-I devices exist in the system.
+ */
+ if (nnpdev_no_devices())
+ return -ENODEV;
+
user_info = kzalloc(sizeof(*user_info), GFP_KERNEL);
if (!user_info)
return -ENOMEM;
--
1.8.3.1
---------------------------------------------------------------------
Intel Israel (74) Limited
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
Powered by blists - more mailing lists