Skip to content

Commit f35d50d

Browse files
committed
Replace spin locks with mutex to avoid large atomic context
- fixes scheduling while atomic caused by called kernel functions create mutexes inside the spin locked section
1 parent 704737f commit f35d50d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

patches/linux_uio/uio_pci_dma.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ struct uio_pci_dma_device
7171
bool msi_enabled;
7272
};
7373

74-
spinlock_t alloc_free_lock;
74+
DEFINE_MUTEX(alloc_free_lock);
75+
7576
static inline int
7677
uio_pci_dma_allocate_kernel_memory(struct uio_pci_dma_private *priv);
7778

@@ -255,7 +256,7 @@ probe
255256
struct kset *kset;
256257
bool msi_enabled = false;
257258

258-
spin_lock_init(&alloc_free_lock);
259+
mutex_init(&alloc_free_lock);
259260

260261
/* attr_bin_request */
261262
BIN_ATTR_PDA(request, sizeof(struct uio_pci_dma_private), S_IWUSR | S_IWGRP,
@@ -525,7 +526,7 @@ BIN_ATTR_WRITE_CALLBACK( request_buffer_write )
525526
if(count != sizeof(struct uio_pci_dma_private) )
526527
{ UIO_PDA_ERROR("Invalid size of request struct -> aborting!\n", exit); }
527528

528-
spin_lock(&alloc_free_lock);
529+
mutex_lock(&alloc_free_lock);
529530

530531
UIO_DEBUG_PRINTF("MB = %zu are requested\n", (request->size/MB_SIZE) );
531532

@@ -589,7 +590,7 @@ BIN_ATTR_WRITE_CALLBACK( request_buffer_write )
589590

590591
kobject_uevent(&priv->kobj, KOBJ_ADD);
591592

592-
spin_unlock(&alloc_free_lock);
593+
mutex_unlock(&alloc_free_lock);
593594

594595
UIO_DEBUG_RETURN(sizeof(struct uio_pci_dma_private));
595596

@@ -616,7 +617,7 @@ BIN_ATTR_WRITE_CALLBACK( request_buffer_write )
616617
priv = NULL;
617618
}
618619

619-
spin_unlock(&alloc_free_lock);
620+
mutex_unlock(&alloc_free_lock);
620621

621622
UIO_DEBUG_RETURN(-1);
622623
}
@@ -970,7 +971,7 @@ BIN_ATTR_WRITE_CALLBACK( delete_buffer_write )
970971
{
971972
UIO_DEBUG_ENTER();
972973

973-
spin_lock(&alloc_free_lock);
974+
mutex_lock(&alloc_free_lock);
974975

975976
struct bin_attribute attrib;
976977
char tmp_string[UIO_PCI_DMA_BUFFER_NAME_SIZE];
@@ -994,7 +995,7 @@ BIN_ATTR_WRITE_CALLBACK( delete_buffer_write )
994995
else
995996
{ printk(DRIVER_NAME " : freeing of buffer %s failed!\n", tmp_string); }
996997

997-
spin_unlock(&alloc_free_lock);
998+
mutex_unlock(&alloc_free_lock);
998999

9991000
UIO_DEBUG_RETURN(count);
10001001
}

0 commit comments

Comments
 (0)