LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Mariusz Bialonczyk <manio@skyboo.net>
To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman <greg@kroah.com>
Cc: Mariusz Bialonczyk <manio@skyboo.net>
Subject: [PATCH 1/4] w1: ds2413: output_write() cosmetic fixes / simplify
Date: Mon, 20 May 2019 09:05:55 +0200	[thread overview]
Message-ID: <20190520070558.20142-1-manio@skyboo.net> (raw)

Make the output_write simpler.
Based on Jean-Francois Dagenais code from:
49695ac46861 ("w1: ds2408: reset on output_write retry with readback")

Signed-off-by: Mariusz Bialonczyk <manio@skyboo.net>
---
 drivers/w1/slaves/w1_ds2413.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/w1/slaves/w1_ds2413.c b/drivers/w1/slaves/w1_ds2413.c
index 492e3d010321..cd3763df69ac 100644
--- a/drivers/w1/slaves/w1_ds2413.c
+++ b/drivers/w1/slaves/w1_ds2413.c
@@ -69,6 +69,7 @@ static ssize_t output_write(struct file *filp, struct kobject *kobj,
 	struct w1_slave *sl = kobj_to_w1_slave(kobj);
 	u8 w1_buf[3];
 	unsigned int retries = W1_F3A_RETRIES;
+	ssize_t bytes_written = -EIO;
 
 	if (count != 1 || off != 0)
 		return -EFAULT;
@@ -78,7 +79,7 @@ static ssize_t output_write(struct file *filp, struct kobject *kobj,
 	dev_dbg(&sl->dev, "mutex locked");
 
 	if (w1_reset_select_slave(sl))
-		goto error;
+		goto out;
 
 	/* according to the DS2413 datasheet the most significant 6 bits
 	   should be set to "1"s, so do it now */
@@ -91,18 +92,20 @@ static ssize_t output_write(struct file *filp, struct kobject *kobj,
 		w1_write_block(sl->master, w1_buf, 3);
 
 		if (w1_read_8(sl->master) == W1_F3A_SUCCESS_CONFIRM_BYTE) {
-			mutex_unlock(&sl->master->bus_mutex);
-			dev_dbg(&sl->dev, "mutex unlocked, retries:%d", retries);
-			return 1;
+			bytes_written = 1;
+			goto out;
 		}
 		if (w1_reset_resume_command(sl->master))
-			goto error;
+			goto out; /* unrecoverable error */
+
+		dev_warn(&sl->dev, "PIO_ACCESS_WRITE error, retries left: %d\n", retries);
 	}
 
-error:
+out:
 	mutex_unlock(&sl->master->bus_mutex);
-	dev_dbg(&sl->dev, "mutex unlocked in error, retries:%d", retries);
-	return -EIO;
+	dev_dbg(&sl->dev, "%s, mutex unlocked, retries: %d\n",
+		(bytes_written > 0) ? "succeeded" : "error", retries);
+	return bytes_written;
 }
 
 static BIN_ATTR(output, S_IRUGO | S_IWUSR | S_IWGRP, NULL, output_write, 1);
-- 
2.19.0.rc1


             reply	other threads:[~2019-05-20  7:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20  7:05 Mariusz Bialonczyk [this message]
2019-05-20  7:05 ` [PATCH 2/4] w1: ds2413: add retry support to state_read() Mariusz Bialonczyk
2019-05-20  7:05 ` [PATCH 3/4] w1: ds2413: when the slave is not responding during read, select it again Mariusz Bialonczyk
2019-05-22 10:40   ` [PATCH 3/4 v2] " Mariusz Bialonczyk
2019-05-20  7:05 ` [PATCH 4/4] w1: ds2805: rename w1_family struct, fixing c-p typo Mariusz Bialonczyk
2019-05-24 18:21   ` Greg KH
2019-05-25  8:45     ` [PATCH 4/4 v2] " Mariusz Bialonczyk
2019-05-25  8:51     ` [PATCH 4/4] " Mariusz Bialonczyk

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=20190520070558.20142-1-manio@skyboo.net \
    --to=manio@skyboo.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH 1/4] w1: ds2413: output_write() cosmetic fixes / simplify' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).