Skip to content

Commit 8aea7f8

Browse files
Davidlohr BuesoSasha Levin
authored andcommitted
drivers/hv: Replace binary semaphore with mutex
At a slight footprint cost (24 vs 32 bytes), mutexes are more optimal than semaphores; it's also a nicer interface for mutual exclusion, which is why they are encouraged over binary semaphores, when possible. Replace the hyperv_mmio_lock, its semantics implies traditional lock ownership; that is, the lock owner is the same for both lock/unlock operations. Therefore it is safe to convert. Signed-off-by: Davidlohr Bueso <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent d7f0b2e commit 8aea7f8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static struct notifier_block hyperv_panic_block = {
7979
static const char *fb_mmio_name = "fb_range";
8080
static struct resource *fb_mmio;
8181
static struct resource *hyperv_mmio;
82-
static DEFINE_SEMAPHORE(hyperv_mmio_lock);
82+
static DEFINE_MUTEX(hyperv_mmio_lock);
8383

8484
static int vmbus_exists(void)
8585
{
@@ -2018,7 +2018,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
20182018
int retval;
20192019

20202020
retval = -ENXIO;
2021-
down(&hyperv_mmio_lock);
2021+
mutex_lock(&hyperv_mmio_lock);
20222022

20232023
/*
20242024
* If overlaps with frame buffers are allowed, then first attempt to
@@ -2065,7 +2065,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
20652065
}
20662066

20672067
exit:
2068-
up(&hyperv_mmio_lock);
2068+
mutex_unlock(&hyperv_mmio_lock);
20692069
return retval;
20702070
}
20712071
EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
@@ -2082,15 +2082,15 @@ void vmbus_free_mmio(resource_size_t start, resource_size_t size)
20822082
{
20832083
struct resource *iter;
20842084

2085-
down(&hyperv_mmio_lock);
2085+
mutex_lock(&hyperv_mmio_lock);
20862086
for (iter = hyperv_mmio; iter; iter = iter->sibling) {
20872087
if ((iter->start >= start + size) || (iter->end <= start))
20882088
continue;
20892089

20902090
__release_region(iter, start, size);
20912091
}
20922092
release_mem_region(start, size);
2093-
up(&hyperv_mmio_lock);
2093+
mutex_unlock(&hyperv_mmio_lock);
20942094

20952095
}
20962096
EXPORT_SYMBOL_GPL(vmbus_free_mmio);

0 commit comments

Comments
 (0)