summaryrefslogtreecommitdiff
path: root/udev-remove.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2003-12-19 18:29:01 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:09 -0700
commita56ef382869bb76ade6d26cd7e8adc983ca3f89e (patch)
treeeb8ba1359793fe3994643a8aab8a5ef871986cd2 /udev-remove.c
parent7ecb8d23f371a38cd918334ee7bf8383f1807ddb (diff)
[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.
Diffstat (limited to 'udev-remove.c')
-rw-r--r--udev-remove.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/udev-remove.c b/udev-remove.c
index dad4a98570..6d7e2ad22a 100644
--- a/udev-remove.c
+++ b/udev-remove.c
@@ -119,18 +119,21 @@ static int delete_node(struct udevice *dev)
int udev_remove_device(char *path, char *subsystem)
{
struct udevice *dev;
- struct udevice device;
char *temp;
+ int retval;
+
+ dev = malloc(sizeof(*dev));
+ if (dev == NULL)
+ return -ENOMEM;
+ memset(dev, 0, sizeof(*dev));
- dev = udevdb_get_dev(path);
- if (dev == NULL) {
+ retval = udevdb_get_dev(path, dev);
+ if (retval) {
dbg("'%s' not found in database, falling back on default name", path);
temp = strrchr(path, '/');
if (temp == NULL)
return -ENODEV;
- memset(&device, 0, sizeof(device));
- dev = &device;
- strncpy(device.name, &temp[1], sizeof(device.name));
+ strncpy(dev->name, &temp[1], sizeof(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);
- return delete_node(dev);
+ retval = delete_node(dev);
+ free(dev);
+ return retval;
}