firewire: add parent-of-unit accessor

Retrieval of an fw_unit's parent is a common pattern in high-level code.
Wrap it up as device = fw_parent_device(unit).

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>

+28 -18
+2 -2
drivers/firewire/core-device.c
··· 93 if (!is_fw_unit(dev)) 94 return 0; 95 96 - device = fw_device(unit->device.parent); 97 id = container_of(drv, struct fw_driver, driver)->id_table; 98 99 for (; id->match_flags != 0; id++) { ··· 114 115 static int get_modalias(struct fw_unit *unit, char *buffer, size_t buffer_size) 116 { 117 - struct fw_device *device = fw_device(unit->device.parent); 118 struct fw_csr_iterator ci; 119 120 int key, value;
··· 93 if (!is_fw_unit(dev)) 94 return 0; 95 96 + device = fw_parent_device(unit); 97 id = container_of(drv, struct fw_driver, driver)->id_table; 98 99 for (; id->match_flags != 0; id++) { ··· 114 115 static int get_modalias(struct fw_unit *unit, char *buffer, size_t buffer_size) 116 { 117 + struct fw_device *device = fw_parent_device(unit); 118 struct fw_csr_iterator ci; 119 120 int key, value;
+21 -16
drivers/firewire/sbp2.c
··· 180 int blocked; /* ditto */ 181 }; 182 183 /* Impossible login_id, to detect logout attempt before successful login */ 184 #define INVALID_LOGIN_ID 0x10000 185 ··· 493 static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, 494 int node_id, int generation, u64 offset) 495 { 496 - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 497 unsigned long flags; 498 499 orb->pointer.high = 0; ··· 515 516 static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu) 517 { 518 - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 519 struct sbp2_orb *orb, *next; 520 struct list_head list; 521 unsigned long flags; ··· 553 int generation, int function, 554 int lun_or_login_id, void *response) 555 { 556 - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 557 struct sbp2_management_orb *orb; 558 unsigned int timeout; 559 int retval = -ENOMEM; ··· 649 650 static void sbp2_agent_reset(struct sbp2_logical_unit *lu) 651 { 652 - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 653 __be32 d = 0; 654 655 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, ··· 666 667 static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu) 668 { 669 - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 670 struct fw_transaction *t; 671 static __be32 d; 672 ··· 705 static void sbp2_conditionally_block(struct sbp2_logical_unit *lu) 706 { 707 struct sbp2_target *tgt = lu->tgt; 708 - struct fw_card *card = fw_device(tgt->unit->device.parent)->card; 709 struct Scsi_Host *shost = 710 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 711 unsigned long flags; ··· 729 static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu) 730 { 731 struct sbp2_target *tgt = lu->tgt; 732 - struct fw_card *card = fw_device(tgt->unit->device.parent)->card; 733 struct Scsi_Host *shost = 734 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 735 unsigned long flags; ··· 754 */ 755 static void sbp2_unblock(struct sbp2_target *tgt) 756 { 757 - struct fw_card *card = fw_device(tgt->unit->device.parent)->card; 758 struct Scsi_Host *shost = 759 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 760 unsigned long flags; ··· 784 struct Scsi_Host *shost = 785 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 786 struct scsi_device *sdev; 787 - struct fw_device *device = fw_device(tgt->unit->device.parent); 788 789 /* prevent deadlocks */ 790 sbp2_unblock(tgt); ··· 857 */ 858 static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu) 859 { 860 - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 861 __be32 d = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT); 862 863 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, ··· 873 struct sbp2_logical_unit *lu = 874 container_of(work, struct sbp2_logical_unit, work.work); 875 struct sbp2_target *tgt = lu->tgt; 876 - struct fw_device *device = fw_device(tgt->unit->device.parent); 877 struct Scsi_Host *shost; 878 struct scsi_device *sdev; 879 struct sbp2_login_response response; ··· 1121 static int sbp2_probe(struct device *dev) 1122 { 1123 struct fw_unit *unit = fw_unit(dev); 1124 - struct fw_device *device = fw_device(unit->device.parent); 1125 struct sbp2_target *tgt; 1126 struct sbp2_logical_unit *lu; 1127 struct Scsi_Host *shost; ··· 1202 struct sbp2_logical_unit *lu = 1203 container_of(work, struct sbp2_logical_unit, work.work); 1204 struct sbp2_target *tgt = lu->tgt; 1205 - struct fw_device *device = fw_device(tgt->unit->device.parent); 1206 int generation, node_id, local_node_id; 1207 1208 if (fw_device_is_shutdown(device)) ··· 1254 struct sbp2_target *tgt = unit->device.driver_data; 1255 struct sbp2_logical_unit *lu; 1256 1257 - fw_device_enable_phys_dma(fw_device(unit->device.parent)); 1258 1259 /* 1260 * Fw-core serializes sbp2_update() against sbp2_remove(). ··· 1347 { 1348 struct sbp2_command_orb *orb = 1349 container_of(base_orb, struct sbp2_command_orb, base); 1350 - struct fw_device *device = fw_device(orb->lu->tgt->unit->device.parent); 1351 int result; 1352 1353 if (status != NULL) { ··· 1454 static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) 1455 { 1456 struct sbp2_logical_unit *lu = cmd->device->hostdata; 1457 - struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 1458 struct sbp2_command_orb *orb; 1459 int generation, retval = SCSI_MLQUEUE_HOST_BUSY; 1460
··· 180 int blocked; /* ditto */ 181 }; 182 183 + static struct fw_device *target_device(struct sbp2_target *tgt) 184 + { 185 + return fw_parent_device(tgt->unit); 186 + } 187 + 188 /* Impossible login_id, to detect logout attempt before successful login */ 189 #define INVALID_LOGIN_ID 0x10000 190 ··· 488 static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, 489 int node_id, int generation, u64 offset) 490 { 491 + struct fw_device *device = target_device(lu->tgt); 492 unsigned long flags; 493 494 orb->pointer.high = 0; ··· 510 511 static int sbp2_cancel_orbs(struct sbp2_logical_unit *lu) 512 { 513 + struct fw_device *device = target_device(lu->tgt); 514 struct sbp2_orb *orb, *next; 515 struct list_head list; 516 unsigned long flags; ··· 548 int generation, int function, 549 int lun_or_login_id, void *response) 550 { 551 + struct fw_device *device = target_device(lu->tgt); 552 struct sbp2_management_orb *orb; 553 unsigned int timeout; 554 int retval = -ENOMEM; ··· 644 645 static void sbp2_agent_reset(struct sbp2_logical_unit *lu) 646 { 647 + struct fw_device *device = target_device(lu->tgt); 648 __be32 d = 0; 649 650 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, ··· 661 662 static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu) 663 { 664 + struct fw_device *device = target_device(lu->tgt); 665 struct fw_transaction *t; 666 static __be32 d; 667 ··· 700 static void sbp2_conditionally_block(struct sbp2_logical_unit *lu) 701 { 702 struct sbp2_target *tgt = lu->tgt; 703 + struct fw_card *card = target_device(tgt)->card; 704 struct Scsi_Host *shost = 705 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 706 unsigned long flags; ··· 724 static void sbp2_conditionally_unblock(struct sbp2_logical_unit *lu) 725 { 726 struct sbp2_target *tgt = lu->tgt; 727 + struct fw_card *card = target_device(tgt)->card; 728 struct Scsi_Host *shost = 729 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 730 unsigned long flags; ··· 749 */ 750 static void sbp2_unblock(struct sbp2_target *tgt) 751 { 752 + struct fw_card *card = target_device(tgt)->card; 753 struct Scsi_Host *shost = 754 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 755 unsigned long flags; ··· 779 struct Scsi_Host *shost = 780 container_of((void *)tgt, struct Scsi_Host, hostdata[0]); 781 struct scsi_device *sdev; 782 + struct fw_device *device = target_device(tgt); 783 784 /* prevent deadlocks */ 785 sbp2_unblock(tgt); ··· 852 */ 853 static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu) 854 { 855 + struct fw_device *device = target_device(lu->tgt); 856 __be32 d = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT); 857 858 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST, ··· 868 struct sbp2_logical_unit *lu = 869 container_of(work, struct sbp2_logical_unit, work.work); 870 struct sbp2_target *tgt = lu->tgt; 871 + struct fw_device *device = target_device(tgt); 872 struct Scsi_Host *shost; 873 struct scsi_device *sdev; 874 struct sbp2_login_response response; ··· 1116 static int sbp2_probe(struct device *dev) 1117 { 1118 struct fw_unit *unit = fw_unit(dev); 1119 + struct fw_device *device = fw_parent_device(unit); 1120 struct sbp2_target *tgt; 1121 struct sbp2_logical_unit *lu; 1122 struct Scsi_Host *shost; ··· 1197 struct sbp2_logical_unit *lu = 1198 container_of(work, struct sbp2_logical_unit, work.work); 1199 struct sbp2_target *tgt = lu->tgt; 1200 + struct fw_device *device = target_device(tgt); 1201 int generation, node_id, local_node_id; 1202 1203 if (fw_device_is_shutdown(device)) ··· 1249 struct sbp2_target *tgt = unit->device.driver_data; 1250 struct sbp2_logical_unit *lu; 1251 1252 + fw_device_enable_phys_dma(fw_parent_device(unit)); 1253 1254 /* 1255 * Fw-core serializes sbp2_update() against sbp2_remove(). ··· 1342 { 1343 struct sbp2_command_orb *orb = 1344 container_of(base_orb, struct sbp2_command_orb, base); 1345 + struct fw_device *device = target_device(orb->lu->tgt); 1346 int result; 1347 1348 if (status != NULL) { ··· 1449 static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done) 1450 { 1451 struct sbp2_logical_unit *lu = cmd->device->hostdata; 1452 + struct fw_device *device = target_device(lu->tgt); 1453 struct sbp2_command_orb *orb; 1454 int generation, retval = SCSI_MLQUEUE_HOST_BUSY; 1455
+5
include/linux/firewire.h
··· 248 put_device(&unit->device); 249 } 250 251 struct ieee1394_device_id; 252 253 struct fw_driver {
··· 248 put_device(&unit->device); 249 } 250 251 + static inline struct fw_device *fw_parent_device(struct fw_unit *unit) 252 + { 253 + return fw_device(unit->device.parent); 254 + } 255 + 256 struct ieee1394_device_id; 257 258 struct fw_driver {