Skip to content

Commit

Permalink
uwb: fix device reference leaks
Browse files Browse the repository at this point in the history
This subsystem consistently fails to drop the device reference taken by
class_find_device().

Note that some of these lookup functions already take a reference to the
returned data, while others claim no reference is needed (or does not
seem need one).

Fixes: 183b9b5 ("uwb: add the UWB stack (core files)")
Signed-off-by: Johan Hovold <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
jhovold authored and gregkh committed Nov 1, 2016
1 parent afe4155 commit d6124b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions drivers/uwb/lc-rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ static struct uwb_rc *uwb_rc_find_by_index(int index)
struct uwb_rc *rc = NULL;

dev = class_find_device(&uwb_rc_class, NULL, &index, uwb_rc_index_match);
if (dev)
if (dev) {
rc = dev_get_drvdata(dev);
put_device(dev);
}

return rc;
}

Expand Down Expand Up @@ -467,7 +470,9 @@ struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *target_rc)
if (dev) {
rc = dev_get_drvdata(dev);
__uwb_rc_get(rc);
put_device(dev);
}

return rc;
}
EXPORT_SYMBOL_GPL(__uwb_rc_try_get);
Expand Down Expand Up @@ -520,8 +525,11 @@ struct uwb_rc *uwb_rc_get_by_grandpa(const struct device *grandpa_dev)

dev = class_find_device(&uwb_rc_class, NULL, grandpa_dev,
find_rc_grandpa);
if (dev)
if (dev) {
rc = dev_get_drvdata(dev);
put_device(dev);
}

return rc;
}
EXPORT_SYMBOL_GPL(uwb_rc_get_by_grandpa);
Expand Down Expand Up @@ -553,8 +561,10 @@ struct uwb_rc *uwb_rc_get_by_dev(const struct uwb_dev_addr *addr)
struct uwb_rc *rc = NULL;

dev = class_find_device(&uwb_rc_class, NULL, addr, find_rc_dev);
if (dev)
if (dev) {
rc = dev_get_drvdata(dev);
put_device(dev);
}

return rc;
}
Expand Down
2 changes: 2 additions & 0 deletions drivers/uwb/pal.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ static bool uwb_rc_class_device_exists(struct uwb_rc *target_rc)

dev = class_find_device(&uwb_rc_class, NULL, target_rc, find_rc);

put_device(dev);

return (dev != NULL);
}

Expand Down

0 comments on commit d6124b4

Please sign in to comment.