Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 309395
b: refs/heads/master
c: 54e2dc9
h: refs/heads/master
i:
  309393: 4d0af99
  309391: 0b964b9
v: v3
  • Loading branch information
Hans de Goede authored and Wim Van Sebroeck committed May 30, 2012
1 parent 3e44b13 commit 408a652
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 85a2e40cb5053574cd3b1f33c00194309ce3704c
refs/heads/master: 54e2dc9341aca23d5241699e3b74c8dce609fa2d
30 changes: 29 additions & 1 deletion trunk/drivers/hwmon/sch56xx-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
struct sch56xx_watchdog_data {
u16 addr;
struct mutex *io_lock;
struct kref kref;
struct watchdog_info wdinfo;
struct watchdog_device wddev;
u8 watchdog_preset;
Expand Down Expand Up @@ -257,6 +258,15 @@ EXPORT_SYMBOL(sch56xx_read_virtual_reg12);
* Watchdog routines
*/

/* Release our data struct when we're unregistered *and*
all references to our watchdog device are released */
static void watchdog_release_resources(struct kref *r)
{
struct sch56xx_watchdog_data *data =
container_of(r, struct sch56xx_watchdog_data, kref);
kfree(data);
}

static int watchdog_set_timeout(struct watchdog_device *wddev,
unsigned int timeout)
{
Expand Down Expand Up @@ -385,12 +395,28 @@ static int watchdog_stop(struct watchdog_device *wddev)
return 0;
}

static void watchdog_ref(struct watchdog_device *wddev)
{
struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev);

kref_get(&data->kref);
}

static void watchdog_unref(struct watchdog_device *wddev)
{
struct sch56xx_watchdog_data *data = watchdog_get_drvdata(wddev);

kref_put(&data->kref, watchdog_release_resources);
}

static const struct watchdog_ops watchdog_ops = {
.owner = THIS_MODULE,
.start = watchdog_start,
.stop = watchdog_stop,
.ping = watchdog_trigger,
.set_timeout = watchdog_set_timeout,
.ref = watchdog_ref,
.unref = watchdog_unref,
};

struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,
Expand Down Expand Up @@ -422,6 +448,7 @@ struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,

data->addr = addr;
data->io_lock = io_lock;
kref_init(&data->kref);

strlcpy(data->wdinfo.identity, "sch56xx watchdog",
sizeof(data->wdinfo.identity));
Expand Down Expand Up @@ -467,7 +494,8 @@ EXPORT_SYMBOL(sch56xx_watchdog_register);
void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data)
{
watchdog_unregister_device(&data->wddev);
kfree(data);
kref_put(&data->kref, watchdog_release_resources);
/* Don't touch data after this it may have been free-ed! */
}
EXPORT_SYMBOL(sch56xx_watchdog_unregister);

Expand Down

0 comments on commit 408a652

Please sign in to comment.