aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/message.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-08-14 09:15:12 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:51:01 -0400
commit7eff2e7a8b65c25920207324e56611150eb1cd9a (patch)
tree02a0eeba9d25d996233e30c18f258dfae0ae2139 /drivers/usb/core/message.c
parent8380770c842faef3001e44662953d64ad9a93663 (diff)
Driver core: change add_uevent_var to use a struct
This changes the uevent buffer functions to use a struct instead of a long list of parameters. It does no longer require the caller to do the proper buffer termination and size accounting, which is currently wrong in some places. It fixes a known bug where parts of the uevent environment are overwritten because of wrong index calculations. Many thanks to Mathieu Desnoyers for finding bugs and improving the error handling. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Cc: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core/message.c')
-rw-r--r--drivers/usb/core/message.c28
1 files changed, 7 insertions, 21 deletions
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index d8f7b089a8f..95a49d8efe7 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1339,14 +1339,11 @@ void usb_release_interface(struct device *dev)
1339} 1339}
1340 1340
1341#ifdef CONFIG_HOTPLUG 1341#ifdef CONFIG_HOTPLUG
1342static int usb_if_uevent(struct device *dev, char **envp, int num_envp, 1342static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
1343 char *buffer, int buffer_size)
1344{ 1343{
1345 struct usb_device *usb_dev; 1344 struct usb_device *usb_dev;
1346 struct usb_interface *intf; 1345 struct usb_interface *intf;
1347 struct usb_host_interface *alt; 1346 struct usb_host_interface *alt;
1348 int i = 0;
1349 int length = 0;
1350 1347
1351 if (!dev) 1348 if (!dev)
1352 return -ENODEV; 1349 return -ENODEV;
@@ -1359,39 +1356,30 @@ static int usb_if_uevent(struct device *dev, char **envp, int num_envp,
1359 alt = intf->cur_altsetting; 1356 alt = intf->cur_altsetting;
1360 1357
1361#ifdef CONFIG_USB_DEVICEFS 1358#ifdef CONFIG_USB_DEVICEFS
1362 if (add_uevent_var(envp, num_envp, &i, 1359 if (add_uevent_var(env, "DEVICE=/proc/bus/usb/%03d/%03d",
1363 buffer, buffer_size, &length,
1364 "DEVICE=/proc/bus/usb/%03d/%03d",
1365 usb_dev->bus->busnum, usb_dev->devnum)) 1360 usb_dev->bus->busnum, usb_dev->devnum))
1366 return -ENOMEM; 1361 return -ENOMEM;
1367#endif 1362#endif
1368 1363
1369 if (add_uevent_var(envp, num_envp, &i, 1364 if (add_uevent_var(env, "PRODUCT=%x/%x/%x",
1370 buffer, buffer_size, &length,
1371 "PRODUCT=%x/%x/%x",
1372 le16_to_cpu(usb_dev->descriptor.idVendor), 1365 le16_to_cpu(usb_dev->descriptor.idVendor),
1373 le16_to_cpu(usb_dev->descriptor.idProduct), 1366 le16_to_cpu(usb_dev->descriptor.idProduct),
1374 le16_to_cpu(usb_dev->descriptor.bcdDevice))) 1367 le16_to_cpu(usb_dev->descriptor.bcdDevice)))
1375 return -ENOMEM; 1368 return -ENOMEM;
1376 1369
1377 if (add_uevent_var(envp, num_envp, &i, 1370 if (add_uevent_var(env, "TYPE=%d/%d/%d",
1378 buffer, buffer_size, &length,
1379 "TYPE=%d/%d/%d",
1380 usb_dev->descriptor.bDeviceClass, 1371 usb_dev->descriptor.bDeviceClass,
1381 usb_dev->descriptor.bDeviceSubClass, 1372 usb_dev->descriptor.bDeviceSubClass,
1382 usb_dev->descriptor.bDeviceProtocol)) 1373 usb_dev->descriptor.bDeviceProtocol))
1383 return -ENOMEM; 1374 return -ENOMEM;
1384 1375
1385 if (add_uevent_var(envp, num_envp, &i, 1376 if (add_uevent_var(env, "INTERFACE=%d/%d/%d",
1386 buffer, buffer_size, &length,
1387 "INTERFACE=%d/%d/%d",
1388 alt->desc.bInterfaceClass, 1377 alt->desc.bInterfaceClass,
1389 alt->desc.bInterfaceSubClass, 1378 alt->desc.bInterfaceSubClass,
1390 alt->desc.bInterfaceProtocol)) 1379 alt->desc.bInterfaceProtocol))
1391 return -ENOMEM; 1380 return -ENOMEM;
1392 1381
1393 if (add_uevent_var(envp, num_envp, &i, 1382 if (add_uevent_var(env,
1394 buffer, buffer_size, &length,
1395 "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", 1383 "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
1396 le16_to_cpu(usb_dev->descriptor.idVendor), 1384 le16_to_cpu(usb_dev->descriptor.idVendor),
1397 le16_to_cpu(usb_dev->descriptor.idProduct), 1385 le16_to_cpu(usb_dev->descriptor.idProduct),
@@ -1404,14 +1392,12 @@ static int usb_if_uevent(struct device *dev, char **envp, int num_envp,
1404 alt->desc.bInterfaceProtocol)) 1392 alt->desc.bInterfaceProtocol))
1405 return -ENOMEM; 1393 return -ENOMEM;
1406 1394
1407 envp[i] = NULL;
1408 return 0; 1395 return 0;
1409} 1396}
1410 1397
1411#else 1398#else
1412 1399
1413static int usb_if_uevent(struct device *dev, char **envp, 1400static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
1414 int num_envp, char *buffer, int buffer_size)
1415{ 1401{
1416 return -ENODEV; 1402 return -ENODEV;
1417} 1403}