Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp16014imu; Thu, 8 Nov 2018 13:59:22 -0800 (PST) X-Google-Smtp-Source: AJdET5c07vRe24YGIT1SVFae9t+l6wdsmeyapL9GEcIoTfogIUPsdNH+HSY6vGKEIPl/nQeOlwMg X-Received: by 2002:a17:902:9a47:: with SMTP id x7-v6mr6269367plv.316.1541714362092; Thu, 08 Nov 2018 13:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541714362; cv=none; d=google.com; s=arc-20160816; b=dHzX0BVJW4uas/DvllNEU8ELG2/K3exzZi62DYDYkssyQ1DSuQBLuwmOtTRWTxWwS0 DMEiWW+JPchPn/kE9r3VMiEkWF+JTRtxJcAdDxV8ZjAn/nKsktl1fWJWBXYH37BW2KDa r95refKeDRnWAT35dd5Ziun2fjnlmqlORJWxyD4NioOiI+wpufRkKq6/fad+/odDxw1L UJacOQbEu07yt0DEI5micHG97mpqk1GvAAalLNEH88I+KCBDkbHTMrYsF3uWX43rsyZg Nag8yeULvv5LSSaIQfQ6UuLdsxXj5mQDE2v7bdM6U24yd+7XHiQhNxVYIoybGnIpA6Sx OE0A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KMBo19OIBZJCB836xT12e9hS6WB5rJVG778v7EI2WSE=; b=dE0LQYdfG2d7BXeH4KMNLWevzNIlkk9R4ysGMeNWurSInv80t4BXvB3Cb9onLjMbVF JU6GjBdgrdBMgZUVqXnHyp7IJsZQ0X8QIW9uV1c1UDO5vRNH2fwz7wKLc03hTXCqdQM/ EvqVHt3YKmkuXAJRfPCJBt/7EyAxBU17swLWHLA3wiWW/XKBawILsxZKB+wNpjBFjerz yetpmXcgYghhP35OVnOC51M9XpZqpoHlIdDp6q6Wx6gxz3tvsWGX1e2oWD2pEDLLLSDh 2FRomikK5GGSYT/QjpQyuEh019rq1VIO8oG0A7IX7iIwf9oPSucYTalIDtFg8nORbx/S kPdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uObEspJ3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18-v6si5885716pfa.3.2018.11.08.13.59.06; Thu, 08 Nov 2018 13:59:22 -0800 (PST) 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=uObEspJ3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729602AbeKIHf0 (ORCPT + 99 others); Fri, 9 Nov 2018 02:35:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:52232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728104AbeKIHfY (ORCPT ); Fri, 9 Nov 2018 02:35:24 -0500 Received: from localhost (unknown [208.72.13.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 091EA208E3; Thu, 8 Nov 2018 21:57:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714276; bh=xKiBVGU9ctkN3ddwrSl/+hEQwX0yWiijSqzPl94auqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uObEspJ31ldWsOYUc7ucz17oFNZIZ5pV8rtU8Q/E57cc37xfxs4ScHxv0NxP3J053 0Oo528wxJ81moIfxNIQIQfpGwyGZUcYpEobJs+J8nxdLutdJiYigxeXYsyL5mexucI SMcGorS9gmWRdYHgNV9KWiEUnNnG2FAbSyXp6IgU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Viresh Kumar , Sasha Levin Subject: [PATCH 3.18 123/144] USB: hub: fix up early-exit pathway in hub_activate Date: Thu, 8 Nov 2018 13:51:34 -0800 Message-Id: <20181108215106.965493025@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215054.826084593@linuxfoundation.org> References: <20181108215054.826084593@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit ca5cbc8b02f9b21cc8cd1ab36668763ec34f9ee8 ] The early-exit pathway in hub_activate, added by commit e50293ef9775 ("USB: fix invalid memory access in hub_activate()") needs improvement. It duplicates code that is already present at the end of the subroutine, and it neglects to undo the effect of a usb_autopm_get_interface_no_resume() call. This patch fixes both problems by making the early-exit pathway jump directly to the end of the subroutine. It simplifies the code at the end by merging two conditionals that actually test the same condition although they appear different: If type < HUB_INIT3 then type must be either HUB_INIT2 or HUB_INIT, and it can't be HUB_INIT because in that case the subroutine would have exited earlier. Signed-off-by: Alan Stern CC: #4.4+ Reviewed-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/core/hub.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 164fdeddfc05..9a47a9c8ebb4 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -1000,11 +1000,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) device_lock(hub->intfdev); /* Was the hub disconnected while we were waiting? */ - if (hub->disconnected) { - device_unlock(hub->intfdev); - kref_put(&hub->kref, hub_release); - return; - } + if (hub->disconnected) + goto disconnected; if (type == HUB_INIT2) goto init2; goto init3; @@ -1230,12 +1227,12 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) /* Scan all ports that need attention */ kick_hub_wq(hub); - /* Allow autosuspend if it was suppressed */ - if (type <= HUB_INIT3) + if (type == HUB_INIT2 || type == HUB_INIT3) { + /* Allow autosuspend if it was suppressed */ + disconnected: usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); - - if (type == HUB_INIT2 || type == HUB_INIT3) device_unlock(hub->intfdev); + } kref_put(&hub->kref, hub_release); } -- 2.17.1