--- x/drivers/usb/gadget/legacy/inode.c +++ y/drivers/usb/gadget/legacy/inode.c @@ -1658,6 +1658,7 @@ gadgetfs_unbind (struct usb_gadget *gadg } static struct dev_data *the_device; +static DEFINE_MUTEX(the_device_mutex); static int gadgetfs_bind(struct usb_gadget *gadget, struct usb_gadget_driver *driver) @@ -2011,12 +2012,18 @@ gadgetfs_fill_super (struct super_block struct inode *inode; struct dev_data *dev; - if (the_device) + mutex_lock(&the_device_mutex); + + if (the_device) { + mutex_unlock(&the_device_mutex); return -ESRCH; + } CHIP = usb_get_gadget_udc_name(); - if (!CHIP) + if (!CHIP) { + mutex_unlock(&the_device_mutex); return -ENODEV; + } /* superblock */ sb->s_blocksize = PAGE_SIZE; @@ -2053,9 +2060,11 @@ gadgetfs_fill_super (struct super_block * from binding to a controller. */ the_device = dev; + mutex_unlock(&the_device_mutex); return 0; Enomem: + mutex_unlock(&the_device_mutex); kfree(CHIP); CHIP = NULL; @@ -2082,10 +2091,12 @@ static void gadgetfs_kill_sb (struct super_block *sb) { kill_litter_super (sb); + mutex_lock(&the_device_mutex); if (the_device) { put_dev (the_device); the_device = NULL; } + mutex_unlock(&the_device_mutex); kfree(CHIP); CHIP = NULL; }