Skip to content

Commit 8ea7819

Browse files
Shrikanth Hegdemaddy-kerneldev
authored andcommitted
powerpc: powernv: ocxl: use lock guard for mutex
use guard(mutex) for scope based resource management of mutex. This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/[email protected]/T/#u Reviewed-by: Srikar Dronamraju <[email protected]> Acked-by: Andrew Donnellan <[email protected]> Signed-off-by: Shrikanth Hegde <[email protected]> Tested-by: Venkat Rao Bagalkote <[email protected]> Signed-off-by: Madhavan Srinivasan <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 37989b5 commit 8ea7819

File tree

1 file changed

+3
-9
lines changed
  • arch/powerpc/platforms/powernv

1 file changed

+3
-9
lines changed

arch/powerpc/platforms/powernv/ocxl.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,11 @@ static void pnv_ocxl_fixup_actag(struct pci_dev *dev)
172172
if (phb->type != PNV_PHB_NPU_OCAPI)
173173
return;
174174

175-
mutex_lock(&links_list_lock);
175+
guard(mutex)(&links_list_lock);
176176

177177
link = find_link(dev);
178178
if (!link) {
179179
dev_warn(&dev->dev, "couldn't update actag information\n");
180-
mutex_unlock(&links_list_lock);
181180
return;
182181
}
183182

@@ -206,7 +205,6 @@ static void pnv_ocxl_fixup_actag(struct pci_dev *dev)
206205
dev_dbg(&dev->dev, "total actags for function: %d\n",
207206
link->fn_desired_actags[PCI_FUNC(dev->devfn)]);
208207

209-
mutex_unlock(&links_list_lock);
210208
}
211209
DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pnv_ocxl_fixup_actag);
212210

@@ -253,12 +251,11 @@ int pnv_ocxl_get_actag(struct pci_dev *dev, u16 *base, u16 *enabled,
253251
{
254252
struct npu_link *link;
255253

256-
mutex_lock(&links_list_lock);
254+
guard(mutex)(&links_list_lock);
257255

258256
link = find_link(dev);
259257
if (!link) {
260258
dev_err(&dev->dev, "actag information not found\n");
261-
mutex_unlock(&links_list_lock);
262259
return -ENODEV;
263260
}
264261
/*
@@ -274,7 +271,6 @@ int pnv_ocxl_get_actag(struct pci_dev *dev, u16 *base, u16 *enabled,
274271
*enabled = link->fn_actags[PCI_FUNC(dev->devfn)].count;
275272
*supported = link->fn_desired_actags[PCI_FUNC(dev->devfn)];
276273

277-
mutex_unlock(&links_list_lock);
278274
return 0;
279275
}
280276
EXPORT_SYMBOL_GPL(pnv_ocxl_get_actag);
@@ -293,12 +289,11 @@ int pnv_ocxl_get_pasid_count(struct pci_dev *dev, int *count)
293289
*
294290
* We only support one AFU-carrying function for now.
295291
*/
296-
mutex_lock(&links_list_lock);
292+
guard(mutex)(&links_list_lock);
297293

298294
link = find_link(dev);
299295
if (!link) {
300296
dev_err(&dev->dev, "actag information not found\n");
301-
mutex_unlock(&links_list_lock);
302297
return -ENODEV;
303298
}
304299

@@ -309,7 +304,6 @@ int pnv_ocxl_get_pasid_count(struct pci_dev *dev, int *count)
309304
break;
310305
}
311306

312-
mutex_unlock(&links_list_lock);
313307
dev_dbg(&dev->dev, "%d PASIDs available for function\n",
314308
rc ? 0 : *count);
315309
return rc;

0 commit comments

Comments
 (0)