usb: ks_bridge: Free up stale buffers in probe

Driver can add data buffer to the link list of rx/tx
buffers after emptying the list during disconnect.
These stale buffers can confuse efs sync server when
mdm device connects back. Hence free up the rx/tx
buffers again during probe. Avoid further addition of
tx buffers after disconnect by checking device
connection status in write API. Also, move
misc_deregister() after cancelling the work in order
to remove device node early during disconnect to avoid
any write call further.

(cherry picked from commit 2f20bda7837d6f9a172b433af72a02f907b2ed2f)

Conflicts:

	drivers/usb/misc/ks_bridge.c

CRs-Fixed: 448142
Change-Id: Ifff58d2adc113257809eb80b7f91c1a0f4a0adeb
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
This commit is contained in:
Hemant Kumar 2012-09-17 14:05:54 -07:00 committed by Iliyan Malchev
parent 29603b118d
commit 15f0a12934

View file

@ -317,6 +317,8 @@ static ssize_t ksb_fs_write(struct file *fp, const char __user *buf,
unsigned long flags;
struct ks_bridge *ksb = fp->private_data;
if (!test_bit(USB_DEV_CONNECTED, &ksb->flags))
return -ENODEV;
if (count > MAX_DATA_PKT_SIZE)
count = MAX_DATA_PKT_SIZE;
@ -589,6 +591,8 @@ ksb_usb_probe(struct usb_interface *ifc, const struct usb_device_id *id)
struct miscdevice *mdev, *fbdev;
struct usb_device *udev;
unsigned int bus_id;
unsigned long flags;
struct data_pkt *pkt;
ifc_num = ifc->cur_altsetting->desc.bInterfaceNumber;
@ -661,6 +665,22 @@ ksb_usb_probe(struct usb_interface *ifc, const struct usb_device_id *id)
dbg_log_event(ksb, "PID-ATT", id->idProduct, 0);
/*free up stale buffers if any from previous disconnect*/
spin_lock_irqsave(&ksb->lock, flags);
while (!list_empty(&ksb->to_ks_list)) {
pkt = list_first_entry(&ksb->to_ks_list,
struct data_pkt, list);
list_del_init(&pkt->list);
ksb_free_data_pkt(pkt);
}
while (!list_empty(&ksb->to_mdm_list)) {
pkt = list_first_entry(&ksb->to_mdm_list,
struct data_pkt, list);
list_del_init(&pkt->list);
ksb_free_data_pkt(pkt);
}
spin_unlock_irqrestore(&ksb->lock, flags);
ksb->fs_dev = *mdev;
misc_register(&ksb->fs_dev);