Skip to contentSkip to conversation

bug in udev-remove.c

udev Greg KH 2 participants 3 messages Dec 17, 2003 – Dec 19, 2003

lore
Share & tools
lore

Greg KH

author
#0 lore raw
Quoted 2 lines · Kay Sievers

Uups, we have a bug in udev-remove.c.

Ick, this was probably my fault from the merge with the dbus code, sorry. Thanks for the patch, I've applied it.

greg k-h

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 6 lines · Greg KH
Quoted 2 lines · Kay Sievers

Uups, we have a bug in udev-remove.c.

Ick, this was probably my fault from the merge with the dbus code, sorry. Thanks for the patch, I've applied it.

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.

thanks,
Kay

udev-remove.c +12 -7
diff -Nru a/udev-remove.c b/udev-remove.c
@@ -119,18 +119,21 @@
 int udev_remove_device(char *path, char *subsystem)
 {
 	struct udevice *dev;
-	struct udevice device;
 	char *temp;
+	int retval;
 
-	dev = udevdb_get_dev(path);
-	if (dev == NULL) {
+	dev = malloc(sizeof(*dev));
+	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);
 		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 @@
 
 	sysbus_send_remove(dev->name, path);
 
-	return delete_node(dev);
+	retval = delete_node(dev);
+	free(dev);
+	return retval;
 }
udevdb.c +4 -11
diff -Nru a/udevdb.c b/udevdb.c
@@ -62,29 +62,22 @@
 	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;
-	struct udevice *dev;
 
 	if (path == NULL)
-		return NULL;
+		return -ENODEV;
 
 	key.dptr = (void *)path;
 	key.dsize = strlen(path) + 1;
 
 	data = tdb_fetch(udevdb, key);
 	if (data.dptr == NULL || data.dsize == 0)
-		return NULL;
-
-	dev = malloc(sizeof(*dev));
-	if (dev == NULL)
-		goto exit;
+		return -ENODEV;
 
 	memcpy(dev, data.dptr, sizeof(*dev));
-exit:
-	free(data.dptr);
-	return dev;
+	return 0;
 }
 
 int udevdb_delete_dev(const char *path)
udevdb.h +1 -1
diff -Nru a/udevdb.h b/udevdb.h
@@ -13,7 +13,7 @@
 extern int udevdb_init(int init_flag);
 
 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);
 
 #endif /* _UDEVDB_H_ */
author
#2 lore raw
In reply to Greg KH
Quoted 11 lines · Kay Sievers
Quoted 6 lines · Greg KH
Quoted 2 lines · Kay Sievers

Uups, we have a bug in udev-remove.c.

Ick, this was probably my fault from the merge with the dbus code, sorry. Thanks for the patch, I've applied it.

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.

I agree, nice cleanup. I've applied this, thanks.

greg k-h

-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel