Skip to content

Commit

Permalink
firewire: move fw_device reference counting from drivers to core
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Stefan Richter committed Jan 15, 2012
1 parent 2ca526b commit 2107622
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
2 changes: 2 additions & 0 deletions drivers/firewire/core-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ static void fw_unit_release(struct device *dev)
{
struct fw_unit *unit = fw_unit(dev);

fw_device_put(fw_parent_device(unit));
kfree(unit);
}

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

fw_device_get(device);
continue;

skip_unit:
Expand Down
13 changes: 13 additions & 0 deletions drivers/firewire/core.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _FIREWIRE_CORE_H
#define _FIREWIRE_CORE_H

#include <linux/device.h>
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/idr.h>
Expand Down Expand Up @@ -141,6 +142,18 @@ extern struct rw_semaphore fw_device_rwsem;
extern struct idr fw_device_idr;
extern int fw_cdev_major;

static inline struct fw_device *fw_device_get(struct fw_device *device)
{
get_device(&device->device);

return device;
}

static inline void fw_device_put(struct fw_device *device)
{
put_device(&device->device);
}

struct fw_device *fw_device_get_by_devt(dev_t devt);
int fw_device_set_broadcast_channel(struct device *dev, void *gen);
void fw_node_event(struct fw_card *card, struct fw_node *node, int event);
Expand Down
12 changes: 0 additions & 12 deletions include/linux/firewire.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,6 @@ static inline int fw_device_is_shutdown(struct fw_device *device)
return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
}

static inline struct fw_device *fw_device_get(struct fw_device *device)
{
get_device(&device->device);

return device;
}

static inline void fw_device_put(struct fw_device *device)
{
put_device(&device->device);
}

int fw_device_enable_phys_dma(struct fw_device *device);

/*
Expand Down
4 changes: 1 addition & 3 deletions sound/firewire/isight.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ static void isight_card_free(struct snd_card *card)

fw_iso_resources_destroy(&isight->resources);
fw_unit_put(isight->unit);
fw_device_put(isight->device);
mutex_destroy(&isight->mutex);
}

Expand Down Expand Up @@ -645,7 +644,7 @@ static int isight_probe(struct device *unit_dev)
isight->card = card;
mutex_init(&isight->mutex);
isight->unit = fw_unit_get(unit);
isight->device = fw_device_get(fw_dev);
isight->device = fw_dev;
isight->audio_base = get_unit_base(unit);
if (!isight->audio_base) {
dev_err(&unit->device, "audio unit base not found\n");
Expand Down Expand Up @@ -682,7 +681,6 @@ static int isight_probe(struct device *unit_dev)

err_unit:
fw_unit_put(isight->unit);
fw_device_put(isight->device);
mutex_destroy(&isight->mutex);
error:
snd_card_free(card);
Expand Down
4 changes: 0 additions & 4 deletions sound/firewire/speakers.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,10 @@ static u32 fwspk_read_firmware_version(struct fw_unit *unit)
static void fwspk_card_free(struct snd_card *card)
{
struct fwspk *fwspk = card->private_data;
struct fw_device *dev = fw_parent_device(fwspk->unit);

amdtp_out_stream_destroy(&fwspk->stream);
cmp_connection_destroy(&fwspk->connection);
fw_unit_put(fwspk->unit);
fw_device_put(dev);
mutex_destroy(&fwspk->mutex);
}

Expand Down Expand Up @@ -718,7 +716,6 @@ static int __devinit fwspk_probe(struct device *unit_dev)
fwspk = card->private_data;
fwspk->card = card;
mutex_init(&fwspk->mutex);
fw_device_get(fw_dev);
fwspk->unit = fw_unit_get(unit);
fwspk->device_info = fwspk_detect(fw_dev);
if (!fwspk->device_info) {
Expand Down Expand Up @@ -767,7 +764,6 @@ static int __devinit fwspk_probe(struct device *unit_dev)
cmp_connection_destroy(&fwspk->connection);
err_unit:
fw_unit_put(fwspk->unit);
fw_device_put(fw_dev);
mutex_destroy(&fwspk->mutex);
error:
snd_card_free(card);
Expand Down

0 comments on commit 2107622

Please sign in to comment.