Loading
usb: gadget: diag: Add reference counting to diag_context
The diag_context structure is allocated and freed each time the
function is bound and unbound. However, since the diag client is
only aware of connect/disconnect status and not whether the function
is bound, there could be a race in which a late usb_diag_read() or
write() is executing when unbind happens and frees the structure.
To prevent this, add a kref object to the diag_context structure
and make sure it is incremented appropriately during the entry to
usb_diag_read/write(). We'll use the kref_put_spinlock_irqsave()
variant to ensure that the lock (which is also part of diag_context)
is taken before executing the final put().
Change-Id: I732a65445f067e1899423397bc33a48a8fb7224d
Signed-off-by:
Jack Pham <jackp@codeaurora.org>