Commit 8d66db50 authored by Elena Reshetova's avatar Elena Reshetova Committed by Greg Kroah-Hartman

drivers, usb: convert ep_data.count from atomic_t to refcount_t

refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.
Signed-off-by: default avatarElena Reshetova <elena.reshetova@intel.com>
Signed-off-by: default avatarHans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid Windsor <dwindsor@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b7ddc981
...@@ -191,7 +191,7 @@ enum ep_state { ...@@ -191,7 +191,7 @@ enum ep_state {
struct ep_data { struct ep_data {
struct mutex lock; struct mutex lock;
enum ep_state state; enum ep_state state;
atomic_t count; refcount_t count;
struct dev_data *dev; struct dev_data *dev;
/* must hold dev->lock before accessing ep or req */ /* must hold dev->lock before accessing ep or req */
struct usb_ep *ep; struct usb_ep *ep;
...@@ -206,12 +206,12 @@ struct ep_data { ...@@ -206,12 +206,12 @@ struct ep_data {
static inline void get_ep (struct ep_data *data) static inline void get_ep (struct ep_data *data)
{ {
atomic_inc (&data->count); refcount_inc (&data->count);
} }
static void put_ep (struct ep_data *data) static void put_ep (struct ep_data *data)
{ {
if (likely (!atomic_dec_and_test (&data->count))) if (likely (!refcount_dec_and_test (&data->count)))
return; return;
put_dev (data->dev); put_dev (data->dev);
/* needs no more cleanup */ /* needs no more cleanup */
...@@ -1562,7 +1562,7 @@ static int activate_ep_files (struct dev_data *dev) ...@@ -1562,7 +1562,7 @@ static int activate_ep_files (struct dev_data *dev)
init_waitqueue_head (&data->wait); init_waitqueue_head (&data->wait);
strncpy (data->name, ep->name, sizeof (data->name) - 1); strncpy (data->name, ep->name, sizeof (data->name) - 1);
atomic_set (&data->count, 1); refcount_set (&data->count, 1);
data->dev = dev; data->dev = dev;
get_dev (dev); get_dev (dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment