Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3103657ybi; Thu, 18 Jul 2019 21:05:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqza/uxgt7ie3n2TH0H3/9PrOID+JIy8EpYYi+vN15GfQ6Mv9lBXP112NwM2D6FaCBamNgty X-Received: by 2002:a17:90a:cb12:: with SMTP id z18mr52796080pjt.82.1563509157871; Thu, 18 Jul 2019 21:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509157; cv=none; d=google.com; s=arc-20160816; b=dyjHHcrMohK66ham3mllmIF/4U+e7V6o5NJ7/Eb7M3iw5CuWFj6MkaoEGq/gsql3VM UyNGDAlLytbzlpcsW/vZC1AM1sxn6SImKBa4th3/DFKY7P7jmpL6HYUeAk8l67gfX4fo SKFbEeELM2yH4ce8W0BjXgW5zBYzULZqHO+hrGZjPkVs5NLjx9W55a/oMhopXs4qnQdq LH4ByMdT1k/I8J4Z/v3VZVWniTPr8jPTJgTsnDUJVnUKqwwG/w0GFpY0IHhZ7OSRgZtu vcMlX9TFGthbJaCyHT63iGosJga38np1HWzu5Zgg7L7/1ySPIixSgC/PIacmcS0qVDrT yoWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O8k3bXqMrfJ5kgWI/lc4DU3GAnE6NeZRODeGOKaoQ0s=; b=cBYQNWcp9SMfyT5vR9pgAMmVMh36GOSw4bJisRFctzVcz7oQzE2+mGsLmAAJncf0td LbNbDIsXF7ezghoLwOufp+7aZ/xeybR065fWDOtuGDWMYmvEQZJc0ZxlTH6fN94qgbqi XtDwgjSIE3KmBat0Kf9lVRT2afIVjJaVAEUPJ8N0ucqKU3etwLa/AR/vO3ncfrkqzVZv c28hIt2LqWzASEBaoOSY4b4ATWjz4qrP94j0MUHc30v6IkC/kd6AhyJS5GahysVeRiiq 7DbWuVr/vppWuRUZ3qVnlC9oeWkbf4h2igQ0IKAUB/VEVsWJD0vtlqIfUwyrwAhq2EQ9 h5kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VXxZE2wf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si554236pls.183.2019.07.18.21.05.42; Thu, 18 Jul 2019 21:05:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VXxZE2wf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731210AbfGSEEp (ORCPT + 99 others); Fri, 19 Jul 2019 00:04:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:36892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbfGSEEg (ORCPT ); Fri, 19 Jul 2019 00:04:36 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D665721852; Fri, 19 Jul 2019 04:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509075; bh=qceo+/TEZVRgGCiRPA/chu92E1luGtQgGGimokaAYQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXxZE2wf3D9qECqHEL9/VzA1m2PVZf/PehME29z8XV9czUk9XGzlJxYl+amQ8Pu08 87uiR5Z4WaJgo2bLL38LO7ihCjGMoV3w+oL1yxFNjlRrLuGfd3XUK62v/aEWdQyI7a 8Nyfl7fNPMFzT2O41mNpkFROVkazuxyK0ccWP1eY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: EJ Hsu , Alan Stern , Felipe Balbi , Sasha Levin , linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 5.1 054/141] usb: gadget: storage: Remove warning message Date: Fri, 19 Jul 2019 00:01:19 -0400 Message-Id: <20190719040246.15945-54-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719040246.15945-1-sashal@kernel.org> References: <20190719040246.15945-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: EJ Hsu [ Upstream commit e70b3f5da00119e057b7faa557753fee7f786f17 ] This change is to fix below warning message in following scenario: usb_composite_setup_continue: Unexpected call When system tried to enter suspend, the fsg_disable() will be called to disable fsg driver and send a signal to fsg_main_thread. However, at this point, the fsg_main_thread has already been frozen and can not respond to this signal. So, this signal will be pended until fsg_main_thread wakes up. Once system resumes from suspend, fsg_main_thread will detect a signal pended and do some corresponding action (in handle_exception()). Then, host will send some setup requests (get descriptor, set configuration...) to UDC driver trying to enumerate this device. During the handling of "set configuration" request, it will try to sync up with fsg_main_thread by sending a signal (which is the same as the signal sent by fsg_disable) to it. In a similar manner, once the fsg_main_thread receives this signal, it will call handle_exception() to handle the request. However, if the fsg_main_thread wakes up from suspend a little late and "set configuration" request from Host arrives a little earlier, fsg_main_thread might come across the request from "set configuration" when it handles the signal from fsg_disable(). In this case, it will handle this request as well. So, when fsg_main_thread tries to handle the signal sent from "set configuration" later, there will nothing left to do and warning message "Unexpected call" is printed. Acked-by: Alan Stern Signed-off-by: EJ Hsu Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/f_mass_storage.c | 21 ++++++++++++++------ drivers/usb/gadget/function/storage_common.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 043f97ad8f22..982c3e89eb0d 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -2293,8 +2293,7 @@ static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) static void fsg_disable(struct usb_function *f) { struct fsg_dev *fsg = fsg_from_func(f); - fsg->common->new_fsg = NULL; - raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); + raise_exception(fsg->common, FSG_STATE_DISCONNECT); } @@ -2307,6 +2306,7 @@ static void handle_exception(struct fsg_common *common) enum fsg_state old_state; struct fsg_lun *curlun; unsigned int exception_req_tag; + struct fsg_dev *fsg; /* * Clear the existing signals. Anything but SIGUSR1 is converted @@ -2413,9 +2413,19 @@ static void handle_exception(struct fsg_common *common) break; case FSG_STATE_CONFIG_CHANGE: - do_set_interface(common, common->new_fsg); - if (common->new_fsg) + fsg = common->new_fsg; + /* + * Add a check here to double confirm if a disconnect event + * occurs and common->new_fsg has been cleared. + */ + if (fsg) { + do_set_interface(common, fsg); usb_composite_setup_continue(common->cdev); + } + break; + + case FSG_STATE_DISCONNECT: + do_set_interface(common, NULL); break; case FSG_STATE_EXIT: @@ -2989,8 +2999,7 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) DBG(fsg, "unbind\n"); if (fsg->common->fsg == fsg) { - fsg->common->new_fsg = NULL; - raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); + raise_exception(fsg->common, FSG_STATE_DISCONNECT); /* FIXME: make interruptible or killable somehow? */ wait_event(common->fsg_wait, common->fsg != fsg); } diff --git a/drivers/usb/gadget/function/storage_common.h b/drivers/usb/gadget/function/storage_common.h index e5e3a2553aaa..12687f7e3de9 100644 --- a/drivers/usb/gadget/function/storage_common.h +++ b/drivers/usb/gadget/function/storage_common.h @@ -161,6 +161,7 @@ enum fsg_state { FSG_STATE_ABORT_BULK_OUT, FSG_STATE_PROTOCOL_RESET, FSG_STATE_CONFIG_CHANGE, + FSG_STATE_DISCONNECT, FSG_STATE_EXIT, FSG_STATE_TERMINATED }; -- 2.20.1