~ubuntu-branches/ubuntu/trusty/systemd/trusty

« back to all changes in this revision

Viewing changes to src/udev/udev-builtin-usb_id.c

Tags: upstream-202
ImportĀ upstreamĀ versionĀ 202

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
 
152
152
static int dev_if_packed_info(struct udev_device *dev, char *ifs_str, size_t len)
153
153
{
154
 
        char *filename = NULL;
155
 
        int fd;
 
154
        _cleanup_free_ char *filename = NULL;
 
155
        _cleanup_close_ int fd = -1;
156
156
        ssize_t size;
157
157
        unsigned char buf[18 + 65535];
158
 
        unsigned int pos, strpos;
 
158
        int pos = 0;
 
159
        unsigned strpos = 0;
159
160
        struct usb_interface_descriptor {
160
161
                u_int8_t        bLength;
161
162
                u_int8_t        bDescriptorType;
167
168
                u_int8_t        bInterfaceProtocol;
168
169
                u_int8_t        iInterface;
169
170
        } __attribute__((packed));
170
 
        int err = 0;
171
 
 
172
 
        if (asprintf(&filename, "%s/descriptors", udev_device_get_syspath(dev)) < 0) {
173
 
                err = -1;
174
 
                goto out;
175
 
        }
 
171
 
 
172
        if (asprintf(&filename, "%s/descriptors", udev_device_get_syspath(dev)) < 0)
 
173
                return log_oom();
 
174
 
176
175
        fd = open(filename, O_RDONLY|O_CLOEXEC);
177
176
        if (fd < 0) {
178
177
                fprintf(stderr, "error opening USB device 'descriptors' file\n");
179
 
                err = -1;
180
 
                goto out;
 
178
                return -errno;
181
179
        }
 
180
 
182
181
        size = read(fd, buf, sizeof(buf));
183
 
        close(fd);
184
 
        if (size < 18 || size == sizeof(buf)) {
185
 
                err = -1;
186
 
                goto out;
187
 
        }
 
182
        if (size < 18 || size == sizeof(buf))
 
183
                return -EIO;
188
184
 
189
 
        pos = 0;
190
 
        strpos = 0;
191
185
        ifs_str[0] = '\0';
192
186
        while (pos < size && strpos+7 < len-2) {
193
187
                struct usb_interface_descriptor *desc;
213
207
                memcpy(&ifs_str[strpos], if_str, 8),
214
208
                strpos += 7;
215
209
        }
 
210
 
216
211
        if (strpos > 0) {
217
212
                ifs_str[strpos++] = ':';
218
213
                ifs_str[strpos++] = '\0';
219
214
        }
220
 
out:
221
 
        free(filename);
222
 
        return err;
 
215
 
 
216
        return 0;
223
217
}
224
218
 
225
219
/*