From: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
To: kernel-janitors@vger.kernel.org
Subject: [KJ] [PATCH] converted binary semaphore to mutex in SBS ACPI
Date: Tue, 17 Apr 2007 20:55:08 +0000 [thread overview]
Message-ID: <20070417205508.GA6474@traven> (raw)
according to http://lwn.net/Articles/167034/ binary semaphore (which
aren't given in interrupt context or locked/unlocked in different
process contexts) should be converted to the new mutex API.
here is a patch that converts the semaphore used by the Smart Battery
System ACPI interface driver to a mutex.
please let me know your comments if i misinterpreted the article or if
you see something wrong in the patch
--
convert binary semaphore in Smart Battery System ACPI driver to the
new mutex API
Signed-off-by: Matthias Kaehlcke <matthias.kaehlcke@gmail.com>
---
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 59640d9..7e90132 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -32,6 +32,7 @@
#include <linux/acpi.h>
#include <linux/i2c.h>
#include <linux/delay.h>
+#include <linux/mutex.h>
#include "i2c_ec.h"
@@ -83,7 +84,7 @@ MODULE_AUTHOR("Rich Townsend");
MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
MODULE_LICENSE("GPL");
-static struct semaphore sbs_sem;
+static DEFINE_MUTEX(sbs_mutex);
#define UPDATE_MODE QUEUE_UPDATE_MODE
/* REQUEST_UPDATE_MODE QUEUE_UPDATE_MODE */
@@ -930,7 +931,7 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
return -ENODEV;
}
- down(&sbs_sem);
+ mutex_lock(&sbs_mutex);
if (update_mode = REQUEST_UPDATE_MODE) {
result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_INFO);
@@ -984,7 +985,7 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
end:
- up(&sbs_sem);
+ mutex_unlock(&sbs_mutex);
return result;
}
@@ -1005,7 +1006,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
return -ENODEV;
}
- down(&sbs_sem);
+ mutex_lock(&sbs_mutex);
if (update_mode = REQUEST_UPDATE_MODE) {
result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_STATE);
@@ -1061,7 +1062,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
end:
- up(&sbs_sem);
+ mutex_unlock(&sbs_mutex);
return result;
}
@@ -1081,7 +1082,7 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
return -ENODEV;
}
- down(&sbs_sem);
+ mutex_lock(&sbs_mutex);
if (update_mode = REQUEST_UPDATE_MODE) {
result = acpi_sbs_update_run(battery->sbs, DATA_TYPE_ALARM);
@@ -1113,7 +1114,7 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
end:
- up(&sbs_sem);
+ mutex_unlock(&sbs_mutex);
return result;
}
@@ -1131,7 +1132,7 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer,
return -ENODEV;
}
- down(&sbs_sem);
+ mutex_lock(&sbs_mutex);
if (!acpi_battery_is_present(battery)) {
result = -ENODEV;
@@ -1169,7 +1170,7 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer,
}
end:
- up(&sbs_sem);
+ mutex_unlock(&sbs_mutex);
if (result) {
return result;
@@ -1221,7 +1222,7 @@ static int acpi_ac_read_state(struct seq_file *seq, void *offset)
return -ENODEV;
}
- down(&sbs_sem);
+ mutex_lock(&sbs_mutex);
if (update_mode = REQUEST_UPDATE_MODE) {
result = acpi_sbs_update_run(sbs, DATA_TYPE_AC_STATE);
@@ -1234,7 +1235,7 @@ static int acpi_ac_read_state(struct seq_file *seq, void *offset)
seq_printf(seq, "state: %s\n",
sbs->ac_present ? "on-line" : "off-line");
- up(&sbs_sem);
+ mutex_unlock(&sbs_mutex);
return 0;
}
@@ -1719,8 +1720,6 @@ static int __init acpi_sbs_init(void)
if (acpi_disabled)
return -ENODEV;
- init_MUTEX(&sbs_sem);
-
if (capacity_mode != DEF_CAPACITY_UNIT
&& capacity_mode != MAH_CAPACITY_UNIT
&& capacity_mode != MWH_CAPACITY_UNIT) {
--
Matthias Kaehlcke
Linux Application Developer
Barcelona
C treats you like a consenting adult. Pascal treats you like a
naughty child. Ada treats you like a criminal
(Bruce Powel Douglass)
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors
reply other threads:[~2007-04-17 20:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20070417205508.GA6474@traven \
--to=matthias.kaehlcke@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.