From: Giedrius Statkevicius <giedrius.statkevicius@gmail.com>
To: lidza.louina@gmail.com, markh@compro.net
Cc: gregkh@linuxfoundation.org,
driverdev-devel@linuxdriverproject.org,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
"Giedrius Statkevičius" <giedrius.statkevicius@gmail.com>
Subject: [PATCH 1/3] staging: dgnc: use a real mutex instead of masquerading a semaphore as a mutex
Date: Mon, 6 Apr 2015 00:15:53 +0300 [thread overview]
Message-ID: <1428268555-8963-1-git-send-email-giedrius.statkevicius@gmail.com> (raw)
A mutex should be used here (and it's name even says that) so remove the hiding
of a semaphore behind a #define and use a real mutex that the kernel provides.
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@gmail.com>
---
drivers/staging/dgnc/dgnc_tty.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index ce4187f..0b9bed4 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -42,16 +42,12 @@
#include "dgnc_sysfs.h"
#include "dgnc_utils.h"
-#define init_MUTEX(sem) sema_init(sem, 1)
-#define DECLARE_MUTEX(name) \
- struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
-
/*
* internal variables
*/
static struct dgnc_board *dgnc_BoardsByMajor[256];
static unsigned char *dgnc_TmpWriteBuf;
-static DECLARE_MUTEX(dgnc_TmpWriteSem);
+static DEFINE_MUTEX(dgnc_TmpWriteSem);
/*
* Default transparent print information.
@@ -1797,7 +1793,7 @@ static int dgnc_tty_write(struct tty_struct *tty,
* the board.
*/
/* we're allowed to block if it's from_user */
- if (down_interruptible(&dgnc_TmpWriteSem))
+ if (mutex_lock_interruptible(&dgnc_TmpWriteSem))
return -EINTR;
/*
@@ -1807,7 +1803,7 @@ static int dgnc_tty_write(struct tty_struct *tty,
count -= copy_from_user(dgnc_TmpWriteBuf, (const unsigned char __user *) buf, count);
if (!count) {
- up(&dgnc_TmpWriteSem);
+ mutex_unlock(&dgnc_TmpWriteSem);
return -EFAULT;
}
@@ -1855,7 +1851,7 @@ static int dgnc_tty_write(struct tty_struct *tty,
if (from_user) {
spin_unlock_irqrestore(&ch->ch_lock, flags);
- up(&dgnc_TmpWriteSem);
+ mutex_unlock(&dgnc_TmpWriteSem);
} else {
spin_unlock_irqrestore(&ch->ch_lock, flags);
}
--
2.3.5
next reply other threads:[~2015-04-05 21:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-05 21:15 Giedrius Statkevicius [this message]
2015-04-05 21:15 ` [PATCH 2/3] staging: dgnc: remove redundant check Giedrius Statkevicius
2015-04-05 21:15 ` [PATCH 3/3] staging: dgnc: improve the coding style in unlocking part of dgnc_tty_write() Giedrius Statkevicius
2015-04-07 8:17 ` Dan Carpenter
2015-04-07 8:19 ` Dan Carpenter
2015-04-07 8:25 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428268555-8963-1-git-send-email-giedrius.statkevicius@gmail.com \
--to=giedrius.statkevicius@gmail.com \
--cc=devel@driverdev.osuosl.org \
--cc=driverdev-devel@linuxdriverproject.org \
--cc=gregkh@linuxfoundation.org \
--cc=lidza.louina@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markh@compro.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox