Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1945503ima; Thu, 25 Oct 2018 07:23:31 -0700 (PDT) X-Google-Smtp-Source: AJdET5fgaWOo2I1QwrkBAnJVbHt/VJNwAIU3H+AI2ZnVgyVTBflzTriyMQtNnxJ8aEF81g0T0l83 X-Received: by 2002:a17:902:6113:: with SMTP id t19-v6mr1727478plj.84.1540477411537; Thu, 25 Oct 2018 07:23:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540477411; cv=none; d=google.com; s=arc-20160816; b=ZYi8kWraOhFoPzTWzHsI1Z3SyyAEOyqnGynnJBiKDkAaWB6C4sfBeUjlQKMXqATG6N Mg5GSBnO4v7mlofczd9niiGhcA0KaAXqp43a8pfQ+Ceu+JhFMfmpufMH57PoKRl/TYU/ nzLZteyhCTjzvy0AswblkLi+ooruKtOcxW10DsTcNIvMqXGKanAj8+Yl9ONJqEkFDwYN TsunSj/qkezKAX/8q/ekk33pha5w530zHFNCWO+l17Po35+eBskq0DGK56yLX0+sQw52 fh2W2k6wVpv5r15/twgHtcx9UB+8M/6Y1DN8cA3Piij2j9aj3/PveY0FtkTbV3DfFvik sTWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=NFQitrpTPuFLJw+0hSNlxycACYV5rJ7yO7fTiA1HCOw=; b=Ju5GE1wB1bNQCSdd/1wqk6vR7pD7dHF2sN/rBM6dfnf7D8IUeI+R5FzX3NftT+7+tu 7JPdLpMRdOc6qav0vPL5zURos3M6bBoUbhJSJNmPCEb9pHW8JmgTfchEPsyWT6ANmxd0 W1MHo+BykwMxWw/uiiouQI9HC/Tm0QEStEH+xFnziXB9CmQAIw0uIYuG30iE1tHDNKTG SanW4F27wTQTjVJGEErYda8T4Fl4cWp2GcrqjUHNkQvGTWeJUxPae0U5VCpUx8TTjKnR iWTRFEY4G1WNmkbedXWwglUWRsNkHv1iaFFnmJRT527SXptTRkm2vJYoXtSzPGpXUcTq DWlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ab4ZF2K5; 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 v17-v6si8264314pgh.35.2018.10.25.07.22.22; Thu, 25 Oct 2018 07:23:31 -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=ab4ZF2K5; 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 S1731501AbeJYWyT (ORCPT + 99 others); Thu, 25 Oct 2018 18:54:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:37240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731475AbeJYWyT (ORCPT ); Thu, 25 Oct 2018 18:54:19 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (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 1F26A20870; Thu, 25 Oct 2018 14:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540477281; bh=FyeVp7MmGrrv4SFsqrs2d0Jlnet07RRC5iLw8Z5w97g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ab4ZF2K5MqGJ0IbFa1CrZo7XJuwMNilCa+4P/84+ua2ppk7dT7AzPdlhQU/bLwnDQ hMjpHoJZ7eNEp8Nu9fKur6KLa+UtbOIhVw45ppcrgaUNMVMcGjTJioazGyT3O+qWli g5wfzfr1NuTYcoTPH3otx1XTyQ7MND0Ndw5KHJAw= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alan Stern , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 3.18 95/98] USB: hub: fix up early-exit pathway in hub_activate Date: Thu, 25 Oct 2018 10:18:50 -0400 Message-Id: <20181025141853.214051-95-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141853.214051-1-sashal@kernel.org> References: <20181025141853.214051-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Stern [ 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