diff options
Diffstat (limited to 'drivers/firewire/fw-transaction.c')
-rw-r--r-- | drivers/firewire/fw-transaction.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c index ccf0e4cf108f..03ae8a77c479 100644 --- a/drivers/firewire/fw-transaction.c +++ b/drivers/firewire/fw-transaction.c | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include <linux/completion.h> | 21 | #include <linux/completion.h> |
22 | #include <linux/kernel.h> | 22 | #include <linux/kernel.h> |
23 | #include <linux/kref.h> | ||
23 | #include <linux/module.h> | 24 | #include <linux/module.h> |
24 | #include <linux/init.h> | 25 | #include <linux/init.h> |
25 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
@@ -297,37 +298,55 @@ EXPORT_SYMBOL(fw_send_request); | |||
297 | struct fw_phy_packet { | 298 | struct fw_phy_packet { |
298 | struct fw_packet packet; | 299 | struct fw_packet packet; |
299 | struct completion done; | 300 | struct completion done; |
301 | struct kref kref; | ||
300 | }; | 302 | }; |
301 | 303 | ||
302 | static void | 304 | static void phy_packet_release(struct kref *kref) |
303 | transmit_phy_packet_callback(struct fw_packet *packet, | 305 | { |
304 | struct fw_card *card, int status) | 306 | struct fw_phy_packet *p = |
307 | container_of(kref, struct fw_phy_packet, kref); | ||
308 | kfree(p); | ||
309 | } | ||
310 | |||
311 | static void transmit_phy_packet_callback(struct fw_packet *packet, | ||
312 | struct fw_card *card, int status) | ||
305 | { | 313 | { |
306 | struct fw_phy_packet *p = | 314 | struct fw_phy_packet *p = |
307 | container_of(packet, struct fw_phy_packet, packet); | 315 | container_of(packet, struct fw_phy_packet, packet); |
308 | 316 | ||
309 | complete(&p->done); | 317 | complete(&p->done); |
318 | kref_put(&p->kref, phy_packet_release); | ||
310 | } | 319 | } |
311 | 320 | ||
312 | void fw_send_phy_config(struct fw_card *card, | 321 | void fw_send_phy_config(struct fw_card *card, |
313 | int node_id, int generation, int gap_count) | 322 | int node_id, int generation, int gap_count) |
314 | { | 323 | { |
315 | struct fw_phy_packet p; | 324 | struct fw_phy_packet *p; |
325 | long timeout = DIV_ROUND_UP(HZ, 10); | ||
316 | u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG) | | 326 | u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG) | |
317 | PHY_CONFIG_ROOT_ID(node_id) | | 327 | PHY_CONFIG_ROOT_ID(node_id) | |
318 | PHY_CONFIG_GAP_COUNT(gap_count); | 328 | PHY_CONFIG_GAP_COUNT(gap_count); |
319 | 329 | ||
320 | p.packet.header[0] = data; | 330 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
321 | p.packet.header[1] = ~data; | 331 | if (p == NULL) |
322 | p.packet.header_length = 8; | 332 | return; |
323 | p.packet.payload_length = 0; | 333 | |
324 | p.packet.speed = SCODE_100; | 334 | p->packet.header[0] = data; |
325 | p.packet.generation = generation; | 335 | p->packet.header[1] = ~data; |
326 | p.packet.callback = transmit_phy_packet_callback; | 336 | p->packet.header_length = 8; |
327 | init_completion(&p.done); | 337 | p->packet.payload_length = 0; |
328 | 338 | p->packet.speed = SCODE_100; | |
329 | card->driver->send_request(card, &p.packet); | 339 | p->packet.generation = generation; |
330 | wait_for_completion(&p.done); | 340 | p->packet.callback = transmit_phy_packet_callback; |
341 | init_completion(&p->done); | ||
342 | kref_set(&p->kref, 2); | ||
343 | |||
344 | card->driver->send_request(card, &p->packet); | ||
345 | timeout = wait_for_completion_timeout(&p->done, timeout); | ||
346 | kref_put(&p->kref, phy_packet_release); | ||
347 | |||
348 | /* will leak p if the callback is never executed */ | ||
349 | WARN_ON(timeout == 0); | ||
331 | } | 350 | } |
332 | 351 | ||
333 | void fw_flush_transactions(struct fw_card *card) | 352 | void fw_flush_transactions(struct fw_card *card) |
@@ -572,7 +591,8 @@ allocate_request(struct fw_packet *p) | |||
572 | break; | 591 | break; |
573 | 592 | ||
574 | default: | 593 | default: |
575 | BUG(); | 594 | fw_error("ERROR - corrupt request received - %08x %08x %08x\n", |
595 | p->header[0], p->header[1], p->header[2]); | ||
576 | return NULL; | 596 | return NULL; |
577 | } | 597 | } |
578 | 598 | ||