Re: [PATCH v2 (resend)] media: imon: reorganize serialization

Tetsuo Handa
2022-05-02T13:04:29Z

On 2022/05/02 21:53, Greg KH wrote:
>> @@ -153,6 +153,24 @@ struct imon_context {
>> const struct imon_usb_dev_descr *dev_descr;
>> /* device description with key */
>> /* table for front panels */
>> + /*
>> + * Fields for deferring free_imon_context().
>> + *
>> + * Since reference to "struct imon_context" is stored into
>> + * "struct file_operations"->private_data, we need to remember
>> + * how many file descriptors might access this "struct imon_context".
>> + */
>> + refcount_t users;
>
> Are you sure this is going to work properly?
>
> How do you handle userspace passing around file descriptors to other
> processes?
>
> You really should not ever have to count this.

Passing around file descriptors results in nothing but delay of freeing memory.
Is this so fatal problem?

static void free_imon_context(struct imon_context *ictx)
{
struct device *dev = ictx->dev;

usb_free_urb(ictx->tx_urb);
usb_free_urb(ictx->rx_urb_intf0);
usb_free_urb(ictx->rx_urb_intf1);
kfree(ictx);

dev_dbg(dev, "%s: iMON context freed\n", __func__);
}

If this is so fatal, can we call usb_free_urb() upon imon_disconnect() ?