Re: [PATCH v2 2/3] usb: gadget: f_fs: add poll for endpoint 0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/17/2014 12:20 PM, Michal Nazarewicz wrote:
> On Fri, Jan 17 2014, Robert Baldyga wrote:
>> This patch adds poll function for file representing ep0.
>>
>> Ability of read from or write to ep0 file is related with actual state of ffs:
>> - When desctiptors or strings are not written yet, POLLOUT flag is set.
>> - If there is any event to read, POLLIN flag is set.
>> - If setup request was read, POLLIN and POLLOUT flag is set, to allow
>>   send response (by performing I/O operation consistent with setup request
>>   direction) or set stall (by performing I/O operation opposite  setup
>>   request direction).
>>
>> Signed-off-by: Robert Baldyga <r.baldyga@xxxxxxxxxxx>
>> ---
>>  drivers/usb/gadget/f_fs.c |   42 ++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 42 insertions(+)
>>
>> diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
>> @@ -558,6 +560,45 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
>>  	return ret;
>>  }
>>  
>> +static unsigned int ffs_ep0_poll(struct file *file, poll_table *wait)
>> +{
>> +	struct ffs_data *ffs = file->private_data;
>> +	unsigned int mask = POLLWRNORM;
>> +	int ret;
>> +
>> +	ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
>> +	if (unlikely(ret < 0))
>> +		return mask;
>> +
>> +	switch (ffs->state) {
>> +	case FFS_READ_DESCRIPTORS:
>> +	case FFS_READ_STRINGS:
>> +		mask |= POLLOUT;
>> +		break;
>> +
>> +	case FFS_ACTIVE:
>> +		switch (FFS_SETUP_STATE(ffs)) {
>> +		case FFS_NO_SETUP:
>> +			if (ffs->ev.count)
>> +				mask |= POLLIN;
>> +			break;
>> +
>> +		case FFS_SETUP_PENDING:
>> +			mask |= (POLLIN | POLLOUT);
>> +			break;
>> +
>> +		case FFS_SETUP_CANCELED:
> 
> The FFS_SETUP_CANCELED and FFS_SETUP_PENDING are the same case.  ep0
> never recovers from FFS_SETUP_CANCELED on its own, it waits for user
> space to attempt to read or write something.  So unless I'm missing
> something the two cases should be merged together and in both POLLIN and
> POLLOUT needs to be set.
> 

Hmm, it seems like it doesn't work this way. In both read and write
functions in ep0 file operations, there is check at the beginning:

if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED)
	return -EIDRM;

So read/write does nothing when FFS_SETUP_CANCELED state is set.

>> +			break;
>> +		}
>> +	case FFS_CLOSING:
>> +		break;
>> +	}
>> +
>> +	mutex_unlock(&ffs->mutex);
>> +
>> +	return mask;
>> +}
>> +
>>  static const struct file_operations ffs_ep0_operations = {
>>  	.llseek =	no_llseek,
>>  
> 
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux