diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2009-05-22 17:16:27 -0400 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2009-06-01 06:48:49 -0400 |
commit | e5333db9285e088a98f4bad5147bfb0b4665fafb (patch) | |
tree | 10a46852f80d27a4eef4f51ae847c7c541c0fd07 /drivers | |
parent | 92368890d551794ee8d7e90477d8498bb7f82a9b (diff) |
firewire: core: check for missing struct update at build time, not run time
struct fw_attribute_group.attrs.[] must have enough room for all
attributes. This can and should be checked at build time.
Our previous check at run time was a little late and not reliable since
most of the time less than the available attributes are populated.
Furthermore, omit an increment of an index at its last usage.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/firewire/fw-device.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c index a38a68b97b58..98ce0841f4c9 100644 --- a/drivers/firewire/fw-device.c +++ b/drivers/firewire/fw-device.c | |||
@@ -292,8 +292,7 @@ static void init_fw_attribute_group(struct device *dev, | |||
292 | group->attrs[j++] = &attr->attr; | 292 | group->attrs[j++] = &attr->attr; |
293 | } | 293 | } |
294 | 294 | ||
295 | BUG_ON(j >= ARRAY_SIZE(group->attrs)); | 295 | group->attrs[j] = NULL; |
296 | group->attrs[j++] = NULL; | ||
297 | group->groups[0] = &group->group; | 296 | group->groups[0] = &group->group; |
298 | group->groups[1] = NULL; | 297 | group->groups[1] = NULL; |
299 | group->group.attrs = group->attrs; | 298 | group->group.attrs = group->attrs; |
@@ -570,9 +569,13 @@ static void create_units(struct fw_device *device) | |||
570 | unit->device.parent = &device->device; | 569 | unit->device.parent = &device->device; |
571 | dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++); | 570 | dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++); |
572 | 571 | ||
572 | BUILD_BUG_ON(ARRAY_SIZE(unit->attribute_group.attrs) < | ||
573 | ARRAY_SIZE(fw_unit_attributes) + | ||
574 | ARRAY_SIZE(config_rom_attributes)); | ||
573 | init_fw_attribute_group(&unit->device, | 575 | init_fw_attribute_group(&unit->device, |
574 | fw_unit_attributes, | 576 | fw_unit_attributes, |
575 | &unit->attribute_group); | 577 | &unit->attribute_group); |
578 | |||
576 | if (device_register(&unit->device) < 0) | 579 | if (device_register(&unit->device) < 0) |
577 | goto skip_unit; | 580 | goto skip_unit; |
578 | 581 | ||
@@ -849,9 +852,13 @@ static void fw_device_init(struct work_struct *work) | |||
849 | device->device.devt = MKDEV(fw_cdev_major, minor); | 852 | device->device.devt = MKDEV(fw_cdev_major, minor); |
850 | dev_set_name(&device->device, "fw%d", minor); | 853 | dev_set_name(&device->device, "fw%d", minor); |
851 | 854 | ||
855 | BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) < | ||
856 | ARRAY_SIZE(fw_device_attributes) + | ||
857 | ARRAY_SIZE(config_rom_attributes)); | ||
852 | init_fw_attribute_group(&device->device, | 858 | init_fw_attribute_group(&device->device, |
853 | fw_device_attributes, | 859 | fw_device_attributes, |
854 | &device->attribute_group); | 860 | &device->attribute_group); |
861 | |||
855 | if (device_add(&device->device)) { | 862 | if (device_add(&device->device)) { |
856 | fw_error("Failed to add device.\n"); | 863 | fw_error("Failed to add device.\n"); |
857 | goto error_with_cdev; | 864 | goto error_with_cdev; |