From 314edf3ca44b268fa70a7a87a106322e2dd461af Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 27 Aug 2005 15:46:58 +0200 Subject: change parameter order of udev_db_search_name() Signed-off-by: Kay Sievers --- udev_db.c | 2 +- udev_db.h | 2 +- udev_rules.c | 19 +++++++++++-------- udevinfo.c | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/udev_db.c b/udev_db.c index d958c6173b..5377a3b373 100644 --- a/udev_db.c +++ b/udev_db.c @@ -202,7 +202,7 @@ int udev_db_get_device(struct udevice *udev, const char *devpath) return 0; } -int udev_db_search_name(char *devpath, size_t len, const char *name) +int udev_db_search_name(const char *name, char *devpath, size_t len) { DIR *dir; char path[PATH_SIZE]; diff --git a/udev_db.h b/udev_db.h index 61ea5b47fc..b0bc51a2c7 100644 --- a/udev_db.h +++ b/udev_db.h @@ -27,7 +27,7 @@ extern int udev_db_add_device(struct udevice *dev); extern int udev_db_delete_device(struct udevice *dev); extern int udev_db_get_device(struct udevice *udev, const char *devpath); -extern int udev_db_search_name(char *devpath, size_t len, const char *name); +extern int udev_db_search_name(const char *name, char *devpath, size_t len); extern int udev_db_get_all_entries(struct list_head *name_list); #endif /* _UDEV_DB_H_ */ diff --git a/udev_rules.c b/udev_rules.c index 6c6aa0f091..8db7fd377a 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -270,28 +270,31 @@ static int import_parent_into_env(struct udevice *udev, struct sysfs_class_devic /* finds the lowest positive N such that N isn't present in the udevdb * if doesn't exist, 0 is returned, N otherwise */ -static int find_free_number(const char *name) +static int find_free_number(const char *name, const char *devpath) { - char devpath[PATH_SIZE]; + char db_devpath[PATH_SIZE]; char filename[PATH_SIZE]; int num = 0; strlcpy(filename, name, sizeof(filename)); while (1) { dbg("look for existing node '%s'", filename); - if (udev_db_search_name(devpath, sizeof(devpath), filename) != 0) { + if (udev_db_search_name(filename, db_devpath, sizeof(db_devpath)) != 0) { dbg("free num=%d", num); - return num; + break; } num++; - if (num > 1000) { - info("find_free_number gone crazy (num=%d), aborted", num); - return -1; + if (num > 100000) { + err("find_free_number aborted at num=%d", num); + num = -1; + break; } snprintf(filename, sizeof(filename), "%s%d", name, num); filename[sizeof(filename)-1] = '\0'; } + + return num; } static int find_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, @@ -546,7 +549,7 @@ found: dbg("substitute sysfs value '%s'", temp2); break; case SUBST_ENUM: - next_free_number = find_free_number(string); + next_free_number = find_free_number(string, udev->devpath); if (next_free_number > 0) { sprintf(temp2, "%d", next_free_number); strlcat(string, temp2, maxsize); diff --git a/udevinfo.c b/udevinfo.c index 11b0104581..b546488c7e 100644 --- a/udevinfo.c +++ b/udevinfo.c @@ -321,7 +321,7 @@ int main(int argc, char *argv[], char *envp[]) } else pos = name; - retval = udev_db_search_name(devpath, sizeof(devpath), pos); + retval = udev_db_search_name(pos, devpath, sizeof(devpath)); if (retval != 0) { fprintf(stderr, "no record for '%s' in database\n", pos); goto exit; -- cgit v1.2.3-54-g00ecf