lkml.org 
[lkml]   [2020]   [Sep]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 4/4] bus: mhi: clients: Add userspace client interface driver
On Fri, Sep 11, 2020 at 06:28:02AM +0000, Hemant Kumar wrote:
> > > +struct uci_dev {
> > > + unsigned int minor;
> > > + struct mhi_device *mhi_dev;
> > > + const char *chan;
> > > +
> > > + /* 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?
> 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.

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

\
 
 \ /
  Last update: 2020-09-11 09:48    [W:1.648 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site