From 091b49d5eab10b5ae30b23536e03df5d2cd6844f Mon Sep 17 00:00:00 2001 From: Liangliang Lu Date: Wed, 3 May 2017 16:06:35 +0800 Subject: [PATCH] usb: gadget: mtp: Move mutex_init() to alloc_inst_mtp_ptp() Now mutex_init() is in function_alloc_mtp_ptp() which will be called when USB composition change. In the corner case, USB composition change when do mtp_read(), the mutex lock is initialized when do mutex_lock(). Change-Id: I7a61f6fe6d8865462c5445f7075722f4f151b03f Signed-off-by: Liangliang Lu --- drivers/usb/gadget/function/f_mtp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_mtp.c b/drivers/usb/gadget/function/f_mtp.c index 4a0b3a0aa65e..7bfeb93f012c 100644 --- a/drivers/usb/gadget/function/f_mtp.c +++ b/drivers/usb/gadget/function/f_mtp.c @@ -1854,6 +1854,8 @@ struct usb_function_instance *alloc_inst_mtp_ptp(bool mtp_config) config_group_init_type_name(&fi_mtp->func_inst.group, "", &mtp_func_type); + mutex_init(&fi_mtp->dev->read_mutex); + return &fi_mtp->func_inst; } EXPORT_SYMBOL_GPL(alloc_inst_mtp_ptp); @@ -1916,7 +1918,6 @@ struct usb_function *function_alloc_mtp_ptp(struct usb_function_instance *fi, dev->is_ptp = !mtp_config; fi->f = &dev->function; - mutex_init(&dev->read_mutex); return &dev->function; } EXPORT_SYMBOL_GPL(function_alloc_mtp_ptp);