firewire: ohci: 0 may be a valid DMA address
authorStefan Richter <stefanr@s5r6.in-berlin.de>
Wed, 14 Oct 2009 18:40:10 +0000 (20:40 +0200)
committerStefan Richter <stefanr@s5r6.in-berlin.de>
Sat, 31 Oct 2009 10:40:51 +0000 (11:40 +0100)
I was told that there are obscure architectures with non-coherent DMA
which may DMA-map to bus address 0.  We shall not use 0 as a magic
number of uninitialized bus address variables.

The packet->payload_length > 0 test cannot be used either (except in
at_context_queue_packet) because local requests are not DMA-mapped
regardless of payload_length.  Hence add a state flag to struct
fw_packet.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
drivers/firewire/core-transaction.c
drivers/firewire/ohci.c
include/linux/firewire.h

index 66789c3cc561514eac80189c76358e09bfb23345..842739df23e26cbb3f6a8caeec780c0872dc60fa 100644 (file)
@@ -226,7 +226,7 @@ static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
        packet->speed = speed;
        packet->generation = generation;
        packet->ack = 0;
-       packet->payload_bus = 0;
+       packet->payload_mapped = false;
 }
 
 /**
@@ -601,7 +601,7 @@ void fw_fill_response(struct fw_packet *response, u32 *request_header,
                WARN(1, KERN_ERR "wrong tcode %d", tcode);
        }
 
-       response->payload_bus = 0;
+       response->payload_mapped = false;
 }
 EXPORT_SYMBOL(fw_fill_response);
 
index 418415564791934f6870f651a3863ec737afa4ea..a71477541dc7e300d40a9e40e667eb57dbbb5551 100644 (file)
@@ -995,7 +995,8 @@ static int at_context_queue_packet(struct context *ctx,
                        packet->ack = RCODE_SEND_ERROR;
                        return -1;
                }
-               packet->payload_bus = payload_bus;
+               packet->payload_bus     = payload_bus;
+               packet->payload_mapped  = true;
 
                d[2].req_count    = cpu_to_le16(packet->payload_length);
                d[2].data_address = cpu_to_le32(payload_bus);
@@ -1023,7 +1024,7 @@ static int at_context_queue_packet(struct context *ctx,
         */
        if (ohci->generation != packet->generation ||
            reg_read(ohci, OHCI1394_IntEventSet) & OHCI1394_busReset) {
-               if (packet->payload_length > 0)
+               if (packet->payload_mapped)
                        dma_unmap_single(ohci->card.device, payload_bus,
                                         packet->payload_length, DMA_TO_DEVICE);
                packet->ack = RCODE_GENERATION;
@@ -1059,7 +1060,7 @@ static int handle_at_packet(struct context *context,
                /* This packet was cancelled, just continue. */
                return 1;
 
-       if (packet->payload_bus)
+       if (packet->payload_mapped)
                dma_unmap_single(ohci->card.device, packet->payload_bus,
                                 packet->payload_length, DMA_TO_DEVICE);
 
@@ -1723,7 +1724,7 @@ static int ohci_cancel_packet(struct fw_card *card, struct fw_packet *packet)
        if (packet->ack != 0)
                goto out;
 
-       if (packet->payload_bus)
+       if (packet->payload_mapped)
                dma_unmap_single(ohci->card.device, packet->payload_bus,
                                 packet->payload_length, DMA_TO_DEVICE);
 
index 211a5d7d87b3e37cb2f07bd6f6d8edba2bb9066f..9416a461b69654b78bf51532cbecff7654f83c8e 100644 (file)
@@ -267,6 +267,7 @@ struct fw_packet {
        void *payload;
        size_t payload_length;
        dma_addr_t payload_bus;
+       bool payload_mapped;
        u32 timestamp;
 
        /*