Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1020940ybe; Wed, 4 Sep 2019 11:15:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxufB2ntiKUqmlT+ol/VDTdhaywZauGPkO3sscsim/k3yWQDeySSt8QLcQ6ZNMN6WhdTdJQ X-Received: by 2002:a62:3844:: with SMTP id f65mr28317272pfa.142.1567620924179; Wed, 04 Sep 2019 11:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620924; cv=none; d=google.com; s=arc-20160816; b=DX2JsrPrBnTpJJaUVfHfX2Mk/TBOCA3CNZP+qz5ssqKFzXDij8CALa/6C2QLFYwdSr Y6AmRQcbvo6+dZwL37DHdNUyNvOp8c3woiObKV7lv+XK8QGAb2R+yjxmKWZr354QIT/v cbI4yB0MpXpLMkO7MJ3EI6OiqQC527JGkhXsw9dGnUlZFhTnq54ruXpqhSxaBrwFZKvW 1iufndy62M3/LzKcyeY7lOXaSx1QRijo1F0evQzOJBmqZwUQHqsZueGVKSdj9aqkAQpe 4Lgw2rX68V76tffwJjxzAg1AeqSjNfDivAtrlrPSd9zvnLBW9fU+JoH2rFZJbEodN5Dr PNyg== 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=ymu+2+p09T9OqU+/dtTtpLFiiXIxUpDdr90PbxZyi2Q=; b=I655YpSI9BmeFVqAB+lU4MmWOcJqHEe/FgOKRCeec2eaZBCV+meReqsGL7JntLezuT A7CZCS9irGrs4hT4uBJkvIuH0lGLOon4MAbyfBxX7z1A+TFKTuQmyIlq6gUdh0WJHUmH ejt8ButGuIgWUu03C1xApwU8kRgBZitGN1KNFBUmxHzjhu7MjYBZclZcodDWOvvr73Cb WQAiZoKzfg6bGf9o5c7NtMUlUKdea/Fi3x9dyfaJ2F+BRokKPJ6uJLa8HcZt4aWDE2/n pgWOI23taa2Echm/zDdNzKJYzt7gyG6Smj9XOAK9YubLS/7Fk4fOyCS6HUm6wwxgo6W3 7sTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PRXsV58I; 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 i187si21043371pfe.21.2019.09.04.11.15.08; Wed, 04 Sep 2019 11:15:24 -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=PRXsV58I; 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 S2389883AbfIDSMb (ORCPT + 99 others); Wed, 4 Sep 2019 14:12:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:56948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390511AbfIDSMb (ORCPT ); Wed, 4 Sep 2019 14:12:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 A510B2341D; Wed, 4 Sep 2019 18:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620750; bh=YhZYuhnmS9tdig3xXuI3dsas3LT8WuW+r+Q0IcMXP2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PRXsV58I6UZ63X59QLT0TwYXq5XrTRUJhKtYVdLVkKJMauXe/NmGqGxeKioJfJZlZ F7FyzqBEbPEsF0sNYYopMRWZJ5GZeX83NvRo/v5043op4Fy0BPCI6psKJNWsFHMo/J /hIjA2juLDbm+J5F5pvDCLZjPZv5NrA/4i8JErI0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Carsten Schmid , Mathias Nyman Subject: [PATCH 5.2 081/143] usb: hcd: use managed device resources Date: Wed, 4 Sep 2019 19:53:44 +0200 Message-Id: <20190904175317.230745302@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Schmid, Carsten commit 76da906ad727048a74bb8067031ee99fc070c7da upstream. Using managed device resources in usb_hcd_pci_probe() allows devm usage for resource subranges, such as the mmio resource for the platform device created to control host/device mode mux, which is a xhci extended capability, and sits inside the xhci mmio region. If managed device resources are not used then "parent" resource is released before subrange at driver removal as .remove callback is called before the devres list of resources for this device is walked and released. This has been observed with the xhci extended capability driver causing a use-after-free which is now fixed. An additional nice benefit is that error handling on driver initialisation is simplified much. Signed-off-by: Carsten Schmid Tested-by: Carsten Schmid Reviewed-by: Mathias Nyman Fixes: fa31b3cb2ae1 ("xhci: Add Intel extended cap / otg phy mux handling") Cc: # v4.19+ Link: https://lore.kernel.org/r/1566569488679.31808@mentor.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd-pci.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c @@ -216,17 +216,18 @@ int usb_hcd_pci_probe(struct pci_dev *de /* EHCI, OHCI */ hcd->rsrc_start = pci_resource_start(dev, 0); hcd->rsrc_len = pci_resource_len(dev, 0); - if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, - driver->description)) { + if (!devm_request_mem_region(&dev->dev, hcd->rsrc_start, + hcd->rsrc_len, driver->description)) { dev_dbg(&dev->dev, "controller already in use\n"); retval = -EBUSY; goto put_hcd; } - hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); + hcd->regs = devm_ioremap_nocache(&dev->dev, hcd->rsrc_start, + hcd->rsrc_len); if (hcd->regs == NULL) { dev_dbg(&dev->dev, "error mapping memory\n"); retval = -EFAULT; - goto release_mem_region; + goto put_hcd; } } else { @@ -240,8 +241,8 @@ int usb_hcd_pci_probe(struct pci_dev *de hcd->rsrc_start = pci_resource_start(dev, region); hcd->rsrc_len = pci_resource_len(dev, region); - if (request_region(hcd->rsrc_start, hcd->rsrc_len, - driver->description)) + if (devm_request_region(&dev->dev, hcd->rsrc_start, + hcd->rsrc_len, driver->description)) break; } if (region == PCI_ROM_RESOURCE) { @@ -275,20 +276,13 @@ int usb_hcd_pci_probe(struct pci_dev *de } if (retval != 0) - goto unmap_registers; + goto put_hcd; device_wakeup_enable(hcd->self.controller); if (pci_dev_run_wake(dev)) pm_runtime_put_noidle(&dev->dev); return retval; -unmap_registers: - if (driver->flags & HCD_MEMORY) { - iounmap(hcd->regs); -release_mem_region: - release_mem_region(hcd->rsrc_start, hcd->rsrc_len); - } else - release_region(hcd->rsrc_start, hcd->rsrc_len); put_hcd: usb_put_hcd(hcd); disable_pci: @@ -347,14 +341,6 @@ void usb_hcd_pci_remove(struct pci_dev * dev_set_drvdata(&dev->dev, NULL); up_read(&companions_rwsem); } - - if (hcd->driver->flags & HCD_MEMORY) { - iounmap(hcd->regs); - release_mem_region(hcd->rsrc_start, hcd->rsrc_len); - } else { - release_region(hcd->rsrc_start, hcd->rsrc_len); - } - usb_put_hcd(hcd); pci_disable_device(dev); }