diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2011-08-27 12:53:03 -0400 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2012-01-15 12:37:20 -0500 |
commit | 210762268466634ddbfaddb48fdf5181ce4b5f2d (patch) | |
tree | 8c07da360066158aa48f450dfeb593ed9ed76d0f | |
parent | 2ca526bf4953380abfe5dff455e356967b239c70 (diff) |
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>
-rw-r--r-- | drivers/firewire/core-device.c | 2 | ||||
-rw-r--r-- | drivers/firewire/core.h | 13 | ||||
-rw-r--r-- | include/linux/firewire.h | 12 | ||||
-rw-r--r-- | sound/firewire/isight.c | 4 | ||||
-rw-r--r-- | sound/firewire/speakers.c | 4 |
5 files changed, 16 insertions, 19 deletions
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index f3b890da1e87..4c6c7d8cdaf1 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c | |||
@@ -641,6 +641,7 @@ static void fw_unit_release(struct device *dev) | |||
641 | { | 641 | { |
642 | struct fw_unit *unit = fw_unit(dev); | 642 | struct fw_unit *unit = fw_unit(dev); |
643 | 643 | ||
644 | fw_device_put(fw_parent_device(unit)); | ||
644 | kfree(unit); | 645 | kfree(unit); |
645 | } | 646 | } |
646 | 647 | ||
@@ -692,6 +693,7 @@ static void create_units(struct fw_device *device) | |||
692 | if (device_register(&unit->device) < 0) | 693 | if (device_register(&unit->device) < 0) |
693 | goto skip_unit; | 694 | goto skip_unit; |
694 | 695 | ||
696 | fw_device_get(device); | ||
695 | continue; | 697 | continue; |
696 | 698 | ||
697 | skip_unit: | 699 | skip_unit: |
diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index b45be5767529..b5b34952cf16 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _FIREWIRE_CORE_H | 1 | #ifndef _FIREWIRE_CORE_H |
2 | #define _FIREWIRE_CORE_H | 2 | #define _FIREWIRE_CORE_H |
3 | 3 | ||
4 | #include <linux/device.h> | ||
4 | #include <linux/fs.h> | 5 | #include <linux/fs.h> |
5 | #include <linux/list.h> | 6 | #include <linux/list.h> |
6 | #include <linux/idr.h> | 7 | #include <linux/idr.h> |
@@ -141,6 +142,18 @@ extern struct rw_semaphore fw_device_rwsem; | |||
141 | extern struct idr fw_device_idr; | 142 | extern struct idr fw_device_idr; |
142 | extern int fw_cdev_major; | 143 | extern int fw_cdev_major; |
143 | 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 | } | ||
156 | |||
144 | struct fw_device *fw_device_get_by_devt(dev_t devt); | 157 | struct fw_device *fw_device_get_by_devt(dev_t devt); |
145 | int fw_device_set_broadcast_channel(struct device *dev, void *gen); | 158 | int fw_device_set_broadcast_channel(struct device *dev, void *gen); |
146 | void fw_node_event(struct fw_card *card, struct fw_node *node, int event); | 159 | void fw_node_event(struct fw_card *card, struct fw_node *node, int event); |
diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 84ccf8e04fa6..6f1d7385e051 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h | |||
@@ -203,18 +203,6 @@ static inline int fw_device_is_shutdown(struct fw_device *device) | |||
203 | return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN; | 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 | int fw_device_enable_phys_dma(struct fw_device *device); | 206 | int fw_device_enable_phys_dma(struct fw_device *device); |
219 | 207 | ||
220 | /* | 208 | /* |
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c index 440030818db7..412b65f740d9 100644 --- a/sound/firewire/isight.c +++ b/sound/firewire/isight.c | |||
@@ -612,7 +612,6 @@ static void isight_card_free(struct snd_card *card) | |||
612 | 612 | ||
613 | fw_iso_resources_destroy(&isight->resources); | 613 | fw_iso_resources_destroy(&isight->resources); |
614 | fw_unit_put(isight->unit); | 614 | fw_unit_put(isight->unit); |
615 | fw_device_put(isight->device); | ||
616 | mutex_destroy(&isight->mutex); | 615 | mutex_destroy(&isight->mutex); |
617 | } | 616 | } |
618 | 617 | ||
@@ -645,7 +644,7 @@ static int isight_probe(struct device *unit_dev) | |||
645 | isight->card = card; | 644 | isight->card = card; |
646 | mutex_init(&isight->mutex); | 645 | mutex_init(&isight->mutex); |
647 | isight->unit = fw_unit_get(unit); | 646 | isight->unit = fw_unit_get(unit); |
648 | isight->device = fw_device_get(fw_dev); | 647 | isight->device = fw_dev; |
649 | isight->audio_base = get_unit_base(unit); | 648 | isight->audio_base = get_unit_base(unit); |
650 | if (!isight->audio_base) { | 649 | if (!isight->audio_base) { |
651 | dev_err(&unit->device, "audio unit base not found\n"); | 650 | dev_err(&unit->device, "audio unit base not found\n"); |
@@ -682,7 +681,6 @@ static int isight_probe(struct device *unit_dev) | |||
682 | 681 | ||
683 | err_unit: | 682 | err_unit: |
684 | fw_unit_put(isight->unit); | 683 | fw_unit_put(isight->unit); |
685 | fw_device_put(isight->device); | ||
686 | mutex_destroy(&isight->mutex); | 684 | mutex_destroy(&isight->mutex); |
687 | error: | 685 | error: |
688 | snd_card_free(card); | 686 | snd_card_free(card); |
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c index 3fc257da180c..18b9b5607f3c 100644 --- a/sound/firewire/speakers.c +++ b/sound/firewire/speakers.c | |||
@@ -656,12 +656,10 @@ static u32 fwspk_read_firmware_version(struct fw_unit *unit) | |||
656 | static void fwspk_card_free(struct snd_card *card) | 656 | static void fwspk_card_free(struct snd_card *card) |
657 | { | 657 | { |
658 | struct fwspk *fwspk = card->private_data; | 658 | struct fwspk *fwspk = card->private_data; |
659 | struct fw_device *dev = fw_parent_device(fwspk->unit); | ||
660 | 659 | ||
661 | amdtp_out_stream_destroy(&fwspk->stream); | 660 | amdtp_out_stream_destroy(&fwspk->stream); |
662 | cmp_connection_destroy(&fwspk->connection); | 661 | cmp_connection_destroy(&fwspk->connection); |
663 | fw_unit_put(fwspk->unit); | 662 | fw_unit_put(fwspk->unit); |
664 | fw_device_put(dev); | ||
665 | mutex_destroy(&fwspk->mutex); | 663 | mutex_destroy(&fwspk->mutex); |
666 | } | 664 | } |
667 | 665 | ||
@@ -718,7 +716,6 @@ static int __devinit fwspk_probe(struct device *unit_dev) | |||
718 | fwspk = card->private_data; | 716 | fwspk = card->private_data; |
719 | fwspk->card = card; | 717 | fwspk->card = card; |
720 | mutex_init(&fwspk->mutex); | 718 | mutex_init(&fwspk->mutex); |
721 | fw_device_get(fw_dev); | ||
722 | fwspk->unit = fw_unit_get(unit); | 719 | fwspk->unit = fw_unit_get(unit); |
723 | fwspk->device_info = fwspk_detect(fw_dev); | 720 | fwspk->device_info = fwspk_detect(fw_dev); |
724 | if (!fwspk->device_info) { | 721 | if (!fwspk->device_info) { |
@@ -767,7 +764,6 @@ err_connection: | |||
767 | cmp_connection_destroy(&fwspk->connection); | 764 | cmp_connection_destroy(&fwspk->connection); |
768 | err_unit: | 765 | err_unit: |
769 | fw_unit_put(fwspk->unit); | 766 | fw_unit_put(fwspk->unit); |
770 | fw_device_put(fw_dev); | ||
771 | mutex_destroy(&fwspk->mutex); | 767 | mutex_destroy(&fwspk->mutex); |
772 | error: | 768 | error: |
773 | snd_card_free(card); | 769 | snd_card_free(card); |