udev-builtin-usb_id: use strjoina to simplify code
This commit is contained in:
@@ -138,13 +138,12 @@ static void set_scsi_type(char *to, const char *from, size_t len) {
|
||||
#define USB_DT_INTERFACE 0x04
|
||||
|
||||
static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
|
||||
_cleanup_free_ char *filename = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
ssize_t size;
|
||||
unsigned char buf[18 + 65535];
|
||||
size_t pos = 0;
|
||||
unsigned strpos = 0;
|
||||
const char *syspath;
|
||||
const char *filename, *syspath;
|
||||
int r;
|
||||
struct usb_interface_descriptor {
|
||||
uint8_t bLength;
|
||||
@@ -161,12 +160,11 @@ static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
|
||||
r = sd_device_get_syspath(dev, &syspath);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (asprintf(&filename, "%s/descriptors", syspath) < 0)
|
||||
return log_oom();
|
||||
|
||||
filename = strjoina(syspath, "/descriptors");
|
||||
fd = open(filename, O_RDONLY|O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return log_device_debug_errno(dev, errno, "Failed to open USB device 'descriptors' file: %m");
|
||||
return log_device_debug_errno(dev, errno, "Failed to open \"%s\": %m", filename);
|
||||
|
||||
size = read(fd, buf, sizeof(buf));
|
||||
if (size < 18 || (size_t) size >= sizeof(buf))
|
||||
|
||||
Reference in New Issue
Block a user