firewire: core: WARN on wrong usage of core transaction functions
PATCH 1/2 firewire: core: WARN on wrong usage of core transaction functions
In the code path which creates request packets, clearly mark a switch branch which must never be reached with a WARN.
In the code path which creates response packets, replace a BUG by a friendlier to debug WARN.
Signed-off-by Stefan Richter <[email protected]>
--- drivers/firewire/core-transaction.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/firewire/core-transaction.c +4 -2
@@ -218,6 +218,9 @@ static void fw_fill_request(struct fw_pa packet->header_length =16 ; packet->payload_length =0 ;break ; + +default : +WARN (1 ,KERN_ERR "wrong tcode %d" , tcode); } common: packet->speed = speed;
@@ -595,8 +598,7 @@ void fw_fill_response(struct fw_packet *break ;default : -BUG (); -return ; +WARN (1 ,KERN_ERR "wrong tcode %d" , tcode); } response->payload_bus =0 ;
Signature · 3 lines
Stefan Richter -=====-==--= =-=- -===- http://arcgraph.de/sr/
PATCH 2/2 firewire: ohci: 0 may be a valid DMA address
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.
Signed-off-by Stefan Richter <[email protected]>
--- drivers/firewire/core-transaction.c | 4 ++-- drivers/firewire/ohci.c | 9 +++++---- include/linux/firewire.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-)
drivers/firewire/ohci.c +5 -4
@@ -995,7 +995,8 @@ static int at_context_queue_packet(struc 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(struc*/ 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 conte/* 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_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 );
drivers/firewire/core-transaction.c +2 -2
@@ -226,7 +226,7 @@ static void fw_fill_request(struct fw_pa 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 *WARN (1 ,KERN_ERR "wrong tcode %d" , tcode); } - response->payload_bus =0 ; + response->payload_mapped = false; }EXPORT_SYMBOL (fw_fill_response);
include/linux/firewire.h +1 -0
@@ -267,6 +267,7 @@ struct fw_packet {void *payload;size_t payload_length;dma_addr_t payload_bus; +bool payload_mapped;u32 timestamp;/*
Signature · 3 lines
Stefan Richter -=====-==--= =-=- -===- http://arcgraph.de/sr/