Revert "HID: fix HID device resource race between HID core and debugging support"

This reverts commit 377c4c7e97 which is
commit fc43e9c857b7aa55efba9398419b14d9e35dcc7d upstream.

It breaks the Android kernel abi and can be brought back in the future
in an abi-safe way if it is really needed.

Bug: 161946584
Change-Id: I80bbce6f594ca4dd9b58d58598d4191112ea095f
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
Greg Kroah-Hartman 2023-12-19 10:56:26 +00:00
parent ee16988743
commit 1775bee186
3 changed files with 3 additions and 17 deletions

View File

@ -708,20 +708,13 @@ static void hid_close_report(struct hid_device *device)
* Free a device structure, all reports, and all fields. * Free a device structure, all reports, and all fields.
*/ */
void hiddev_free(struct kref *ref)
{
struct hid_device *hid = container_of(ref, struct hid_device, ref);
hid_close_report(hid);
kfree(hid->dev_rdesc);
kfree(hid);
}
static void hid_device_release(struct device *dev) static void hid_device_release(struct device *dev)
{ {
struct hid_device *hid = to_hid_device(dev); struct hid_device *hid = to_hid_device(dev);
kref_put(&hid->ref, hiddev_free); hid_close_report(hid);
kfree(hid->dev_rdesc);
kfree(hid);
} }
/* /*
@ -2821,7 +2814,6 @@ struct hid_device *hid_allocate_device(void)
spin_lock_init(&hdev->debug_list_lock); spin_lock_init(&hdev->debug_list_lock);
sema_init(&hdev->driver_input_lock, 1); sema_init(&hdev->driver_input_lock, 1);
mutex_init(&hdev->ll_open_lock); mutex_init(&hdev->ll_open_lock);
kref_init(&hdev->ref);
return hdev; return hdev;
} }

View File

@ -1132,7 +1132,6 @@ static int hid_debug_events_open(struct inode *inode, struct file *file)
goto out; goto out;
} }
list->hdev = (struct hid_device *) inode->i_private; list->hdev = (struct hid_device *) inode->i_private;
kref_get(&list->hdev->ref);
file->private_data = list; file->private_data = list;
mutex_init(&list->read_mutex); mutex_init(&list->read_mutex);
@ -1225,8 +1224,6 @@ static int hid_debug_events_release(struct inode *inode, struct file *file)
list_del(&list->node); list_del(&list->node);
spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags); spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
kfifo_free(&list->hid_debug_fifo); kfifo_free(&list->hid_debug_fifo);
kref_put(&list->hdev->ref, hiddev_free);
kfree(list); kfree(list);
return 0; return 0;

View File

@ -656,7 +656,6 @@ struct hid_device { /* device report descriptor */
struct list_head debug_list; struct list_head debug_list;
spinlock_t debug_list_lock; spinlock_t debug_list_lock;
wait_queue_head_t debug_wait; wait_queue_head_t debug_wait;
struct kref ref;
unsigned int id; /* system unique id */ unsigned int id; /* system unique id */
@ -664,8 +663,6 @@ struct hid_device { /* device report descriptor */
ANDROID_KABI_RESERVE(2); ANDROID_KABI_RESERVE(2);
}; };
void hiddev_free(struct kref *ref);
#define to_hid_device(pdev) \ #define to_hid_device(pdev) \
container_of(pdev, struct hid_device, dev) container_of(pdev, struct hid_device, dev)