Skip to content

Commit 62b93f9

Browse files
Erickkaranjaopsiff
authored andcommitted
PCI: switchtec: Replace manual locks with guard
[Upstream commit f2543da] 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 Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
1 parent b4fa078 commit 62b93f9

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

drivers/pci/switch/switchtec.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,9 @@ static void mrpc_event_work(struct work_struct *work)
267267

268268
dev_dbg(&stdev->dev, "%s\n", __func__);
269269

270-
mutex_lock(&stdev->mrpc_mutex);
270+
guard(mutex)(&stdev->mrpc_mutex);
271271
cancel_delayed_work(&stdev->mrpc_timeout);
272272
mrpc_complete_cmd(stdev);
273-
mutex_unlock(&stdev->mrpc_mutex);
274273
}
275274

276275
static void mrpc_error_complete_cmd(struct switchtec_dev *stdev)
@@ -1320,18 +1319,18 @@ static void stdev_kill(struct switchtec_dev *stdev)
13201319
cancel_delayed_work_sync(&stdev->mrpc_timeout);
13211320

13221321
/* Mark the hardware as unavailable and complete all completions */
1323-
mutex_lock(&stdev->mrpc_mutex);
1324-
stdev->alive = false;
1325-
1326-
/* Wake up and kill any users waiting on an MRPC request */
1327-
list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) {
1328-
stuser->cmd_done = true;
1329-
wake_up_interruptible(&stuser->cmd_comp);
1330-
list_del_init(&stuser->list);
1331-
stuser_put(stuser);
1332-
}
1322+
scoped_guard (mutex, &stdev->mrpc_mutex) {
1323+
stdev->alive = false;
1324+
1325+
/* Wake up and kill any users waiting on an MRPC request */
1326+
list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) {
1327+
stuser->cmd_done = true;
1328+
wake_up_interruptible(&stuser->cmd_comp);
1329+
list_del_init(&stuser->list);
1330+
stuser_put(stuser);
1331+
}
13331332

1334-
mutex_unlock(&stdev->mrpc_mutex);
1333+
}
13351334

13361335
/* Wake up any users waiting on event_wq */
13371336
wake_up_interruptible(&stdev->event_wq);

0 commit comments

Comments
 (0)