Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: ff-core - convert locking to guard notation

Use guard() and scoped_guard() notation instead of explicitly acquiring
and releasing spinlocks and mutexes to simplify the code and ensure that
all locks are released properly.

Link: https://lore.kernel.org/r/20241107071538.195340-2-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+29 -42
+29 -42
drivers/input/ff-core.c
··· 93 93 { 94 94 struct ff_device *ff = dev->ff; 95 95 struct ff_effect *old; 96 - int ret = 0; 96 + int error; 97 97 int id; 98 98 99 99 if (!test_bit(EV_FF, dev->evbit)) ··· 114 114 } 115 115 116 116 if (!test_bit(effect->type, ff->ffbit)) { 117 - ret = compat_effect(ff, effect); 118 - if (ret) 119 - return ret; 117 + error = compat_effect(ff, effect); 118 + if (error) 119 + return error; 120 120 } 121 121 122 - mutex_lock(&ff->mutex); 122 + guard(mutex)(&ff->mutex); 123 123 124 124 if (effect->id == -1) { 125 125 for (id = 0; id < ff->max_effects; id++) 126 126 if (!ff->effect_owners[id]) 127 127 break; 128 128 129 - if (id >= ff->max_effects) { 130 - ret = -ENOSPC; 131 - goto out; 132 - } 129 + if (id >= ff->max_effects) 130 + return -ENOSPC; 133 131 134 132 effect->id = id; 135 133 old = NULL; ··· 135 137 } else { 136 138 id = effect->id; 137 139 138 - ret = check_effect_access(ff, id, file); 139 - if (ret) 140 - goto out; 140 + error = check_effect_access(ff, id, file); 141 + if (error) 142 + return error; 141 143 142 144 old = &ff->effects[id]; 143 145 144 - if (!check_effects_compatible(effect, old)) { 145 - ret = -EINVAL; 146 - goto out; 147 - } 146 + if (!check_effects_compatible(effect, old)) 147 + return -EINVAL; 148 148 } 149 149 150 - ret = ff->upload(dev, effect, old); 151 - if (ret) 152 - goto out; 150 + error = ff->upload(dev, effect, old); 151 + if (error) 152 + return error; 153 153 154 - spin_lock_irq(&dev->event_lock); 155 - ff->effects[id] = *effect; 156 - ff->effect_owners[id] = file; 157 - spin_unlock_irq(&dev->event_lock); 154 + scoped_guard(spinlock_irq, &dev->event_lock) { 155 + ff->effects[id] = *effect; 156 + ff->effect_owners[id] = file; 157 + } 158 158 159 - out: 160 - mutex_unlock(&ff->mutex); 161 - return ret; 159 + return 0; 162 160 } 163 161 EXPORT_SYMBOL_GPL(input_ff_upload); 164 162 ··· 172 178 if (error) 173 179 return error; 174 180 175 - spin_lock_irq(&dev->event_lock); 176 - ff->playback(dev, effect_id, 0); 177 - ff->effect_owners[effect_id] = NULL; 178 - spin_unlock_irq(&dev->event_lock); 181 + scoped_guard(spinlock_irq, &dev->event_lock) { 182 + ff->playback(dev, effect_id, 0); 183 + ff->effect_owners[effect_id] = NULL; 184 + } 179 185 180 186 if (ff->erase) { 181 187 error = ff->erase(dev, effect_id); 182 188 if (error) { 183 - spin_lock_irq(&dev->event_lock); 184 - ff->effect_owners[effect_id] = file; 185 - spin_unlock_irq(&dev->event_lock); 189 + scoped_guard(spinlock_irq, &dev->event_lock) 190 + ff->effect_owners[effect_id] = file; 186 191 187 192 return error; 188 193 } ··· 203 210 int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file) 204 211 { 205 212 struct ff_device *ff = dev->ff; 206 - int ret; 207 213 208 214 if (!test_bit(EV_FF, dev->evbit)) 209 215 return -ENOSYS; 210 216 211 - mutex_lock(&ff->mutex); 212 - ret = erase_effect(dev, effect_id, file); 213 - mutex_unlock(&ff->mutex); 214 - 215 - return ret; 217 + guard(mutex)(&ff->mutex); 218 + return erase_effect(dev, effect_id, file); 216 219 } 217 220 EXPORT_SYMBOL_GPL(input_ff_erase); 218 221 ··· 228 239 229 240 dev_dbg(&dev->dev, "flushing now\n"); 230 241 231 - mutex_lock(&ff->mutex); 242 + guard(mutex)(&ff->mutex); 232 243 233 244 for (i = 0; i < ff->max_effects; i++) 234 245 erase_effect(dev, i, file); 235 - 236 - mutex_unlock(&ff->mutex); 237 246 238 247 return 0; 239 248 }