From 8733d0a18aceb48334dedbdbdc433a47b473c575 Mon Sep 17 00:00:00 2001 From: Wendy Liang Date: Thu, 10 Nov 2016 15:55:51 -0800 Subject: [LIBMETAL PATCH] linux: uio dev: open dev file only if it exists It can take some time to have the /dev/uioX in the file system after it binds the platform device to the UIO driver. Check if the device file exists before trying to open the file. Signed-off-by: Wendy Liang --- lib/system/linux/device.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/system/linux/device.c b/lib/system/linux/device.c index 9fae373..fbd2133 100644 --- a/lib/system/linux/device.c +++ b/lib/system/linux/device.c @@ -214,6 +214,18 @@ static int metal_uio_dev_open(struct linux_bus *lbus, struct linux_device *ldev) return -ENODEV; } + i = 0; + do { + if (!access(ldev->dev_path, F_OK)) + break; + usleep(10); + i++; + } while (i < 1000); + if (i >= 1000) { + metal_log(LOG_ERROR, "failed to open file %s, timeout.\n", + ldev->dev_path); + return -ENODEV; + } result = metal_open(ldev->dev_path, 0); if (result < 0) { metal_log(LOG_ERROR, "failed to open device %s\n", -- 1.9.1