Commit 210762268466634ddbfaddb48fdf5181ce4b5f2d

Authored by Stefan Richter
1 parent 2ca526bf49

firewire: move fw_device reference counting from drivers to core

fw_unit device drivers invariably need to talk to the fw_unit's parent
(an fw_device) and grandparent (an fw_card).  firewire-core already
maintains an fw_card reference for the entire lifetime of an fw_device.
Likewise, let firewire-core maintain an fw_device reference for the
entire lifetime of an fw_unit so that fw_unit drivers don't have to.

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

Showing 5 changed files with 16 additions and 19 deletions Side-by-side Diff

drivers/firewire/core-device.c
... ... @@ -641,6 +641,7 @@
641 641 {
642 642 struct fw_unit *unit = fw_unit(dev);
643 643  
  644 + fw_device_put(fw_parent_device(unit));
644 645 kfree(unit);
645 646 }
646 647  
... ... @@ -692,6 +693,7 @@
692 693 if (device_register(&unit->device) < 0)
693 694 goto skip_unit;
694 695  
  696 + fw_device_get(device);
695 697 continue;
696 698  
697 699 skip_unit:
drivers/firewire/core.h
1 1 #ifndef _FIREWIRE_CORE_H
2 2 #define _FIREWIRE_CORE_H
3 3  
  4 +#include <linux/device.h>
4 5 #include <linux/fs.h>
5 6 #include <linux/list.h>
6 7 #include <linux/idr.h>
... ... @@ -140,6 +141,18 @@
140 141 extern struct rw_semaphore fw_device_rwsem;
141 142 extern struct idr fw_device_idr;
142 143 extern int fw_cdev_major;
  144 +
  145 +static inline struct fw_device *fw_device_get(struct fw_device *device)
  146 +{
  147 + get_device(&device->device);
  148 +
  149 + return device;
  150 +}
  151 +
  152 +static inline void fw_device_put(struct fw_device *device)
  153 +{
  154 + put_device(&device->device);
  155 +}
143 156  
144 157 struct fw_device *fw_device_get_by_devt(dev_t devt);
145 158 int fw_device_set_broadcast_channel(struct device *dev, void *gen);
include/linux/firewire.h
... ... @@ -203,18 +203,6 @@
203 203 return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
204 204 }
205 205  
206   -static inline struct fw_device *fw_device_get(struct fw_device *device)
207   -{
208   - get_device(&device->device);
209   -
210   - return device;
211   -}
212   -
213   -static inline void fw_device_put(struct fw_device *device)
214   -{
215   - put_device(&device->device);
216   -}
217   -
218 206 int fw_device_enable_phys_dma(struct fw_device *device);
219 207  
220 208 /*
sound/firewire/isight.c
... ... @@ -612,7 +612,6 @@
612 612  
613 613 fw_iso_resources_destroy(&isight->resources);
614 614 fw_unit_put(isight->unit);
615   - fw_device_put(isight->device);
616 615 mutex_destroy(&isight->mutex);
617 616 }
618 617  
... ... @@ -645,7 +644,7 @@
645 644 isight->card = card;
646 645 mutex_init(&isight->mutex);
647 646 isight->unit = fw_unit_get(unit);
648   - isight->device = fw_device_get(fw_dev);
  647 + isight->device = fw_dev;
649 648 isight->audio_base = get_unit_base(unit);
650 649 if (!isight->audio_base) {
651 650 dev_err(&unit->device, "audio unit base not found\n");
... ... @@ -682,7 +681,6 @@
682 681  
683 682 err_unit:
684 683 fw_unit_put(isight->unit);
685   - fw_device_put(isight->device);
686 684 mutex_destroy(&isight->mutex);
687 685 error:
688 686 snd_card_free(card);
sound/firewire/speakers.c
... ... @@ -656,12 +656,10 @@
656 656 static void fwspk_card_free(struct snd_card *card)
657 657 {
658 658 struct fwspk *fwspk = card->private_data;
659   - struct fw_device *dev = fw_parent_device(fwspk->unit);
660 659  
661 660 amdtp_out_stream_destroy(&fwspk->stream);
662 661 cmp_connection_destroy(&fwspk->connection);
663 662 fw_unit_put(fwspk->unit);
664   - fw_device_put(dev);
665 663 mutex_destroy(&fwspk->mutex);
666 664 }
667 665  
... ... @@ -718,7 +716,6 @@
718 716 fwspk = card->private_data;
719 717 fwspk->card = card;
720 718 mutex_init(&fwspk->mutex);
721   - fw_device_get(fw_dev);
722 719 fwspk->unit = fw_unit_get(unit);
723 720 fwspk->device_info = fwspk_detect(fw_dev);
724 721 if (!fwspk->device_info) {
... ... @@ -767,7 +764,6 @@
767 764 cmp_connection_destroy(&fwspk->connection);
768 765 err_unit:
769 766 fw_unit_put(fwspk->unit);
770   - fw_device_put(fw_dev);
771 767 mutex_destroy(&fwspk->mutex);
772 768 error:
773 769 snd_card_free(card);