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: cma3000_d0x - use guard notation when acquiring mutex

Using guard notation makes the code more compact and error handling
more robust by ensuring that mutexes are released in all code paths
when control leaves critical section.

Reviewed-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240904044244.1042174-5-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+4 -12
+4 -12
drivers/input/misc/cma3000_d0x.c
··· 217 217 { 218 218 struct cma3000_accl_data *data = input_get_drvdata(input_dev); 219 219 220 - mutex_lock(&data->mutex); 220 + guard(mutex)(&data->mutex); 221 221 222 222 if (!data->suspended) 223 223 cma3000_poweron(data); 224 224 225 225 data->opened = true; 226 - 227 - mutex_unlock(&data->mutex); 228 226 229 227 return 0; 230 228 } ··· 231 233 { 232 234 struct cma3000_accl_data *data = input_get_drvdata(input_dev); 233 235 234 - mutex_lock(&data->mutex); 236 + guard(mutex)(&data->mutex); 235 237 236 238 if (!data->suspended) 237 239 cma3000_poweroff(data); 238 240 239 241 data->opened = false; 240 - 241 - mutex_unlock(&data->mutex); 242 242 } 243 243 244 244 void cma3000_suspend(struct cma3000_accl_data *data) 245 245 { 246 - mutex_lock(&data->mutex); 246 + guard(mutex)(&data->mutex); 247 247 248 248 if (!data->suspended && data->opened) 249 249 cma3000_poweroff(data); 250 250 251 251 data->suspended = true; 252 - 253 - mutex_unlock(&data->mutex); 254 252 } 255 253 EXPORT_SYMBOL(cma3000_suspend); 256 254 257 255 258 256 void cma3000_resume(struct cma3000_accl_data *data) 259 257 { 260 - mutex_lock(&data->mutex); 258 + guard(mutex)(&data->mutex); 261 259 262 260 if (data->suspended && data->opened) 263 261 cma3000_poweron(data); 264 262 265 263 data->suspended = false; 266 - 267 - mutex_unlock(&data->mutex); 268 264 } 269 265 EXPORT_SYMBOL(cma3000_resume); 270 266