Sometimes the devpath gets empty string. It is not sure, but the deviced
seems to get blocked in such case, reading the parent's product/serial
node. It leads watchdog timeout, and the deviced gets SIGABRT from the
systemd. It is not clear that the empty devpath results it though, add
guard clauses for filtering out such an abnormal devpath.
(gdb) bt
#0 __libc_read (nbytes=4097, buf=0xaba70f28, fd=-
1415114968)
at ../sysdeps/unix/sysv/linux/read.c:26
#1 __libc_read (fd=fd@entry=28, buf=buf@entry=0xaba70f28,
nbytes=nbytes@entry=4097) at ../sysdeps/unix/sysv/linux/read.c:24
#2 0xf76289a2 in read (__nbytes=4097, __buf=0xaba70f28, __fd=28)
at /usr/include/bits/unistd.h:44
#3 read_full_virtual_file (filename=<optimized out>, ret_contents=0xffd180ec,
ret_size=0xffd180f4) at ../src/basic/fileio.c:371
#4 0xf7626608 in sd_device_get_sysattr_value (device=0xaba084f8,
sysattr=0xaaefe36c "product", _value=0xffd181b0)
at ../src/libsystemd/sd-device/sd-device.c:1789
#5 0xf761c92e in udev_device_get_sysattr_value (
udev_device=udev_device@entry=0xaba2c060, sysattr=<optimized out>)
at ../src/libudev/libudev-device.c:741
#6 0xaaeec55c in add_usbhost_list (dev=dev@entry=0xab9fc4e0,
devpath=devpath@entry=0xaba3d984 "")
at /usr/src/debug/deviced-10.0.0-1.arm/src/usb-host/usb-host.c:236
Change-Id: I52ac60e5fefa48ea7e262c3ca7472a019786ca82
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
*/
#include <stdio.h>
#include <stdint.h>
+#include <string.h>
#include <limits.h>
#include <sys/stat.h>
#include <fcntl.h>
const char *str;
struct udev_device *parent;
+ if (!devpath || strlen(devpath) == 0)
+ return -EINVAL;
+
/* allocate new usbhost device */
usbhost = calloc(1, sizeof(struct usbhost_device));
if (!usbhost) {
/* devpath is an unique information among usb host devices */
devpath = udev_device_get_devpath(dev);
- if (!devpath) {
+ if (!devpath || strlen(devpath) == 0) {
_E("Failed to get devpath from udev_device.");
return;
}
/* devpath is an unique information among usb host devices */
devpath = udev_device_get_devpath(dev);
- if (!devpath) {
+ if (!devpath || strlen(devpath) == 0) {
_E("Failed to get devpath from '%s' device.", syspath);
continue;
}
}
rdevpath = udev_device_get_devpath(udev_device);
- if (!rdevpath) {
+ if (!rdevpath || !strlen(rdevpath)) {
_E("Failed to get devpath from udev_device.");
ret = -errno;
goto out;