aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-10-30 16:19:59 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-10-30 16:19:59 +0100
commit2fc9cfc5a4cd5bc66aeca951c4f6b58f2b6671ef (patch)
tree975f566c8fc3501daa0f3ac6dc78b3a67c5f4ee4
parent0cc65720ad45463b0b57eda078ef2194a374531b (diff)
downloadusbutils-2fc9cfc5a4cd5bc66aeca951c4f6b58f2b6671ef.tar.gz
names: simplify get_vendor_product_with_fallback() a bit
Based on some review from Lonnie Abelbeck, if get_sysfs_name() failed in get_vendor_product_with_fallback(), the strings "[unknown]" would not be properly set for the product/vendor. Now the odds of that happening are very slim, but simplify this all by setting the strings first, and then, if we can find a real override, use that instead. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--names.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/names.c b/names.c
index 556020f..7bc0ae9 100644
--- a/names.c
+++ b/names.c
@@ -250,6 +250,10 @@ void get_vendor_product_with_fallback(char *vendor, int vendor_len,
libusb_get_device_descriptor(dev, &desc);
+ /* set to "[unknown]" by default unless something below finds a string */
+ strncpy(vendor, "[unknown]", vendor_len);
+ strncpy(product, "[unknown]", product_len);
+
have_vendor = !!get_vendor_string(vendor, vendor_len, desc.idVendor);
have_product = !!get_product_string(product, product_len,
desc.idVendor, desc.idProduct);
@@ -259,11 +263,9 @@ void get_vendor_product_with_fallback(char *vendor, int vendor_len,
if (get_sysfs_name(sysfs_name, sizeof(sysfs_name), dev) >= 0) {
if (!have_vendor)
- if (!read_sysfs_prop(vendor, vendor_len, sysfs_name, "manufacturer"))
- strncpy(vendor, "[unknown]", vendor_len);
+ read_sysfs_prop(vendor, vendor_len, sysfs_name, "manufacturer");
if (!have_product)
- if (!read_sysfs_prop(product, product_len, sysfs_name, "product"))
- strncpy(product, "[unknown]", product_len);
+ read_sysfs_prop(product, product_len, sysfs_name, "product");
}
}