Linux Watchdog driver development
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: wim@linux-watchdog.org, linux@roeck-us.net,
	linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Oliver Neukum <oneukum@suse.com>
Subject: [PATCH 3/8] pcwd_usb: usb_pcwd_open handle and return errors
Date: Thu, 27 Apr 2023 15:33:45 +0200	[thread overview]
Message-ID: <20230427133350.31064-4-oneukum@suse.com> (raw)
In-Reply-To: <20230427133350.31064-1-oneukum@suse.com>

Operations on the bus can suffer an IO error.
Handle it undoing partial operations and return
it to user space

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/watchdog/pcwd_usb.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c
index d5d68a529620..ed3be8926a15 100644
--- a/drivers/watchdog/pcwd_usb.c
+++ b/drivers/watchdog/pcwd_usb.c
@@ -273,7 +273,7 @@ static int usb_pcwd_start(struct usb_pcwd_private *usb_pcwd)
 
 	if ((retval == 0) || (lsb == 0)) {
 		pr_err("Card did not acknowledge enable attempt\n");
-		return -1;
+		return -EIO;
 	}
 
 	return 0;
@@ -484,10 +484,22 @@ static int usb_pcwd_open(struct inode *inode, struct file *file)
 		goto error;
 
 	/* Activate */
-	usb_pcwd_start(usb_pcwd_device);
-	usb_pcwd_keepalive(usb_pcwd_device);
+	retval = usb_pcwd_start(usb_pcwd_device);
+	if (retval < 0)
+		goto err_bail;
+	retval = usb_pcwd_keepalive(usb_pcwd_device);
+	if (retval < 0)
+		goto err_bail_and_stop;
 	retval = stream_open(inode, file);
+	if (retval < 0)
+		goto err_bail_and_stop;
+	mutex_unlock(&disconnect_mutex);
+	return retval;
 
+err_bail_and_stop:
+	usb_pcwd_stop(usb_pcwd_device);
+err_bail:
+	clear_bit(0, &is_active);
 error:
 	mutex_unlock(&disconnect_mutex);
 	return retval;
-- 
2.40.0


  parent reply	other threads:[~2023-04-27 13:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230427133350.31064-1-oneukum@suse.com>
2023-04-27 13:33 ` [PATCH 1/8] pwcd_usb: fix error handling in probe Oliver Neukum
2023-04-27 13:33 ` [PATCH 2/8] pcwd_usb: stop open race disconnect Oliver Neukum
2023-04-27 13:33 ` Oliver Neukum [this message]
2023-04-27 13:33 ` [PATCH 4/8] pcwd_usb: do not leave a freed URB active Oliver Neukum
2023-04-27 13:33 ` [PATCH 5/8] pcwd_usb: usb_pcwd_ioctl: return IO errors Oliver Neukum
2023-04-27 13:33 ` [PATCH 6/8] pcwd_usb: memory ordering of interrupt and waiter Oliver Neukum
2023-04-27 13:33 ` [PATCH 7/8] usb_pcwd: WDIOC_SETTIMEOUT: prevent preemption Oliver Neukum
2023-04-27 13:33 ` [PATCH 8/8] usb_pcwd: remove superfluous usb_device pointer Oliver Neukum
2023-05-13  8:52   ` Dan Carpenter
2023-04-27 14:12 ` watchdog: pcwd driver updates (was: No subject) Guenter Roeck
2023-04-27 14:19   ` Oliver Neukum
2023-04-27 14:35     ` Guenter Roeck

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=20230427133350.31064-4-oneukum@suse.com \
    --to=oneukum@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wim@linux-watchdog.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox