From patchwork Fri Jun 17 06:26:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9182617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 814A06075F for ; Fri, 17 Jun 2016 06:29:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7048C1FF0B for ; Fri, 17 Jun 2016 06:29:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6527B2839F; Fri, 17 Jun 2016 06:29:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E62C927EED for ; Fri, 17 Jun 2016 06:29:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754753AbcFQG2u (ORCPT ); Fri, 17 Jun 2016 02:28:50 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:57146 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755239AbcFQG1S (ORCPT ); Fri, 17 Jun 2016 02:27:18 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8W00MCLKLASF90@mailout3.w1.samsung.com>; Fri, 17 Jun 2016 07:27:10 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-b7-5763983ea067 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id C8.83.05254.E3893675; Fri, 17 Jun 2016 07:27:10 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8W00HUZKL21910@eusync4.samsung.com>; Fri, 17 Jun 2016 07:27:10 +0100 (BST) From: Marek Szyprowski To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Marek Szyprowski , Joerg Roedel , Inki Dae , Kukjin Kim , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , "Rafael J. Wysocki" , Ulf Hansson , Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH v2 01/10] driver core: Add a wrapper around __device_release_driver() Date: Fri, 17 Jun 2016 08:26:51 +0200 Message-id: <1466144820-6286-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1466144820-6286-1-git-send-email-m.szyprowski@samsung.com> References: <1466144820-6286-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBLMWRmVeSWpSXmKPExsVy+t/xa7p2M5LDDa4cULTYOGM9q8XUh0/Y LJoXr2ezmHR/AovFgv3WFp2zN7BbvH5haNH/+DWzxabH11gtLu+aw2bxufcIo8WM8/uYLNYe uctu8XjFW3aLM6cvsVocXxvuIODx5OA8Jo/Fe14yeWxa1cnmcefaHjaP/XPXsHtsXlLvMfnG ckaPLVfbWTz6tqxi9Pi8SS6AK4rLJiU1J7MstUjfLoEr43bPM5aCC/wVZ7o+MjcwvuTpYuTk kBAwkdi5awcrhC0mceHeerYuRi4OIYGljBKX9k9ngnCamCTert3IAlLFJmAo0fW2C6xKRGAl o8S2PfuYQRxmgavMEnP27ASrEhYIlzi07Sk7iM0ioCpxfMsUMJtXwF1i8ZMmFoh9chInj00G 280p4CHx4tYPsLgQUM2uw6eYJzDyLmBkWMUomlqaXFCclJ5rqFecmFtcmpeul5yfu4kREt5f djAuPmZ1iFGAg1GJh3eFaHK4EGtiWXFl7iFGCQ5mJRFezelAId6UxMqq1KL8+KLSnNTiQ4zS HCxK4rxzd70PERJITyxJzU5NLUgtgskycXBKNTAu0DR44b214Bbr1cKHX5vi3MJmXzhrvLak d6Hd3p/rZM+dS/6+aLreBLfaTw1c0yawBE0JnVgWWXfjHHvHnGPirL3Gjl6/Dha6JiwtnOI3 NfREpMkdI31O/aDorN4Mo54X+zUb9FK4lE5MF+M5ebOkdeHxx25hC0+o9lwJZ6nLv7TMr+Ht fQ8lluKMREMt5qLiRABtsgpSawIAAA== Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Rafael J. Wysocki" Add an internal wrapper around __device_release_driver() that will acquire device locks and do the necessary checks before calling it. The next patch will make use of it. Signed-off-by: Rafael J. Wysocki Signed-off-by: Marek Szyprowski --- drivers/base/dd.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 16688f50729c..d9e76e9205c7 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -796,6 +796,22 @@ static void __device_release_driver(struct device *dev) } } +static void device_release_driver_internal(struct device *dev, + struct device_driver *drv, + struct device *parent) +{ + if (parent) + device_lock(parent); + + device_lock(dev); + if (!drv || drv == dev->driver) + __device_release_driver(dev); + + device_unlock(dev); + if (parent) + device_unlock(parent); +} + /** * device_release_driver - manually detach device from driver. * @dev: device. @@ -810,9 +826,7 @@ void device_release_driver(struct device *dev) * within their ->remove callback for the same device, they * will deadlock right here. */ - device_lock(dev); - __device_release_driver(dev); - device_unlock(dev); + device_release_driver_internal(dev, NULL, NULL); } EXPORT_SYMBOL_GPL(device_release_driver); @@ -837,15 +851,7 @@ void driver_detach(struct device_driver *drv) dev = dev_prv->device; get_device(dev); spin_unlock(&drv->p->klist_devices.k_lock); - - if (dev->parent) /* Needed for USB */ - device_lock(dev->parent); - device_lock(dev); - if (dev->driver == drv) - __device_release_driver(dev); - device_unlock(dev); - if (dev->parent) - device_unlock(dev->parent); + device_release_driver_internal(dev, drv, dev->parent); put_device(dev); } }