[PATCH] linux: Don't spam the console with "device unconfigured" errors

Hans de Goede hdegoede at redhat.com
Sat Mar 31 13:25:32 EDT 2012


A device being unconfigured is actually a semi-normal condition, this happens
for example when you select "safely remove" device in most linux file-managers.

Unfortunately in the case of a libusb_get_configuration() call there is no
way for the app to tell if a returned config of 0 means:
1) quirky device which actually has a config 0 and is running with that config
2) unconfigured device

Unlike for example libusb_get_active_config_descriptor() which correctly
returns LIBUSB_ERROR_NOT_FOUND in case 2. Something which we cannot fix
as that would break our API compatibility.

Therefor instead of just silencing the error, this patch moves it to
op_get_configuration() so that callers of libusb_get_configuration() will
still get a hint in their logs when they hit an unconfigured device.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 libusb/os/linux_usbfs.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 780f0bd..8713a09 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -504,7 +504,7 @@ static int sysfs_get_active_config(struct libusb_device *dev, int *config)
 			"read bConfigurationValue failed ret=%d errno=%d", r, errno);
 		return LIBUSB_ERROR_IO;
 	} else if (r == 0) {
-		usbi_err(DEVICE_CTX(dev), "device unconfigured");
+		usbi_dbg("device unconfigured");
 		*config = -1;
 		return 0;
 	}
@@ -1199,8 +1199,10 @@ static int op_get_configuration(struct libusb_device_handle *handle,
 	if (r < 0)
 		return r;
 
-	if (*config == -1)
+	if (*config == -1) {
+		usbi_err(HANDLE_CTX(handle), "device unconfigured");
 		*config = 0;
+	}
 
 	return 0;
 }
-- 
1.7.9.3




More information about the libusbx mailing list