Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4628833yba; Mon, 20 May 2019 00:29:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwu5Qg+WDWIbeXQIf4ojZwyC+87h2/5Ndus2yXf+LLzZnCi/7ps9MlkBVB+XgFCNkr283n9 X-Received: by 2002:a63:a1a:: with SMTP id 26mr72988291pgk.11.1558337342663; Mon, 20 May 2019 00:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558337342; cv=none; d=google.com; s=arc-20160816; b=fOUa/eEAgWeJt4rqTUqufQs/S+1K9Xs2qaqHj+Khkm/5WsBDsuk1st1fBimT/W2qPp vOvm1FOi9/Gra/SRIw9vEDlmoyNZFQbX9mxyi7O+SuuPvFT2HPeFpc3EjOdJAkwZA2qz X8zT1TMe9LTCXvgzZ1MCyna3LMf4+bGAjOA2QnlRTpIMmQX1d+/+PgDtNZsAIGBA/38s ExrAWXAs+Nu+gUqGXmhTLu08oLwqr4QzUik/jUNaA2uEtziI4ai+UdLQQ0oAox7sQiTL gupcw0Yal76NKJa+4eLes8izgdiTbTDvERLazjlQXNOHmpZNJXUliKYPM+AlLSJ5nPxR 9DoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:message-id:date:cc:to:from; bh=BIEs/9ap/wkkGD+AmU7ViLf4UemuQ8YziPwwMUnsdok=; b=kANjuzugFJE+M/WJW7M9Ctfz2cgOp+iHerDlO5h/LBqV/csmDcMzRzMZ7aQIVdz8pf BqNiKHRgeem0FAXaX/qCxV6jO+1DNsdZ9Dt4V3MPjMg7oztM7HPdshcWs8Qh2b1I4UbC VlvdkdFZ/4KlxXOkDQ+TgSBvffp3Vdzvht5invmNQGcMoU54J+yt+2qcTQcTefLkLwWT XpxKHs+xZtpd/kiumqgf/88UN1tH87zqgiHonk4u802Ho2Vv1KLBQKrDXWp5Bvke5RUc cTtp2IRFoMua8AHtiaEVZtxEfysZnyhKnXz3K+2erM45jTQFDFNqvB3xJdIhn+4Q05cz sr2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=REJECT dis=NONE) header.from=skyboo.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 192si16369905pgb.488.2019.05.20.00.28.47; Mon, 20 May 2019 00:29:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=REJECT dis=NONE) header.from=skyboo.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730422AbfETHGL (ORCPT + 99 others); Mon, 20 May 2019 03:06:11 -0400 Received: from skyboo.net ([94.40.87.198]:51452 "EHLO skyboo.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbfETHGK (ORCPT ); Mon, 20 May 2019 03:06:10 -0400 Received: from manio by skyboo.net with local (Exim 4.91) (envelope-from ) id 1hScN5-0005o5-F5; Mon, 20 May 2019 09:06:07 +0200 From: Mariusz Bialonczyk To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Cc: Mariusz Bialonczyk Date: Mon, 20 May 2019 09:05:55 +0200 Message-Id: <20190520070558.20142-1-manio@skyboo.net> X-Mailer: git-send-email 2.19.0.rc1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, greg@kroah.com, manio@skyboo.net X-SA-Exim-Mail-From: manio@skyboo.net X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nemesis.skyboo.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_RELAYS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.1 Subject: [PATCH 1/4] w1: ds2413: output_write() cosmetic fixes / simplify X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on skyboo.net) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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