firewire: core: improve check for local node
authorStefan Richter <stefanr@s5r6.in-berlin.de>
Wed, 13 May 2009 19:42:14 +0000 (21:42 +0200)
committerStefan Richter <stefanr@s5r6.in-berlin.de>
Sun, 17 May 2009 12:13:47 +0000 (14:13 +0200)
My recently added test for a device being local in fw-cdev.c got it
slightly wrong:  Comparisons of node IDs are only valid if the
generation is current, which I forgot to check.  Normally, serialization
by card->lock takes care of this, but a device in FW_DEVICE_GONE state
will necessarily have a wrong generation and invalid node_id.

The "is it local?" check is made 100% correct and simpler now by means
of a struct fw_device flag which is set at fw_device creation.

Besides the fw-cdev site which was to be fixed, there is another site
which can make use of the new flag, and an RFC-2734 driver will benefit
from it too.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
drivers/firewire/fw-cdev.c
drivers/firewire/fw-device.c
drivers/firewire/fw-device.h

index 7eb6594cc3e5b92e9891773ada1898a4f0831c38..8a5e6ae2552c11ff761edbd09d76215405e6b62a 100644 (file)
@@ -739,15 +739,11 @@ static void release_descriptor(struct client *client,
 static int ioctl_add_descriptor(struct client *client, void *buffer)
 {
        struct fw_cdev_add_descriptor *request = buffer;
-       struct fw_card *card = client->device->card;
        struct descriptor_resource *r;
        int ret;
 
        /* Access policy: Allow this ioctl only on local nodes' device files. */
-       spin_lock_irq(&card->lock);
-       ret = client->device->node_id != card->local_node->node_id;
-       spin_unlock_irq(&card->lock);
-       if (ret)
+       if (!client->device->is_local)
                return -ENOSYS;
 
        if (request->length > 256)
index a47e2129d83d3a5f99aa7165a6600f3bea9b5383..a38a68b97b5878f32b87f2d1993cc624f8d1add6 100644 (file)
@@ -1042,6 +1042,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
                device->node = fw_node_get(node);
                device->node_id = node->node_id;
                device->generation = card->generation;
+               device->is_local = node == card->local_node;
                mutex_init(&device->client_list_mutex);
                INIT_LIST_HEAD(&device->client_list);
 
@@ -1075,7 +1076,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
                            FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) {
                        PREPARE_DELAYED_WORK(&device->work, fw_device_refresh);
                        schedule_delayed_work(&device->work,
-                               node == card->local_node ? 0 : INITIAL_DELAY);
+                               device->is_local ? 0 : INITIAL_DELAY);
                }
                break;
 
index 97588937c0185167446ee29dda3abb50087075e0..623cfee289bd46cfe92ef76c99ad0b658c27ea47 100644 (file)
@@ -80,6 +80,7 @@ struct fw_device {
        u32 *config_rom;
        size_t config_rom_length;
        int config_rom_retries;
+       unsigned is_local:1;
        unsigned cmc:1;
        unsigned bc_implemented:2;