From: Hemant Kumar <hemantk@codeaurora.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: manivannan.sadhasivam@linaro.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org, jhugo@codeaurora.org,
bbhatt@codeaurora.org
Subject: Re: [PATCH v6 4/4] bus: mhi: Add userspace client interface driver
Date: Fri, 18 Sep 2020 11:14:08 -0700 [thread overview]
Message-ID: <4e60cac3-d680-93ea-922e-bd4f22cf3f0a@codeaurora.org> (raw)
In-Reply-To: <20200917164419.GC721081@kroah.com>
Hi Greg,
On 9/17/20 9:44 AM, Greg KH wrote:
> On Wed, Sep 16, 2020 at 12:56:07PM -0700, Hemant Kumar wrote:
...
...
>> +
>> +static int mhi_uci_open(struct inode *inode, struct file *filp)
>> +{
>> + struct uci_dev *udev = NULL;
>> + unsigned int minor = iminor(inode);
>> + int ret = -EIO;
>> + struct uci_buf *buf_itr, *tmp;
>> + struct uci_chan *dl_chan;
>> + struct mhi_device *mhi_dev;
>> + struct device *dev;
>> +
>> + mutex_lock(&uci_idr_mutex);
>> + udev = idr_find(&uci_idr, minor);
>> + mutex_unlock(&uci_idr_mutex);
>> + if (!udev) {
>> + pr_err("uci dev: minor %d not found\n", minor);
>
> Don't spam the kernel log for things that users can do :(
i will change it to a pr_debug, as it helps to debug why open() is failing.
>
>> + ret = -ENODEV;
>> + goto error_no_dev;
>> + }
>> +
>> + kref_get(&udev->ref_count);
>
> Why grab a reference? What does that help with?
In case open() and driver remove() are racing, it helps to prevent use
after free of udev in open().
>
>> +
>> + mhi_dev = udev->mhi_dev;
>> + dev = &mhi_dev->dev;
>> +
>> + mutex_lock(&udev->lock);
>> + if (kref_read(&udev->ref_count) > 2) {
>> + dev_dbg(dev, "Node already opened\n");
>
> Nope, this is NOT doing what you think it is doing.
>
> I told you before, do not try to keep a device node from being opened
> multiple times, as it will always fail (think about passing file handles
> around between programs...)
>
> If userspace wants to do this, it will do it. If your driver can't
> handle that, that's fine, userspace will learn not to do that. But the
> kernel can not prevent this from happening.
This check is not returning error, instead just setting
filp->private_data = udev; and return 0; It is skipping channel prepare
and queuing of inbound buffers which was done by first open().
>
> Also note that reading a kref value is a HUGE sign that the code is
> incorrect, you should never care about the value of a reference. Maybe
> if it is 0, but that's a special case...
In previous patch this was done using separate open reference count and
after removing that i was relying on udev ref count. MHI channel prepare
and buffer allocation for a give channel suppose to happen at open() and
only for first open() call.
>
> Anyway, given that you ignored my previous review comments here, I'm
> loath to keep reviewing this patch series. Please get others to review
> it first before sending it back as I don't like being the only one doing
> this type of work...
Thanks for reviewing my patch series Greg and help making it a better
driver!
>
> thanks,
>
> greg k-h
>
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
next prev parent reply other threads:[~2020-09-18 18:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-16 19:56 [PATCH v6 0/4] user space client interface driver Hemant Kumar
2020-09-16 19:56 ` [PATCH v6 1/4] bus: mhi: core: Add helper API to return number of free TREs Hemant Kumar
2020-09-27 3:12 ` Manivannan Sadhasivam
2020-09-16 19:56 ` [PATCH v6 2/4] bus: mhi: core: Move MHI_MAX_MTU to external header file Hemant Kumar
2020-09-27 3:14 ` Manivannan Sadhasivam
2020-09-16 19:56 ` [PATCH v6 3/4] docs: Add documentation for userspace client interface Hemant Kumar
2020-09-16 19:56 ` [PATCH v6 4/4] bus: mhi: Add userspace client interface driver Hemant Kumar
2020-09-16 21:52 ` Randy Dunlap
2020-09-17 16:40 ` Greg KH
2020-09-18 17:53 ` Hemant Kumar
2020-09-17 16:44 ` Greg KH
2020-09-18 18:14 ` Hemant Kumar [this message]
2020-09-19 6:03 ` Greg KH
2020-09-18 20:08 ` Jeffrey Hugo
2020-09-23 18:17 ` Hemant Kumar
2020-09-22 11:10 ` Loic Poulain
2020-10-01 3:30 ` Hemant Kumar
2020-09-17 8:47 ` [PATCH v6 0/4] user space " Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4e60cac3-d680-93ea-922e-bd4f22cf3f0a@codeaurora.org \
--to=hemantk@codeaurora.org \
--cc=bbhatt@codeaurora.org \
--cc=gregkh@linuxfoundation.org \
--cc=jhugo@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).