@@ -909,6 +909,10 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
909
909
enum ep0_state state ;
910
910
911
911
spin_lock_irq (& dev -> lock );
912
+ if (dev -> state <= STATE_DEV_OPENED ) {
913
+ retval = - EINVAL ;
914
+ goto done ;
915
+ }
912
916
913
917
/* report fd mode change before acting on it */
914
918
if (dev -> setup_abort ) {
@@ -1107,8 +1111,6 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1107
1111
struct dev_data * dev = fd -> private_data ;
1108
1112
ssize_t retval = - ESRCH ;
1109
1113
1110
- spin_lock_irq (& dev -> lock );
1111
-
1112
1114
/* report fd mode change before acting on it */
1113
1115
if (dev -> setup_abort ) {
1114
1116
dev -> setup_abort = 0 ;
@@ -1154,7 +1156,6 @@ ep0_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1154
1156
} else
1155
1157
DBG (dev , "fail %s, state %d\n" , __func__ , dev -> state );
1156
1158
1157
- spin_unlock_irq (& dev -> lock );
1158
1159
return retval ;
1159
1160
}
1160
1161
@@ -1201,6 +1202,9 @@ ep0_poll (struct file *fd, poll_table *wait)
1201
1202
struct dev_data * dev = fd -> private_data ;
1202
1203
int mask = 0 ;
1203
1204
1205
+ if (dev -> state <= STATE_DEV_OPENED )
1206
+ return DEFAULT_POLLMASK ;
1207
+
1204
1208
poll_wait (fd , & dev -> wait , wait );
1205
1209
1206
1210
spin_lock_irq (& dev -> lock );
@@ -1236,19 +1240,6 @@ static long dev_ioctl (struct file *fd, unsigned code, unsigned long value)
1236
1240
return ret ;
1237
1241
}
1238
1242
1239
- /* used after device configuration */
1240
- static const struct file_operations ep0_io_operations = {
1241
- .owner = THIS_MODULE ,
1242
- .llseek = no_llseek ,
1243
-
1244
- .read = ep0_read ,
1245
- .write = ep0_write ,
1246
- .fasync = ep0_fasync ,
1247
- .poll = ep0_poll ,
1248
- .unlocked_ioctl = dev_ioctl ,
1249
- .release = dev_release ,
1250
- };
1251
-
1252
1243
/*----------------------------------------------------------------------*/
1253
1244
1254
1245
/* The in-kernel gadget driver handles most ep0 issues, in particular
@@ -1772,6 +1763,14 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1772
1763
u32 tag ;
1773
1764
char * kbuf ;
1774
1765
1766
+ spin_lock_irq (& dev -> lock );
1767
+ if (dev -> state > STATE_DEV_OPENED ) {
1768
+ value = ep0_write (fd , buf , len , ptr );
1769
+ spin_unlock_irq (& dev -> lock );
1770
+ return value ;
1771
+ }
1772
+ spin_unlock_irq (& dev -> lock );
1773
+
1775
1774
if (len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4 ))
1776
1775
return - EINVAL ;
1777
1776
@@ -1845,7 +1844,6 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1845
1844
* on, they can work ... except in cleanup paths that
1846
1845
* kick in after the ep0 descriptor is closed.
1847
1846
*/
1848
- fd -> f_op = & ep0_io_operations ;
1849
1847
value = len ;
1850
1848
}
1851
1849
return value ;
@@ -1876,12 +1874,14 @@ dev_open (struct inode *inode, struct file *fd)
1876
1874
return value ;
1877
1875
}
1878
1876
1879
- static const struct file_operations dev_init_operations = {
1877
+ static const struct file_operations ep0_operations = {
1880
1878
.llseek = no_llseek ,
1881
1879
1882
1880
.open = dev_open ,
1881
+ .read = ep0_read ,
1883
1882
.write = dev_config ,
1884
1883
.fasync = ep0_fasync ,
1884
+ .poll = ep0_poll ,
1885
1885
.unlocked_ioctl = dev_ioctl ,
1886
1886
.release = dev_release ,
1887
1887
};
@@ -1997,7 +1997,7 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
1997
1997
goto Enomem ;
1998
1998
1999
1999
dev -> sb = sb ;
2000
- dev -> dentry = gadgetfs_create_file (sb , CHIP , dev , & dev_init_operations );
2000
+ dev -> dentry = gadgetfs_create_file (sb , CHIP , dev , & ep0_operations );
2001
2001
if (!dev -> dentry ) {
2002
2002
put_dev (dev );
2003
2003
goto Enomem ;
0 commit comments