public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: linux1394-devel@lists.sourceforge.net
Cc: linux-hotplug@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kay Sievers <kay.sievers@vrfy.org>
Subject: [PATCH 1/2] firewire: core: check for missing struct update at build time, not run time
Date: Fri, 22 May 2009 23:16:27 +0200 (CEST)	[thread overview]
Message-ID: <tkrat.7b837daea0cfa5b2@s5r6.in-berlin.de> (raw)
In-Reply-To: <ac3eb2510905220423h23e7aca1u3bc7c204db551eb0@mail.gmail.com>

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>
---
 drivers/firewire/fw-device.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Index: linux/drivers/firewire/fw-device.c
===================================================================
--- linux.orig/drivers/firewire/fw-device.c
+++ linux/drivers/firewire/fw-device.c
@@ -289,14 +289,13 @@ static void init_fw_attribute_group(stru
 		attr = &config_rom_attributes[i].attr;
 		if (attr->show(dev, attr, NULL) < 0)
 			continue;
 		group->attrs[j++] = &attr->attr;
 	}
 
-	BUG_ON(j >= ARRAY_SIZE(group->attrs));
-	group->attrs[j++] = NULL;
+	group->attrs[j] = NULL;
 	group->groups[0] = &group->group;
 	group->groups[1] = NULL;
 	group->group.attrs = group->attrs;
 	dev->groups = group->groups;
 }
 
@@ -570,9 +569,13 @@ static void create_units(struct fw_devic
 		unit->device.parent = &device->device;
 		dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++);
 
+		BUILD_BUG_ON(ARRAY_SIZE(unit->attribute_group.attrs) <
+				ARRAY_SIZE(fw_unit_attributes) +
+				ARRAY_SIZE(config_rom_attributes));
 		init_fw_attribute_group(&unit->device,
 					fw_unit_attributes,
 					&unit->attribute_group);
+
 		if (device_register(&unit->device) < 0)
 			goto skip_unit;
 
@@ -849,9 +852,13 @@ static void fw_device_init(struct work_s
 	device->device.devt = MKDEV(fw_cdev_major, minor);
 	dev_set_name(&device->device, "fw%d", minor);
 
+	BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) <
+			ARRAY_SIZE(fw_device_attributes) +
+			ARRAY_SIZE(config_rom_attributes));
 	init_fw_attribute_group(&device->device,
 				fw_device_attributes,
 				&device->attribute_group);
+
 	if (device_add(&device->device)) {
 		fw_error("Failed to add device.\n");
 		goto error_with_cdev;

-- 
Stefan Richter
-=====-==--= -=-= =-==-
http://arcgraph.de/sr/


       reply	other threads:[~2009-05-22 21:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <tkrat.d86e749d664670a9@s5r6.in-berlin.de>
     [not found] ` <ac3eb2510905211001m77eda9e4gb73001d504fd5376@mail.gmail.com>
     [not found]   ` <4A159899.20506@s5r6.in-berlin.de>
     [not found]     ` <4A165CED.8030601@s5r6.in-berlin.de>
     [not found]       ` <ac3eb2510905220423h23e7aca1u3bc7c204db551eb0@mail.gmail.com>
2009-05-22 21:16         ` Stefan Richter [this message]
2009-05-22 21:17           ` [PATCH 2/2] firewire: core: add sysfs attribute for easier udev rules Stefan Richter
2009-05-22 22:03             ` Stefan Richter
2009-05-23  0:35             ` Kay Sievers
2009-05-24 12:09               ` Stefan Richter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tkrat.7b837daea0cfa5b2@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-hotplug@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox