user space client interface driver
Subsystems (3)
v5 cover user space client interface driver
V5:
- Removed mhi_uci_drv structure.
- Used idr instead of creating global list of uci devices.
- Used kref instead of local ref counting for uci device and open count.
- Removed unlikely macro.
V4:
- Fix locking to protect proper struct members.
- Updated documentation describing uci client driver use cases.
- Fixed uci ref counting in mhi_uci_open for error case.
- Addressed style related review comments.
V3: Added documentation for MHI UCI driver.
V2: Added mutex lock to prevent multiple readers to access same mhi buffer which can result into use after free.
Hemant Kumar (4):
bus: mhi: core: Add helper API to return number of free TREs
bus: mhi: core: Move MHI_MAX_MTU to external header file
docs: Add documentation for userspace client interface
bus: mhi: clients: Add userspace client interface driver
Documentation/mhi/index.rst | 1 + Documentation/mhi/uci.rst | 39 +++ drivers/bus/mhi/Kconfig | 6 + drivers/bus/mhi/Makefile | 1 + drivers/bus/mhi/clients/Kconfig | 15 + drivers/bus/mhi/clients/Makefile | 3 + drivers/bus/mhi/clients/uci.c | 662 +++++++++++++++++++++++++++++++++++++++ drivers/bus/mhi/core/internal.h | 1 - drivers/bus/mhi/core/main.c | 12 + include/linux/mhi.h | 12 + 10 files changed, 751 insertions(+), 1 deletion(-) create mode 100644 Documentation/mhi/uci.rst create mode 100644 drivers/bus/mhi/clients/Kconfig create mode 100644 drivers/bus/mhi/clients/Makefile create mode 100644 drivers/bus/mhi/clients/uci.c
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v5 2/4 bus: mhi: core: Move MHI_MAX_MTU to external header file
Currently this macro is defined in internal MHI header as a TRE length mask. Moving it to external header allows MHI client drivers to set this upper bound for the transmit buffer size.
--- drivers/bus/mhi/core/internal.h | 1 - include/linux/mhi.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/bus/mhi/core/internal.h +0 -1
@@ -453,7 +453,6 @@ enum mhi_pm_state {#define CMD_EL_PER_RING 128#define PRIMARY_CMD_RING 0#define MHI_DEV_WAKE_DB 127 -#define MHI_MAX_MTU 0xffff#define MHI_RANDOM_U32_NONZERO (bmsk) (prandom_u32_max(bmsk) + 1)enum mhi_er_type {
include/linux/mhi.h +3 -0
@@ -16,6 +16,9 @@#include <linux/wait.h> #include <linux/workqueue.h> +/* MHI client drivers to set this upper bound for tx buffer */ +#define MHI_MAX_MTU 0xffff +#define MHI_MAX_OEM_PK_HASH_SEGMENTS 16struct mhi_chan ;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v5 3/4 docs: Add documentation for userspace client interface
In reply to Hemant KumarMHI userspace client driver is creating device file node for user application to perform file operations. File operations are handled by MHI core driver. Currently Loopback MHI channel is supported by this driver.
--- Documentation/mhi/index.rst | 1 + Documentation/mhi/uci.rst | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Documentation/mhi/uci.rst
Documentation/mhi/index.rst +1 -0
@@ -9,6 +9,7 @@ MHI mhi topology + uci .. only:: subproject and html
Documentation/mhi/uci.rst new file +39 -0
@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================= +Userspace Client Interface (UCI) +================================= + +UCI driver enables userspace clients to communicate to external MHI devices +like modem and WLAN. It creates standard character device file nodes for user +space clients to perform open, read, write, poll and close file operations. + +Device file node is created with format:- + +/dev/mhi_<controller_name>_<mhi_device_name> + +controller_name is the name of underlying bus used to transfer data. +mhi_device_name is the name of the MHI channel being used by MHI client in +userspace to send or receive data using MHI protocol. + +There is a separate character device file node created for each channel specified +in mhi device id table. MHI channels are statically defined by MHI specification. +Driver currently supports LOOPBACK channel 0 (Host to device) and 1 (Device to Host). + +LOOPBACK Channel +---------------- + +Userspace MHI client using LOOPBACK channel opens device file node. As part of +open operation TREs to transfer ring of LOOPBACK channel 1 gets queued and channel +doorbell is rung. When userspace MHI client performs write operation on device node, +data buffer gets queued as a TRE to transfer ring of LOOPBACK channel 0. MHI Core +driver rings the channel doorbell for MHI device to move data over underlying bus. +When userspace MHI client driver performs read operation, same data gets looped back +to MHI host using LOOPBACK channel 1. LOOPBACK channel is used to verify data path +and data integrity between MHI Host and MHI device. + +Other Use Cases +--------------- + +Getting MHI device specific diagnostics information to userspace MHI diag client +using DIAG channel 4 (Host to device) and 5 (Device to Host).
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v5 4/4 bus: mhi: clients: Add userspace client interface driver
In reply to Hemant KumarThis MHI client driver allows userspace clients to transfer raw data between MHI device and host using standard file operations. Device file node is created with format
/dev/mhi_<controller_name>_<mhi_device_name>
Currently it supports LOOPBACK channel.
--- drivers/bus/mhi/Kconfig | 6 + drivers/bus/mhi/Makefile | 1 + drivers/bus/mhi/clients/Kconfig | 15 + drivers/bus/mhi/clients/Makefile | 3 + drivers/bus/mhi/clients/uci.c | 662 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 687 insertions(+) create mode 100644 drivers/bus/mhi/clients/Kconfig create mode 100644 drivers/bus/mhi/clients/Makefile create mode 100644 drivers/bus/mhi/clients/uci.c
drivers/bus/mhi/Kconfig +6 -0
@@ -20,3 +20,9 @@ config MHI_BUS_DEBUG Enable debugfs support for use with the MHI transport. Allows reading and/or modifying some values within the MHI controller for debug and test purposes. + +if MHI_BUS + +source "drivers/bus/mhi/clients/Kconfig" + +endif
drivers/bus/mhi/Makefile +1 -0
@@ -1,2 +1,3 @@ # core layer obj-y += core/ +obj-y += clients/
drivers/bus/mhi/clients/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only + +menu "MHI clients support" + +config MHI_UCI + tristate "MHI UCI" + depends on MHI_BUS + help + MHI based userspace client interface driver is used for transferring + raw data between host and device using standard file operations from + userspace. Open, read, write, and close operations are supported + by this driver. Please check mhi_uci_match_table for all supported + channels that are exposed to userspace. + +endmenu
drivers/bus/mhi/clients/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_MHI_UCI) += uci.o
drivers/bus/mhi/clients/uci.c new file +662 -0
662 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v5 1/4 bus: mhi: core: Add helper API to return number of free TREs
In reply to Hemant KumarIntroduce mhi_get_no_free_descriptors() API to return number of TREs available to queue buffer. MHI clients can use this API to know before hand if ring is full without calling queue API.
--- drivers/bus/mhi/core/main.c | 12 ++++++++++++ include/linux/mhi.h | 9 +++++++++ 2 files changed, 21 insertions(+)
drivers/bus/mhi/core/main.c +12 -0
@@ -258,6 +258,18 @@ int mhi_destroy_device(struct device *dev, void *data)return 0 ; } +int mhi_get_no_free_descriptors (struct mhi_device *mhi_dev, +enum dma_data_direction dir) +{ +struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl; +struct mhi_chan *mhi_chan = (dir ==DMA_TO_DEVICE ) ? + mhi_dev->ul_chan : mhi_dev->dl_chan; +struct mhi_ring *tre_ring = &mhi_chan->tre_ring; + +return get_nr_avail_ring_elements (mhi_cntrl, tre_ring); +} +EXPORT_SYMBOL_GPL (mhi_get_no_free_descriptors); +void mhi_notify (struct mhi_device *mhi_dev,enum mhi_callback cb_reason) {struct mhi_driver *mhi_drv;
include/linux/mhi.h +9 -0
@@ -600,6 +600,15 @@ void mhi_set_mhi_state(struct mhi_controller *mhi_cntrl,void mhi_notify (struct mhi_device *mhi_dev,enum mhi_callback cb_reason);/** +* mhi_get_no_free_descriptors - Get transfer ring length +* Get # of TD available to queue buffers +* @mhi_dev: Device associated with the channels +* @dir: Direction of the channel +*/ +int mhi_get_no_free_descriptors (struct mhi_device *mhi_dev, +enum dma_data_direction dir); + +/** * mhi_prepare_for_power_up - Do pre-initialization before power up. * This is optional, call this before power up if * the controller does not want bus framework to
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Hi Jeff and Mani,
Quoted 35 lines · Hemant Kumar
V5:
- Removedmhi_uci_drvstructure.
- Used idr instead of creating global list of uci devices.
- Used kref instead of local ref counting for uci device and open count.
- Removed unlikely macro.V4:
- Fix locking to protect proper struct members.
- Updated documentation describing uci client driver use cases.
- Fixed uci ref counting inmhi_uci_openfor error case.
- Addressed style related review comments.V3: Added documentation for MHI UCI driver.
V2: Added mutex lock to prevent multiple readers to access same mhi buffer which can result into use after free.
Hemant Kumar (4):
bus: mhi: core: Add helper API to return number of free TREs
bus: mhi: core: MoveMHI_MAX_MTUto external header file
docs: Add documentation for userspace client interface
bus: mhi: clients: Add userspace client interface driverDocumentation/mhi/index.rst | 1 + Documentation/mhi/uci.rst | 39 +++ drivers/bus/mhi/Kconfig | 6 + drivers/bus/mhi/Makefile | 1 + drivers/bus/mhi/clients/Kconfig | 15 + drivers/bus/mhi/clients/Makefile | 3 + drivers/bus/mhi/clients/uci.c | 662 +++++++++++++++++++++++++++++++++++++++ drivers/bus/mhi/core/internal.h | 1 - drivers/bus/mhi/core/main.c | 12 + include/linux/mhi.h | 12 + 10 files changed, 751 insertions(+), 1 deletion(-)
Quoted 5 lines
create mode 100644
Documentation/mhi/uci.rstcreate mode 100644drivers/bus/mhi/clients/Kconfigcreate mode 100644drivers/bus/mhi/clients/Makefilecreate mode 100644drivers/bus/mhi/clients/uci.c
Could you please review my changes on V5? I tried addressing Greg's comment and would need help getting it reviewed from other contributors to MHI driver as well.
Thanks,
Hemant
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v5 4/4] bus: mhi: clients: Add userspace client interface driver
In reply to Hemant KumarQuoted 6 lines · Hemant Kumar
This MHI client driver allows userspace clients to transfer raw data between MHI device and host using standard file operations. Device file node is created with format
/dev/mhi_<controller_name>_<mhi_device_name>
Quoted 7 lines
Currently it supports LOOPBACK channel.
Signed-off-by Hemant Kumar <[email protected]>--- drivers/bus/mhi/Kconfig | 6 + drivers/bus/mhi/Makefile | 1 + drivers/bus/mhi/clients/Kconfig | 15 +
Why a whole new subdirectory for just one file?
Please keep it in the same directory until you get too many different files.
Quoted 39 lines
drivers/bus/mhi/clients/Makefile | 3 + drivers/bus/mhi/clients/uci.c | 662 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 687 insertions(+) create mode 100644 drivers/bus/mhi/clients/Kconfig create mode 100644 drivers/bus/mhi/clients/Makefile create mode 100644 drivers/bus/mhi/clients/uci.cdrivers/bus/mhi/Kconfig +6
-0@@ -20,3 +20,9 @@ config MHI_BUS_DEBUG Enable debugfs support for use with the MHI transport. Allows reading and/or modifying some values within the MHI controller for debug and test purposes. + +if MHI_BUS + +source "drivers/bus/mhi/clients/Kconfig" + +endifdrivers/bus/mhi/Makefile +1
-0@@ -1,2 +1,3 @@ # core layer obj-y += core/ +obj-y += clients/drivers/bus/mhi/clients/Kconfig new file +4
-0@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only + +menu "MHI clients support" +
drivers/bus/mhi/clients/Kconfig line 14
Quoted 10 lines
drivers/bus/mhi/clients/Kconfig new file +10
-0+config MHI_UCI + tristate "MHI UCI" + depends on MHI_BUS + help + MHI based userspace client interface driver is used for transferring + raw data between host and device using standard file operations from + userspace. Open, read, write, and close operations are supported + by this driver. Please check mhi_uci_match_table for all supported + channels that are exposed to userspace. +
Module name information?
drivers/bus/mhi/clients/Makefile line 3
Quoted 10 lines
drivers/bus/mhi/clients/Kconfig new file +1
-0+endmenudrivers/bus/mhi/clients/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_MHI_UCI) += uci.o
Why not mhi_ as a prefix? This is a very generic module name, right?
Quoted 13 lines
drivers/bus/mhi/clients/uci.c new file +7
-0@@ -0,0 +1,662 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.*/ + +#include <linux/kernel.h> +#include <linux/mhi.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h>
drivers/bus/mhi/clients/uci.c line 17
Quoted 10 lines
drivers/bus/mhi/clients/uci.c new file +10
-0+#include <linux/poll.h> + +#define DEVICE_NAME "mhi" +#define MHI_UCI_DRIVER_NAME "mhi_uci" +#define MAX_UCI_MINORS (128) + +static DEFINE_IDR (uci_idr); +static DEFINE_MUTEX (uci_idr_mutex); +static struct class *uci_dev_class; +static int uci_dev_major =-1 ;
Why init this to -1?
Quoted 50 lines
drivers/bus/mhi/clients/uci.c new file +50
-0+ +/** +* struct uci_chan - MHI channel for a uci device +* @wq: wait queue for reader/writer +* @lock: spin lock +* @pending: list of rx buffers userspace is waiting to read +* @cur_buf: current buffer userspace is reading +* @rx_size: size of the current rx buffer userspace is reading +*/ +struct uci_chan { +wait_queue_head_t wq; + +/* protects pending and cur_buf members */ +spinlock_t lock; + +struct list_head pending; +struct uci_buf *cur_buf; +size_t rx_size; +}; + +/** +* struct uci_buf - uci buffer +* @data: data buffer +* @len: length of data buffer +* @node: list node of the uci buffer +*/ +struct uci_buf { +void *data; +size_t len; +struct list_head node; +}; + +/** +* struct uci_dev - MHI uci device +* @minor: uci device node minor number +* @mhi_dev: associated mhi device object +* @chan: MHI channel name +* @lock: mutex lock +* @ul_chan: uplink uci channel object +* @dl_chan: downlink uci channel object +* @mtu: max tx buffer length +* @actual_mtu: maximum size of incoming buffer +* @ref_count: uci_dev reference count +* @open_count: device node open count +* @enabled: uci device probed +*/ +struct uci_dev { +unsigned int minor; +struct mhi_device *mhi_dev; +const char *chan;
drivers/bus/mhi/clients/uci.c line 77
Quoted 10 lines
drivers/bus/mhi/clients/uci.c new file +10
-0+ +/* protects uci_dev struct members */ +struct mutex lock; + +struct uci_chan ul_chan; +struct uci_chan dl_chan; +size_t mtu; +size_t actual_mtu; +struct kref ref_count; +struct kref open_count;
I'm stopping right here. A structure can only have ONE reference count to control its lifespan. You have 2 here, which guarantees that either you are using a kref incorrectly, or your code is totally confused and will break easily.
Please fix this as this is not how to do this.
Also, why does anyone need to care about the number of times that open() is called? The vfs layer should handle all of that for you, right?
No other misc driver has to deal with this multi-layered reference counting, so perhaps you are making this a lot more complex than it really has to be?
thanks,
greg k-h
Re: [PATCH v5 4/4] bus: mhi: clients: Add userspace client interface driver
Hi Greg,
Quoted 15 lines · Greg KH
Quoted 6 lines · Hemant Kumar
This MHI client driver allows userspace clients to transfer raw data between MHI device and host using standard file operations. Device file node is created with format
/dev/mhi_<controller_name>_<mhi_device_name>
Quoted 7 lines
Currently it supports LOOPBACK channel.
Signed-off-by Hemant Kumar <[email protected]>--- drivers/bus/mhi/Kconfig | 6 + drivers/bus/mhi/Makefile | 1 + drivers/bus/mhi/clients/Kconfig | 15 +
Quoted 4 lines
Why a whole new subdirectory for just one file?
Please keep it in the same directory until you get too many different files.
Currently MHI core driver files are under bus/mhi/core. Since MHI clients sit on top of core layer of MHI driver, i can move uci.c directly under /bus/mhi/.
Quoted 44 lines
Quoted 44 lines
drivers/bus/mhi/clients/Makefile | 3 + drivers/bus/mhi/clients/uci.c | 662 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 687 insertions(+)create mode 100644
drivers/bus/mhi/clients/Kconfigcreate mode 100644drivers/bus/mhi/clients/Makefilecreate mode 100644drivers/bus/mhi/clients/uci.cdrivers/bus/mhi/Kconfig +6
-0@@ -20,3 +20,9 @@ config MHI_BUS_DEBUG Enable debugfs support for use with the MHI transport. Allows reading and/or modifying some values within the MHI controller for debug and test purposes. + +if MHI_BUS + +source "drivers/bus/mhi/clients/Kconfig" + +endifdrivers/bus/mhi/Makefile +1
-0@@ -1,2 +1,3 @@ # core layer obj-y += core/ +obj-y += clients/drivers/bus/mhi/clients/Kconfig new file +8
-0@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only + +menu "MHI clients support" + +config MHI_UCI + tristate "MHI UCI" + depends on MHI_BUS + help
Quoted 8 lines
drivers/bus/mhi/clients/Kconfig line 14
Quoted 6 lines
drivers/bus/mhi/clients/Kconfig new file +6
-0+ MHI based userspace client interface driver is used for transferring + raw data between host and device using standard file operations from + userspace. Open, read, write, and close operations are supported + by this driver. Please check mhi_uci_match_table for all supported + channels that are exposed to userspace. +Module name information?
Thanks for pointing it out, will add in next patch set.
Quoted 14 lines
drivers/bus/mhi/clients/Makefile line 3
Quoted 12 lines
drivers/bus/mhi/clients/Kconfig new file +1
-0+endmenudrivers/bus/mhi/clients/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_MHI_UCI) += uci.oWhy not
mhi_as a prefix? This is a very generic module name, right?
how about adding
mhi_uci-y := uci.o
obj-$(CONFIG_MHI_UCI) += mhi_uci.o
Quoted 18 lines
Quoted 18 lines
drivers/bus/mhi/clients/uci.c new file +11
-0@@ -0,0 +1,662 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.*/ + +#include <linux/kernel.h> +#include <linux/mhi.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/poll.h> + +#define DEVICE_NAME "mhi" +#define MHI_UCI_DRIVER_NAME "mhi_uci"
Quoted 8 lines
drivers/bus/mhi/clients/uci.c line 17
Quoted 6 lines
drivers/bus/mhi/clients/uci.c new file +6
-0+#define MAX_UCI_MINORS (128) + +static DEFINE_IDR (uci_idr); +static DEFINE_MUTEX (uci_idr_mutex); +static struct class *uci_dev_class; +static int uci_dev_major =-1 ;Why init this to -1?
Idea was to initialize with invalid value, i can leave it zero initialized.
Quoted 67 lines
Quoted 51 lines
drivers/bus/mhi/clients/uci.c new file +50
-0+ +/** +* struct uci_chan - MHI channel for a uci device +* @wq: wait queue for reader/writer +* @lock: spin lock +* @pending: list of rx buffers userspace is waiting to read +* @cur_buf: current buffer userspace is reading +* @rx_size: size of the current rx buffer userspace is reading +*/ +struct uci_chan { +wait_queue_head_t wq; + +/* protects pending and cur_buf members */ +spinlock_t lock; + +struct list_head pending; +struct uci_buf *cur_buf; +size_t rx_size; +}; + +/** +* struct uci_buf - uci buffer +* @data: data buffer +* @len: length of data buffer +* @node: list node of the uci buffer +*/ +struct uci_buf { +void *data; +size_t len; +struct list_head node; +}; + +/** +* struct uci_dev - MHI uci device +* @minor: uci device node minor number +* @mhi_dev: associated mhi device object +* @chan: MHI channel name +* @lock: mutex lock +* @ul_chan: uplink uci channel object +* @dl_chan: downlink uci channel object +* @mtu: max tx buffer length +* @actual_mtu: maximum size of incoming buffer +* @ref_count: uci_dev reference count +* @open_count: device node open count +* @enabled: uci device probed +*/ +struct uci_dev { +unsigned int minor; +struct mhi_device *mhi_dev; +const char *chan;drivers/bus/mhi/clients/uci.c line 77
Quoted 10 lines
drivers/bus/mhi/clients/uci.c new file +10
-0+ +/* protects uci_dev struct members */ +struct mutex lock; + +struct uci_chan ul_chan; +struct uci_chan dl_chan; +size_t mtu; +size_t actual_mtu; +struct kref ref_count; +struct kref open_count;I'm stopping right here. A structure can only have ONE reference count to control its lifespan. You have 2 here, which guarantees that either you are using a kref incorrectly, or your code is totally confused and will break easily.
Quoted 4 lines
Please fix this as this is not how to do this.
Also, why does anyone need to care about the number of times that
open()is called? The vfs layer should handle all of that for you, right?
Reason for using open_count was to allow start MHI channel only when first open() was called and stop the MHI channel when last release() is called. Since uci driver just need to handle one open() from user space other calls to open can simply return -EBUSY. i will get rid of open_count and does not let multiple threads to open same file node.
Quoted 9 lines
No other misc driver has to deal with this multi-layered reference counting, so perhaps you are making this a lot more complex than it really has to be?
thanks,
greg k-h
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v5 4/4] bus: mhi: clients: Add userspace client interface driver
In reply to a message not in the archiveQuoted 22 lines · Hemant Kumar
Quoted 22 lines
Quoted 4 lines
drivers/bus/mhi/clients/uci.c new file +4
-0+struct uci_dev { +unsigned int minor; +struct mhi_device *mhi_dev; +const char *chan;drivers/bus/mhi/clients/uci.c line 77
Quoted 10 lines
drivers/bus/mhi/clients/uci.c new file +10
-0+ +/* protects uci_dev struct members */ +struct mutex lock; + +struct uci_chan ul_chan; +struct uci_chan dl_chan; +size_t mtu; +size_t actual_mtu; +struct kref ref_count; +struct kref open_count;I'm stopping right here. A structure can only have ONE reference count to control its lifespan. You have 2 here, which guarantees that either you are using a kref incorrectly, or your code is totally confused and will break easily.
Please fix this as this is not how to do this.
Quoted 7 lines
Quoted 2 lines
Also, why does anyone need to care about the number of times that
open()is called? The vfs layer should handle all of that for you, right?Reason for using
open_countwas to allow start MHI channel only when firstopen()was called and stop the MHI channel when lastrelease()is called. Since uci driver just need to handle oneopen()from user space other calls to open can simply return-EBUSY. i will get rid ofopen_countand does not let multiple threads to open same file node.
You will fail in trying to attempt only one open on your device node, sorry. You can properly trigger off of the first/last things, but having two different reference counts is NOT how to do this, those are to control the lifetime of a structure/object.
greg k-h