All of lore.kernel.org
 help / color / mirror / Atom feed
From: GwanYeong Kim <gy741.kim@gmail.com>
To: valentina.manea.m@gmail.com
Cc: shuah@kernel.org, gregkh@linuxfoundation.org,
	allison@lohutok.net, opensource@jilayne.com,
	changcheng.liu@intel.com, tglx@linutronix.de,
	linux-usb@vger.kernel.org, GwanYeong Kim <gy741.kim@gmail.com>
Subject: [PATCH v3] usbip: tools: Fix read_usb_vudc_device() error path handling
Date: Fri, 18 Oct 2019 03:22:23 +0000	[thread overview]
Message-ID: <20191018032223.4644-1-gy741.kim@gmail.com> (raw)
In-Reply-To: <948530c4-0f42-1244-faee-aad531074bf3@kernel.org>

This isn't really accurate right. fread() doesn't always
return 0 in error. It could return < number of elements
and set errno.

Signed-off-by: GwanYeong Kim <gy741.kim@gmail.com>
---
 tools/usb/usbip/libsrc/usbip_device_driver.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
index 051d7d3f443b..927a151fa9aa 100644
--- a/tools/usb/usbip/libsrc/usbip_device_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
@@ -69,7 +69,7 @@ int read_usb_vudc_device(struct udev_device *sdev, struct usbip_usb_device *dev)
 	FILE *fd = NULL;
 	struct udev_device *plat;
 	const char *speed;
-	int ret = 0;
+	size_t ret;
 
 	plat = udev_device_get_parent(sdev);
 	path = udev_device_get_syspath(plat);
@@ -79,8 +79,10 @@ int read_usb_vudc_device(struct udev_device *sdev, struct usbip_usb_device *dev)
 	if (!fd)
 		return -1;
 	ret = fread((char *) &descr, sizeof(descr), 1, fd);
-	if (ret < 0)
+	if (ret != 1) {
+		err("Cannot read vudc device descr file: %s", strerror(errno));
 		goto err;
+	}
 	fclose(fd);
 
 	copy_descr_attr(dev, &descr, bDeviceClass);
-- 
2.17.1


  reply	other threads:[~2019-10-18  5:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-15 13:14 [PATCH] usbip: tools: Fix read_usb_vudc_device() error path handling GwanYeong Kim
2019-10-15 23:14 ` shuah
2019-10-16  4:38   ` GwanYeong Kim
2019-10-16 13:18     ` Greg KH
2019-10-17  2:25       ` [PATCH v2] " GwanYeong Kim
2019-10-17  2:33         ` shuah
2019-10-17  5:26           ` GwanYeong Kim
2019-10-17 13:00             ` shuah
2019-10-18  3:22               ` GwanYeong Kim [this message]
2019-10-21 18:59                 ` [PATCH v3] " shuah

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=20191018032223.4644-1-gy741.kim@gmail.com \
    --to=gy741.kim@gmail.com \
    --cc=allison@lohutok.net \
    --cc=changcheng.liu@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=opensource@jilayne.com \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=valentina.manea.m@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.