linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/scsi/esas2r: Replace binary semaphore with mutex
@ 2019-11-01 20:51 Davidlohr Bueso
  0 siblings, 0 replies; only message in thread
From: Davidlohr Bueso @ 2019-11-01 20:51 UTC (permalink / raw)
  To: linuxdrivers, jejb, martin.petersen
  Cc: linux-kernel, linux-scsi, dave, Davidlohr Bueso

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 buffered_ioctl_sem, 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 <dbueso@suse.de>
---
This is in an effort to reduce semaphore users in the kernel.
Compile-tested only.

 drivers/scsi/esas2r/esas2r_ioctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
index 442c5e70a7b4..aad352fe27cf 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -56,7 +56,7 @@ dma_addr_t esas2r_buffered_ioctl_addr;
 u32 esas2r_buffered_ioctl_size;
 struct pci_dev *esas2r_buffered_ioctl_pcid;
 
-static DEFINE_SEMAPHORE(buffered_ioctl_semaphore);
+static DEFINE_MUTEX(buffered_ioctl_mutex);
 typedef int (*BUFFERED_IOCTL_CALLBACK)(struct esas2r_adapter *,
 				       struct esas2r_request *,
 				       struct esas2r_sg_context *,
@@ -209,7 +209,7 @@ static u8 handle_buffered_ioctl(struct esas2r_buffered_ioctl *bi)
 	struct esas2r_sg_context sgc;
 	u8 result = IOCTL_SUCCESS;
 
-	if (down_interruptible(&buffered_ioctl_semaphore))
+	if (mutex_lock_interruptible(&buffered_ioctl_mutex))
 		return IOCTL_OUT_OF_RESOURCES;
 
 	/* allocate a buffer or use the existing buffer. */
@@ -285,7 +285,7 @@ static u8 handle_buffered_ioctl(struct esas2r_buffered_ioctl *bi)
 	if (result == IOCTL_SUCCESS)
 		memcpy(bi->ioctl, esas2r_buffered_ioctl, bi->length);
 
-	up(&buffered_ioctl_semaphore);
+	mutex_unlock(&buffered_ioctl_mutex);
 	return result;
 }
 
-- 
2.16.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-01 20:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-01 20:51 [PATCH] drivers/scsi/esas2r: Replace binary semaphore with mutex Davidlohr Bueso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).