Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Clifton Barnes <cabarnes@indesign-llc.com>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Cc: <stable@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Clifton Barnes and committed by
Linus Torvalds
9fe678fa 853eee72

+38 -14
+36 -14
drivers/w1/slaves/w1_ds2780.c
··· 26 26 #include "../w1_family.h" 27 27 #include "w1_ds2780.h" 28 28 29 - int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, 30 - int io) 29 + static int w1_ds2780_do_io(struct device *dev, char *buf, int addr, 30 + size_t count, int io) 31 31 { 32 32 struct w1_slave *sl = container_of(dev, struct w1_slave, dev); 33 33 34 - if (!dev) 35 - return -ENODEV; 34 + if (addr > DS2780_DATA_SIZE || addr < 0) 35 + return 0; 36 36 37 - mutex_lock(&sl->master->mutex); 38 - 39 - if (addr > DS2780_DATA_SIZE || addr < 0) { 40 - count = 0; 41 - goto out; 42 - } 43 37 count = min_t(int, count, DS2780_DATA_SIZE - addr); 44 38 45 39 if (w1_reset_select_slave(sl) == 0) { ··· 41 47 w1_write_8(sl->master, W1_DS2780_WRITE_DATA); 42 48 w1_write_8(sl->master, addr); 43 49 w1_write_block(sl->master, buf, count); 44 - /* XXX w1_write_block returns void, not n_written */ 45 50 } else { 46 51 w1_write_8(sl->master, W1_DS2780_READ_DATA); 47 52 w1_write_8(sl->master, addr); ··· 48 55 } 49 56 } 50 57 51 - out: 52 - mutex_unlock(&sl->master->mutex); 53 - 54 58 return count; 55 59 } 60 + 61 + int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, 62 + int io) 63 + { 64 + struct w1_slave *sl = container_of(dev, struct w1_slave, dev); 65 + int ret; 66 + 67 + if (!dev) 68 + return -ENODEV; 69 + 70 + mutex_lock(&sl->master->mutex); 71 + 72 + ret = w1_ds2780_do_io(dev, buf, addr, count, io); 73 + 74 + mutex_unlock(&sl->master->mutex); 75 + 76 + return ret; 77 + } 56 78 EXPORT_SYMBOL(w1_ds2780_io); 79 + 80 + int w1_ds2780_io_nolock(struct device *dev, char *buf, int addr, size_t count, 81 + int io) 82 + { 83 + int ret; 84 + 85 + if (!dev) 86 + return -ENODEV; 87 + 88 + ret = w1_ds2780_do_io(dev, buf, addr, count, io); 89 + 90 + return ret; 91 + } 92 + EXPORT_SYMBOL(w1_ds2780_io_nolock); 57 93 58 94 int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd) 59 95 {
+2
drivers/w1/slaves/w1_ds2780.h
··· 124 124 125 125 extern int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, 126 126 int io); 127 + extern int w1_ds2780_io_nolock(struct device *dev, char *buf, int addr, 128 + size_t count, int io); 127 129 extern int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd); 128 130 129 131 #endif /* !_W1_DS2780_H */