| .. | .. |
|---|
| 229 | 229 | */ |
|---|
| 230 | 230 | |
|---|
| 231 | 231 | static const char *CHIP; |
|---|
| 232 | +static DEFINE_MUTEX(sb_mutex); /* Serialize superblock operations */ |
|---|
| 232 | 233 | |
|---|
| 233 | 234 | /*----------------------------------------------------------------------*/ |
|---|
| 234 | 235 | |
|---|
| .. | .. |
|---|
| 2012 | 2013 | { |
|---|
| 2013 | 2014 | struct inode *inode; |
|---|
| 2014 | 2015 | struct dev_data *dev; |
|---|
| 2016 | + int rc; |
|---|
| 2015 | 2017 | |
|---|
| 2016 | | - if (the_device) |
|---|
| 2017 | | - return -ESRCH; |
|---|
| 2018 | + mutex_lock(&sb_mutex); |
|---|
| 2019 | + |
|---|
| 2020 | + if (the_device) { |
|---|
| 2021 | + rc = -ESRCH; |
|---|
| 2022 | + goto Done; |
|---|
| 2023 | + } |
|---|
| 2018 | 2024 | |
|---|
| 2019 | 2025 | CHIP = usb_get_gadget_udc_name(); |
|---|
| 2020 | | - if (!CHIP) |
|---|
| 2021 | | - return -ENODEV; |
|---|
| 2026 | + if (!CHIP) { |
|---|
| 2027 | + rc = -ENODEV; |
|---|
| 2028 | + goto Done; |
|---|
| 2029 | + } |
|---|
| 2022 | 2030 | |
|---|
| 2023 | 2031 | /* superblock */ |
|---|
| 2024 | 2032 | sb->s_blocksize = PAGE_SIZE; |
|---|
| .. | .. |
|---|
| 2055 | 2063 | * from binding to a controller. |
|---|
| 2056 | 2064 | */ |
|---|
| 2057 | 2065 | the_device = dev; |
|---|
| 2058 | | - return 0; |
|---|
| 2066 | + rc = 0; |
|---|
| 2067 | + goto Done; |
|---|
| 2059 | 2068 | |
|---|
| 2060 | | -Enomem: |
|---|
| 2069 | + Enomem: |
|---|
| 2061 | 2070 | kfree(CHIP); |
|---|
| 2062 | 2071 | CHIP = NULL; |
|---|
| 2072 | + rc = -ENOMEM; |
|---|
| 2063 | 2073 | |
|---|
| 2064 | | - return -ENOMEM; |
|---|
| 2074 | + Done: |
|---|
| 2075 | + mutex_unlock(&sb_mutex); |
|---|
| 2076 | + return rc; |
|---|
| 2065 | 2077 | } |
|---|
| 2066 | 2078 | |
|---|
| 2067 | 2079 | /* "mount -t gadgetfs path /dev/gadget" ends up here */ |
|---|
| .. | .. |
|---|
| 2083 | 2095 | static void |
|---|
| 2084 | 2096 | gadgetfs_kill_sb (struct super_block *sb) |
|---|
| 2085 | 2097 | { |
|---|
| 2098 | + mutex_lock(&sb_mutex); |
|---|
| 2086 | 2099 | kill_litter_super (sb); |
|---|
| 2087 | 2100 | if (the_device) { |
|---|
| 2088 | 2101 | put_dev (the_device); |
|---|
| .. | .. |
|---|
| 2090 | 2103 | } |
|---|
| 2091 | 2104 | kfree(CHIP); |
|---|
| 2092 | 2105 | CHIP = NULL; |
|---|
| 2106 | + mutex_unlock(&sb_mutex); |
|---|
| 2093 | 2107 | } |
|---|
| 2094 | 2108 | |
|---|
| 2095 | 2109 | /*----------------------------------------------------------------------*/ |
|---|