Skip to content

Commit 2107622

Browse files
author
Stefan Richter
committed
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>
1 parent 2ca526b commit 2107622

5 files changed

Lines changed: 16 additions & 19 deletions

File tree

‎drivers/firewire/core-device.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ static void fw_unit_release(struct device *dev)
641641
{
642642
struct fw_unit *unit = fw_unit(dev);
643643

644+
fw_device_put(fw_parent_device(unit));
644645
kfree(unit);
645646
}
646647

@@ -692,6 +693,7 @@ static void create_units(struct fw_device *device)
692693
if (device_register(&unit->device) < 0)
693694
goto skip_unit;
694695

696+
fw_device_get(device);
695697
continue;
696698

697699
skip_unit:

‎drivers/firewire/core.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _FIREWIRE_CORE_H
22
#define _FIREWIRE_CORE_H
33

4+
#include <linux/device.h>
45
#include <linux/fs.h>
56
#include <linux/list.h>
67
#include <linux/idr.h>
@@ -141,6 +142,18 @@ extern struct rw_semaphore fw_device_rwsem;
141142
extern struct idr fw_device_idr;
142143
extern int fw_cdev_major;
143144

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+
144157
struct fw_device *fw_device_get_by_devt(dev_t devt);
145158
int fw_device_set_broadcast_channel(struct device *dev, void *gen);
146159
void fw_node_event(struct fw_card *card, struct fw_node *node, int event);

‎include/linux/firewire.h‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,6 @@ static inline int fw_device_is_shutdown(struct fw_device *device)
203203
return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
204204
}
205205

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-
218206
int fw_device_enable_phys_dma(struct fw_device *device);
219207

220208
/*

‎sound/firewire/isight.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ static void isight_card_free(struct snd_card *card)
612612

613613
fw_iso_resources_destroy(&isight->resources);
614614
fw_unit_put(isight->unit);
615-
fw_device_put(isight->device);
616615
mutex_destroy(&isight->mutex);
617616
}
618617

@@ -645,7 +644,7 @@ static int isight_probe(struct device *unit_dev)
645644
isight->card = card;
646645
mutex_init(&isight->mutex);
647646
isight->unit = fw_unit_get(unit);
648-
isight->device = fw_device_get(fw_dev);
647+
isight->device = fw_dev;
649648
isight->audio_base = get_unit_base(unit);
650649
if (!isight->audio_base) {
651650
dev_err(&unit->device, "audio unit base not found\n");
@@ -682,7 +681,6 @@ static int isight_probe(struct device *unit_dev)
682681

683682
err_unit:
684683
fw_unit_put(isight->unit);
685-
fw_device_put(isight->device);
686684
mutex_destroy(&isight->mutex);
687685
error:
688686
snd_card_free(card);

‎sound/firewire/speakers.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,10 @@ static u32 fwspk_read_firmware_version(struct fw_unit *unit)
656656
static void fwspk_card_free(struct snd_card *card)
657657
{
658658
struct fwspk *fwspk = card->private_data;
659-
struct fw_device *dev = fw_parent_device(fwspk->unit);
660659

661660
amdtp_out_stream_destroy(&fwspk->stream);
662661
cmp_connection_destroy(&fwspk->connection);
663662
fw_unit_put(fwspk->unit);
664-
fw_device_put(dev);
665663
mutex_destroy(&fwspk->mutex);
666664
}
667665

@@ -718,7 +716,6 @@ static int __devinit fwspk_probe(struct device *unit_dev)
718716
fwspk = card->private_data;
719717
fwspk->card = card;
720718
mutex_init(&fwspk->mutex);
721-
fw_device_get(fw_dev);
722719
fwspk->unit = fw_unit_get(unit);
723720
fwspk->device_info = fwspk_detect(fw_dev);
724721
if (!fwspk->device_info) {
@@ -767,7 +764,6 @@ static int __devinit fwspk_probe(struct device *unit_dev)
767764
cmp_connection_destroy(&fwspk->connection);
768765
err_unit:
769766
fw_unit_put(fwspk->unit);
770-
fw_device_put(fw_dev);
771767
mutex_destroy(&fwspk->mutex);
772768
error:
773769
snd_card_free(card);

0 commit comments

Comments
 (0)