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

PCI: switchtec: Replace manual locks with guard

Replace lock/unlock pairs with guards to simplify and tidy up the code.

Generated-by: Coccinelle SmPL

Signed-off-by: Erick Karanja <karanja99erick@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Link: https://patch.msgid.link/20250828093556.810911-1-karanja99erick@gmail.com

authored by

Erick Karanja and committed by
Bjorn Helgaas
f2543da1 8f5ae30d

+11 -12
+11 -12
drivers/pci/switch/switchtec.c
··· 269 269 270 270 dev_dbg(&stdev->dev, "%s\n", __func__); 271 271 272 - mutex_lock(&stdev->mrpc_mutex); 272 + guard(mutex)(&stdev->mrpc_mutex); 273 273 cancel_delayed_work(&stdev->mrpc_timeout); 274 274 mrpc_complete_cmd(stdev); 275 - mutex_unlock(&stdev->mrpc_mutex); 276 275 } 277 276 278 277 static void mrpc_error_complete_cmd(struct switchtec_dev *stdev) ··· 1321 1322 cancel_delayed_work_sync(&stdev->mrpc_timeout); 1322 1323 1323 1324 /* Mark the hardware as unavailable and complete all completions */ 1324 - mutex_lock(&stdev->mrpc_mutex); 1325 - stdev->alive = false; 1325 + scoped_guard (mutex, &stdev->mrpc_mutex) { 1326 + stdev->alive = false; 1326 1327 1327 - /* Wake up and kill any users waiting on an MRPC request */ 1328 - list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { 1329 - stuser->cmd_done = true; 1330 - wake_up_interruptible(&stuser->cmd_comp); 1331 - list_del_init(&stuser->list); 1332 - stuser_put(stuser); 1328 + /* Wake up and kill any users waiting on an MRPC request */ 1329 + list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { 1330 + stuser->cmd_done = true; 1331 + wake_up_interruptible(&stuser->cmd_comp); 1332 + list_del_init(&stuser->list); 1333 + stuser_put(stuser); 1334 + } 1335 + 1333 1336 } 1334 - 1335 - mutex_unlock(&stdev->mrpc_mutex); 1336 1337 1337 1338 /* Wake up any users waiting on event_wq */ 1338 1339 wake_up_interruptible(&stdev->event_wq);