summaryrefslogtreecommitdiffstats
path: root/lib/driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/driver.c')
-rw-r--r--lib/driver.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/driver.c b/lib/driver.c
index b60074511f..66d8fee38f 100644
--- a/lib/driver.c
+++ b/lib/driver.c
@@ -45,11 +45,21 @@ static LIST_HEAD(active);
struct device_d *get_device_by_name(const char *name)
{
struct device_d *dev;
- char devname[MAX_DRIVER_NAME + 3];
for_each_device(dev) {
- sprintf(devname, "%s%d", dev->name, dev->id);
- if(!strcmp(name, devname))
+ if(!strcmp(dev_name(dev), name))
+ return dev;
+ }
+
+ return NULL;
+}
+
+struct device_d *get_device_by_name_id(const char *name, int id)
+{
+ struct device_d *dev;
+
+ for_each_device(dev) {
+ if(!strcmp(dev->name, name) && id == dev->id)
return dev;
}
@@ -59,11 +69,9 @@ struct device_d *get_device_by_name(const char *name)
int get_free_deviceid(const char *name_template)
{
int i = 0;
- char name[MAX_DRIVER_NAME + 3];
while (1) {
- sprintf(name, "%s%d", name_template, i);
- if (!get_device_by_name(name))
+ if (!get_device_by_name_id(name_template, i))
return i;
i++;
};
@@ -95,9 +103,17 @@ int register_device(struct device_d *new_device)
{
struct driver_d *drv;
- new_device->id = get_free_deviceid(new_device->name);
+ if (new_device->id < 0) {
+ new_device->id = get_free_deviceid(new_device->name);
+ } else {
+ if (get_device_by_name_id(new_device->name, new_device->id)) {
+ eprintf("register_device: already registered %s\n",
+ dev_name(new_device));
+ return -EINVAL;
+ }
+ }
- debug ("register_device: %s\n",new_device->name);
+ debug ("register_device: %s\n", dev_name(new_device));
if (!new_device->bus) {
// dev_err(new_device, "no bus type associated. Needs fixup\n");
@@ -120,7 +136,7 @@ EXPORT_SYMBOL(register_device);
int unregister_device(struct device_d *old_dev)
{
- debug("unregister_device: %s:%s\n",old_dev->name, old_dev->id);
+ debug("unregister_device: %s\n", dev_name(old_dev));
if (!list_empty(&old_dev->children)) {
errno = -EBUSY;
@@ -164,7 +180,7 @@ struct driver_d *get_driver_by_name(const char *name)
static void noinfo(struct device_d *dev)
{
- printf("no info available for %s\n", dev->name);
+ printf("no info available for %s\n", dev_name(dev));
}
static void noshortinfo(struct device_d *dev)
@@ -237,7 +253,7 @@ static int do_devinfo_subtree(struct device_d *dev, int depth, char edge)
for (i = 0; i < depth; i++)
printf("| ");
- printf("%c----%s%d", edge, dev->name, dev->id);
+ printf("%c----%s", edge, dev_name(dev));
if (!list_empty(&dev->cdevs)) {
printf(" (");
list_for_each_entry(cdev, &dev->cdevs, devices_list) {
@@ -264,7 +280,7 @@ const char *dev_id(const struct device_d *dev)
{
static char buf[sizeof(unsigned long) * 2];
- sprintf(buf, "%s%d", dev->name, dev->id);
+ sprintf(buf, FORMAT_DRIVER_MANE_ID, dev->name, dev->id);
return buf;
}