提交 9fe678fa 编写于 作者: C Clifton Barnes 提交者: Linus Torvalds

drivers/power/ds2780_battery.c: add a nolock function to w1 interface

Adds a nolock function to the w1 interface to avoid locking the
mutex if needed.
Signed-off-by: NClifton Barnes <cabarnes@indesign-llc.com>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Cc: <stable@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 853eee72
...@@ -26,20 +26,14 @@ ...@@ -26,20 +26,14 @@
#include "../w1_family.h" #include "../w1_family.h"
#include "w1_ds2780.h" #include "w1_ds2780.h"
int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, static int w1_ds2780_do_io(struct device *dev, char *buf, int addr,
int io) size_t count, int io)
{ {
struct w1_slave *sl = container_of(dev, struct w1_slave, dev); struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
if (!dev) if (addr > DS2780_DATA_SIZE || addr < 0)
return -ENODEV; return 0;
mutex_lock(&sl->master->mutex);
if (addr > DS2780_DATA_SIZE || addr < 0) {
count = 0;
goto out;
}
count = min_t(int, count, DS2780_DATA_SIZE - addr); count = min_t(int, count, DS2780_DATA_SIZE - addr);
if (w1_reset_select_slave(sl) == 0) { if (w1_reset_select_slave(sl) == 0) {
...@@ -47,7 +41,6 @@ int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, ...@@ -47,7 +41,6 @@ int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
w1_write_8(sl->master, W1_DS2780_WRITE_DATA); w1_write_8(sl->master, W1_DS2780_WRITE_DATA);
w1_write_8(sl->master, addr); w1_write_8(sl->master, addr);
w1_write_block(sl->master, buf, count); w1_write_block(sl->master, buf, count);
/* XXX w1_write_block returns void, not n_written */
} else { } else {
w1_write_8(sl->master, W1_DS2780_READ_DATA); w1_write_8(sl->master, W1_DS2780_READ_DATA);
w1_write_8(sl->master, addr); w1_write_8(sl->master, addr);
...@@ -55,13 +48,42 @@ int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, ...@@ -55,13 +48,42 @@ int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
} }
} }
out: return count;
}
int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
int io)
{
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
int ret;
if (!dev)
return -ENODEV;
mutex_lock(&sl->master->mutex);
ret = w1_ds2780_do_io(dev, buf, addr, count, io);
mutex_unlock(&sl->master->mutex); mutex_unlock(&sl->master->mutex);
return count; return ret;
} }
EXPORT_SYMBOL(w1_ds2780_io); EXPORT_SYMBOL(w1_ds2780_io);
int w1_ds2780_io_nolock(struct device *dev, char *buf, int addr, size_t count,
int io)
{
int ret;
if (!dev)
return -ENODEV;
ret = w1_ds2780_do_io(dev, buf, addr, count, io);
return ret;
}
EXPORT_SYMBOL(w1_ds2780_io_nolock);
int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd) int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd)
{ {
struct w1_slave *sl = container_of(dev, struct w1_slave, dev); struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
......
...@@ -124,6 +124,8 @@ ...@@ -124,6 +124,8 @@
extern int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, extern int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
int io); int io);
extern int w1_ds2780_io_nolock(struct device *dev, char *buf, int addr,
size_t count, int io);
extern int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd); extern int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd);
#endif /* !_W1_DS2780_H */ #endif /* !_W1_DS2780_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册