Commit 8aea7f82 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Sasha Levin

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: default avatarDavidlohr Bueso <dbueso@suse.de>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent d7f0b2e4
...@@ -79,7 +79,7 @@ static struct notifier_block hyperv_panic_block = { ...@@ -79,7 +79,7 @@ static struct notifier_block hyperv_panic_block = {
static const char *fb_mmio_name = "fb_range"; static const char *fb_mmio_name = "fb_range";
static struct resource *fb_mmio; static struct resource *fb_mmio;
static struct resource *hyperv_mmio; static struct resource *hyperv_mmio;
static DEFINE_SEMAPHORE(hyperv_mmio_lock); static DEFINE_MUTEX(hyperv_mmio_lock);
static int vmbus_exists(void) static int vmbus_exists(void)
{ {
...@@ -2018,7 +2018,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, ...@@ -2018,7 +2018,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
int retval; int retval;
retval = -ENXIO; retval = -ENXIO;
down(&hyperv_mmio_lock); mutex_lock(&hyperv_mmio_lock);
/* /*
* If overlaps with frame buffers are allowed, then first attempt to * 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, ...@@ -2065,7 +2065,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
} }
exit: exit:
up(&hyperv_mmio_lock); mutex_unlock(&hyperv_mmio_lock);
return retval; return retval;
} }
EXPORT_SYMBOL_GPL(vmbus_allocate_mmio); EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
...@@ -2082,7 +2082,7 @@ void vmbus_free_mmio(resource_size_t start, resource_size_t size) ...@@ -2082,7 +2082,7 @@ void vmbus_free_mmio(resource_size_t start, resource_size_t size)
{ {
struct resource *iter; struct resource *iter;
down(&hyperv_mmio_lock); mutex_lock(&hyperv_mmio_lock);
for (iter = hyperv_mmio; iter; iter = iter->sibling) { for (iter = hyperv_mmio; iter; iter = iter->sibling) {
if ((iter->start >= start + size) || (iter->end <= start)) if ((iter->start >= start + size) || (iter->end <= start))
continue; continue;
...@@ -2090,7 +2090,7 @@ void vmbus_free_mmio(resource_size_t start, resource_size_t size) ...@@ -2090,7 +2090,7 @@ void vmbus_free_mmio(resource_size_t start, resource_size_t size)
__release_region(iter, start, size); __release_region(iter, start, size);
} }
release_mem_region(start, size); release_mem_region(start, size);
up(&hyperv_mmio_lock); mutex_unlock(&hyperv_mmio_lock);
} }
EXPORT_SYMBOL_GPL(vmbus_free_mmio); EXPORT_SYMBOL_GPL(vmbus_free_mmio);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment