@@ -93,7 +93,7 @@ int input_ff_upload(struct input_dev *dev, struct ff_effect *effect,
9393{
9494 struct ff_device * ff = dev -> ff ;
9595 struct ff_effect * old ;
96- int ret = 0 ;
96+ int error ;
9797 int id ;
9898
9999 if (!test_bit (EV_FF , dev -> evbit ))
@@ -114,53 +114,47 @@ int input_ff_upload(struct input_dev *dev, struct ff_effect *effect,
114114 }
115115
116116 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 ;
120120 }
121121
122- mutex_lock (& ff -> mutex );
122+ guard ( mutex ) (& ff -> mutex );
123123
124124 if (effect -> id == -1 ) {
125125 for (id = 0 ; id < ff -> max_effects ; id ++ )
126126 if (!ff -> effect_owners [id ])
127127 break ;
128128
129- if (id >= ff -> max_effects ) {
130- ret = - ENOSPC ;
131- goto out ;
132- }
129+ if (id >= ff -> max_effects )
130+ return - ENOSPC ;
133131
134132 effect -> id = id ;
135133 old = NULL ;
136134
137135 } else {
138136 id = effect -> id ;
139137
140- ret = check_effect_access (ff , id , file );
141- if (ret )
142- goto out ;
138+ error = check_effect_access (ff , id , file );
139+ if (error )
140+ return error ;
143141
144142 old = & ff -> effects [id ];
145143
146- if (!check_effects_compatible (effect , old )) {
147- ret = - EINVAL ;
148- goto out ;
149- }
144+ if (!check_effects_compatible (effect , old ))
145+ return - EINVAL ;
150146 }
151147
152- ret = ff -> upload (dev , effect , old );
153- if (ret )
154- goto out ;
148+ error = ff -> upload (dev , effect , old );
149+ if (error )
150+ return error ;
155151
156- spin_lock_irq ( & dev -> event_lock );
157- ff -> effects [id ] = * effect ;
158- ff -> effect_owners [id ] = file ;
159- spin_unlock_irq ( & dev -> event_lock );
152+ scoped_guard ( spinlock_irq , & dev -> event_lock ) {
153+ ff -> effects [id ] = * effect ;
154+ ff -> effect_owners [id ] = file ;
155+ }
160156
161- out :
162- mutex_unlock (& ff -> mutex );
163- return ret ;
157+ return 0 ;
164158}
165159EXPORT_SYMBOL_GPL (input_ff_upload );
166160
@@ -178,17 +172,16 @@ static int erase_effect(struct input_dev *dev, int effect_id,
178172 if (error )
179173 return error ;
180174
181- spin_lock_irq ( & dev -> event_lock );
182- ff -> playback (dev , effect_id , 0 );
183- ff -> effect_owners [effect_id ] = NULL ;
184- spin_unlock_irq ( & dev -> event_lock );
175+ scoped_guard ( spinlock_irq , & dev -> event_lock ) {
176+ ff -> playback (dev , effect_id , 0 );
177+ ff -> effect_owners [effect_id ] = NULL ;
178+ }
185179
186180 if (ff -> erase ) {
187181 error = ff -> erase (dev , effect_id );
188182 if (error ) {
189- spin_lock_irq (& dev -> event_lock );
190- ff -> effect_owners [effect_id ] = file ;
191- spin_unlock_irq (& dev -> event_lock );
183+ scoped_guard (spinlock_irq , & dev -> event_lock )
184+ ff -> effect_owners [effect_id ] = file ;
192185
193186 return error ;
194187 }
@@ -210,16 +203,12 @@ static int erase_effect(struct input_dev *dev, int effect_id,
210203int input_ff_erase (struct input_dev * dev , int effect_id , struct file * file )
211204{
212205 struct ff_device * ff = dev -> ff ;
213- int ret ;
214206
215207 if (!test_bit (EV_FF , dev -> evbit ))
216208 return - ENOSYS ;
217209
218- mutex_lock (& ff -> mutex );
219- ret = erase_effect (dev , effect_id , file );
220- mutex_unlock (& ff -> mutex );
221-
222- return ret ;
210+ guard (mutex )(& ff -> mutex );
211+ return erase_effect (dev , effect_id , file );
223212}
224213EXPORT_SYMBOL_GPL (input_ff_erase );
225214
@@ -239,13 +228,11 @@ int input_ff_flush(struct input_dev *dev, struct file *file)
239228
240229 dev_dbg (& dev -> dev , "flushing now\n" );
241230
242- mutex_lock (& ff -> mutex );
231+ guard ( mutex ) (& ff -> mutex );
243232
244233 for (i = 0 ; i < ff -> max_effects ; i ++ )
245234 erase_effect (dev , i , file );
246235
247- mutex_unlock (& ff -> mutex );
248-
249236 return 0 ;
250237}
251238EXPORT_SYMBOL_GPL (input_ff_flush );
0 commit comments