ath79: add support for COMFAST CF-E130N v2
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-4.19 / 950-0588-w1-ds2413-output_write-cosmetic-fixes-simplify.patch
1 From 3280ce5f5483a351f49e84b48ad98df87989346a Mon Sep 17 00:00:00 2001
2 From: Mariusz Bialonczyk <manio@skyboo.net>
3 Date: Mon, 20 May 2019 09:05:55 +0200
4 Subject: [PATCH] w1: ds2413: output_write() cosmetic fixes / simplify
5
6 commit ae2ee27aa985232f66421d7cd1c7f4b87c7dba7d upstream.
7
8 Make the output_write simpler.
9 Based on Jean-Francois Dagenais code from:
10 49695ac46861 ("w1: ds2408: reset on output_write retry with readback")
11
12 Signed-off-by: Mariusz Bialonczyk <manio@skyboo.net>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14 ---
15 drivers/w1/slaves/w1_ds2413.c | 19 +++++++++++--------
16 1 file changed, 11 insertions(+), 8 deletions(-)
17
18 --- a/drivers/w1/slaves/w1_ds2413.c
19 +++ b/drivers/w1/slaves/w1_ds2413.c
20 @@ -69,6 +69,7 @@ static ssize_t output_write(struct file
21 struct w1_slave *sl = kobj_to_w1_slave(kobj);
22 u8 w1_buf[3];
23 unsigned int retries = W1_F3A_RETRIES;
24 + ssize_t bytes_written = -EIO;
25
26 if (count != 1 || off != 0)
27 return -EFAULT;
28 @@ -78,7 +79,7 @@ static ssize_t output_write(struct file
29 dev_dbg(&sl->dev, "mutex locked");
30
31 if (w1_reset_select_slave(sl))
32 - goto error;
33 + goto out;
34
35 /* according to the DS2413 datasheet the most significant 6 bits
36 should be set to "1"s, so do it now */
37 @@ -91,18 +92,20 @@ static ssize_t output_write(struct file
38 w1_write_block(sl->master, w1_buf, 3);
39
40 if (w1_read_8(sl->master) == W1_F3A_SUCCESS_CONFIRM_BYTE) {
41 - mutex_unlock(&sl->master->bus_mutex);
42 - dev_dbg(&sl->dev, "mutex unlocked, retries:%d", retries);
43 - return 1;
44 + bytes_written = 1;
45 + goto out;
46 }
47 if (w1_reset_resume_command(sl->master))
48 - goto error;
49 + goto out; /* unrecoverable error */
50 +
51 + dev_warn(&sl->dev, "PIO_ACCESS_WRITE error, retries left: %d\n", retries);
52 }
53
54 -error:
55 +out:
56 mutex_unlock(&sl->master->bus_mutex);
57 - dev_dbg(&sl->dev, "mutex unlocked in error, retries:%d", retries);
58 - return -EIO;
59 + dev_dbg(&sl->dev, "%s, mutex unlocked, retries: %d\n",
60 + (bytes_written > 0) ? "succeeded" : "error", retries);
61 + return bytes_written;
62 }
63
64 static BIN_ATTR(output, S_IRUGO | S_IWUSR | S_IWGRP, NULL, output_write, 1);