Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35920526 authored by Liangliang Lu's avatar Liangliang Lu Committed by Mayank Rana
Browse files

usb: gadget: f_diag: allocate diag USB channel when not found



Currently usb function instance driver depends on diag char driver to
create the channel (using usb_diag_open api). Failing to create channel
can result in enumeration failure. Avoid this dependency by creating
diag channel from function instance if not available. Same channel
will be reused when diag char driver creates/opens the channel.

Change-Id: I11debd0189d81542762af22b3d203728d2266a42
Signed-off-by: default avatarLiangliang Lu <luliang@codeaurora.org>
parent 84a47e8c
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -386,9 +386,11 @@ struct usb_diag_ch *usb_diag_open(const char *name, void *priv,
	ch->priv = priv;
	ch->notify = notify;

	if (!found) {
		spin_lock_irqsave(&ch_lock, flags);
		list_add_tail(&ch->list, &usb_diag_ch_list);
		spin_unlock_irqrestore(&ch_lock, flags);
	}

	return ch;
}
@@ -863,6 +865,7 @@ static struct diag_context *diag_context_init(const char *name)
	struct diag_context *dev;
	struct usb_diag_ch *_ch;
	int found = 0;
	unsigned long flags;

	pr_debug("%s\n", __func__);

@@ -872,9 +875,19 @@ static struct diag_context *diag_context_init(const char *name)
			break;
		}
	}

	if (!found) {
		pr_err("%s: unable to get diag usb channel\n", __func__);
		return ERR_PTR(-ENODEV);
		pr_warn("%s: unable to get diag usb channel\n", __func__);

		_ch = kzalloc(sizeof(*_ch), GFP_KERNEL);
		if (_ch == NULL)
			return ERR_PTR(-ENOMEM);

		_ch->name = name;

		spin_lock_irqsave(&ch_lock, flags);
		list_add_tail(&_ch->list, &usb_diag_ch_list);
		spin_unlock_irqrestore(&ch_lock, flags);
	}

	dev = kzalloc(sizeof(*dev), GFP_KERNEL);