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