[PATCH] udev-remove.c cleanups
I've moved the malloc out of the udevdb into udev-remove to free the struct after use and not to allocate a different struct in the case the device is not in the data base. I seems a bit easier to read.
This commit is contained in:
parent
7ecb8d23f3
commit
a56ef38286
|
@ -119,18 +119,21 @@ static int delete_node(struct udevice *dev)
|
||||||
int udev_remove_device(char *path, char *subsystem)
|
int udev_remove_device(char *path, char *subsystem)
|
||||||
{
|
{
|
||||||
struct udevice *dev;
|
struct udevice *dev;
|
||||||
struct udevice device;
|
|
||||||
char *temp;
|
char *temp;
|
||||||
|
int retval;
|
||||||
|
|
||||||
dev = udevdb_get_dev(path);
|
dev = malloc(sizeof(*dev));
|
||||||
if (dev == NULL) {
|
if (dev == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
memset(dev, 0, sizeof(*dev));
|
||||||
|
|
||||||
|
retval = udevdb_get_dev(path, dev);
|
||||||
|
if (retval) {
|
||||||
dbg("'%s' not found in database, falling back on default name", path);
|
dbg("'%s' not found in database, falling back on default name", path);
|
||||||
temp = strrchr(path, '/');
|
temp = strrchr(path, '/');
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
memset(&device, 0, sizeof(device));
|
strncpy(dev->name, &temp[1], sizeof(dev->name));
|
||||||
dev = &device;
|
|
||||||
strncpy(device.name, &temp[1], sizeof(device.name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg("name is '%s'", dev->name);
|
dbg("name is '%s'", dev->name);
|
||||||
|
@ -138,5 +141,7 @@ int udev_remove_device(char *path, char *subsystem)
|
||||||
|
|
||||||
sysbus_send_remove(dev->name, path);
|
sysbus_send_remove(dev->name, path);
|
||||||
|
|
||||||
return delete_node(dev);
|
retval = delete_node(dev);
|
||||||
|
free(dev);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
15
udevdb.c
15
udevdb.c
|
@ -62,29 +62,22 @@ int udevdb_add_dev(const char *path, const struct udevice *dev)
|
||||||
return tdb_store(udevdb, key, data, TDB_REPLACE);
|
return tdb_store(udevdb, key, data, TDB_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct udevice *udevdb_get_dev(const char *path)
|
int udevdb_get_dev(const char *path, struct udevice *dev)
|
||||||
{
|
{
|
||||||
TDB_DATA key, data;
|
TDB_DATA key, data;
|
||||||
struct udevice *dev;
|
|
||||||
|
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return NULL;
|
return -ENODEV;
|
||||||
|
|
||||||
key.dptr = (void *)path;
|
key.dptr = (void *)path;
|
||||||
key.dsize = strlen(path) + 1;
|
key.dsize = strlen(path) + 1;
|
||||||
|
|
||||||
data = tdb_fetch(udevdb, key);
|
data = tdb_fetch(udevdb, key);
|
||||||
if (data.dptr == NULL || data.dsize == 0)
|
if (data.dptr == NULL || data.dsize == 0)
|
||||||
return NULL;
|
return -ENODEV;
|
||||||
|
|
||||||
dev = malloc(sizeof(*dev));
|
|
||||||
if (dev == NULL)
|
|
||||||
goto exit;
|
|
||||||
|
|
||||||
memcpy(dev, data.dptr, sizeof(*dev));
|
memcpy(dev, data.dptr, sizeof(*dev));
|
||||||
exit:
|
return 0;
|
||||||
free(data.dptr);
|
|
||||||
return dev;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int udevdb_delete_dev(const char *path)
|
int udevdb_delete_dev(const char *path)
|
||||||
|
|
2
udevdb.h
2
udevdb.h
|
@ -13,7 +13,7 @@ extern void udevdb_exit(void);
|
||||||
extern int udevdb_init(int init_flag);
|
extern int udevdb_init(int init_flag);
|
||||||
|
|
||||||
extern int udevdb_add_dev(const char *path, const struct udevice *dev);
|
extern int udevdb_add_dev(const char *path, const struct udevice *dev);
|
||||||
extern struct udevice *udevdb_get_dev(const char *path);
|
extern int udevdb_get_dev(const char *path, struct udevice *dev);
|
||||||
extern int udevdb_delete_dev(const char *path);
|
extern int udevdb_delete_dev(const char *path);
|
||||||
|
|
||||||
#endif /* _UDEVDB_H_ */
|
#endif /* _UDEVDB_H_ */
|
||||||
|
|
Loading…
Reference in New Issue