From patchwork Wed Jun 27 12:50:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 10491487 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 3678B60532 for ; Wed, 27 Jun 2018 12:51:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2439528E8D for ; Wed, 27 Jun 2018 12:51:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 223D428EA2; Wed, 27 Jun 2018 12:51:51 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AA9F228E8D for ; Wed, 27 Jun 2018 12:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=+XOs2dT8LL7J8kOnkBrMRHfivY3PTJJkr4uRXdroeMo=; b=WC6A2gfjQ6Kcx8S/m+jp1EXez7 AJI8eDrFmZeY/mi1V1G93iJeOS7Jo87Zsh255ZygmxAo8MIjh8qqIfpVUp2UKl0TWA0Xvcyezfx5v JLfP2PjzCgC0vCXTXVc0SAO6aeD1Wy7dxxTmZlNlVUwTkrL8BLbd2ZM3Six2/GwMoF6H7cfSwTUzo aigphl8x87y0vFdyuvHsPVnQ9GGc1z7PpO691350kKetYnd+I5wvoN1RRt5alm80DfXGppGmOZ4Bh mTzw2Tzit7axZWII8O9NMBYXuM1BBKkD3eyfMY0TRUpBsIjCslepHJ6Ow8JGpgaOsmQ8Aj5+jK2HF Dwf+iktQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fY9vA-0005h6-HV; Wed, 27 Jun 2018 12:51:40 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fY9v5-0005fS-Tf for linux-arm-kernel@lists.infradead.org; Wed, 27 Jun 2018 12:51:37 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CB668605A5; Wed, 27 Jun 2018 12:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530103884; bh=lhkpGk75F3pQcTHccC1itm+8WL/mmT5/GA0tQYpHhrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W1uC4us7FCWmiJvDPBfBzp5slp/KSlq+oSg2PqZ8T5CaiS5d+7pNb8FtWSceNslAp Oyyt0nhC4RYJMKnSNGy7AHPwQ9f0CcPKRxt+i5i6QGoAxbwblrt39V4AZxbX7O01m7 OawwiiCbPQDaVyAmV8KWNHA82jL7dKcs1cczZvpE= Received: from blr-ubuntu-41.ap.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4B2E560714; Wed, 27 Jun 2018 12:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530103882; bh=lhkpGk75F3pQcTHccC1itm+8WL/mmT5/GA0tQYpHhrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fZxU5uIMI3VfX0QW1+kljCXJFZlioyXVYgZCfn7eUrjT66E/iUd0n+bhBNXcuKYLr gaiSN3m1+i0AYWDU37q6eQ2CqYbMjXmvJgftKNw9W5tG5Y+znk+Vrnwm3xpmPfS1R0 14POuiq27dFMTAopOzJQr2jZ+T+uvSYkaJTXJtUo= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4B2E560714 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: rjw@rjwysocki.net, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] device core: Add flag to autoremove device link on supplier unbind Date: Wed, 27 Jun 2018 18:20:56 +0530 Message-Id: <20180627125056.12851-2-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 2.16.1.72.g5be1f00a9a70 In-Reply-To: <20180627125056.12851-1-vivek.gautam@codeaurora.org> References: <20180627125056.12851-1-vivek.gautam@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180627_055136_024002_C9FEEA96 X-CRM114-Status: GOOD ( 16.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-doc@vger.kernel.org, Greg Kroah-Hartman , linux-pm@vger.kernel.org, Jonathan Corbet , Vivek Gautam , linux-arm-msm@vger.kernel.org, Robin Murphy , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a flag to autoremove the device links on supplier driver unbind. This obviates the need to explicitly delete the link in the remove path. We remove these links only when the supplier's link to its consumers has gone to DL_STATE_SUPPLIER_UNBIND state. Signed-off-by: Vivek Gautam Suggested-by: Lukas Wunner Cc: Jonathan Corbet Cc: Greg Kroah-Hartman Cc: Robin Murphy Cc: linux-doc@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-pm@vger.kernel.org Cc: linux-arm-msm@vger.kernel.org Reviewed-by: Ulf Hansson --- Documentation/driver-api/device_link.rst | 4 ++++ drivers/base/core.c | 10 ++++++++++ include/linux/device.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/Documentation/driver-api/device_link.rst b/Documentation/driver-api/device_link.rst index a005b904a264..d6763272e747 100644 --- a/Documentation/driver-api/device_link.rst +++ b/Documentation/driver-api/device_link.rst @@ -86,6 +86,10 @@ automatically purged when the consumer fails to probe or later unbinds. This obviates the need to explicitly delete the link in the ``->remove`` callback or in the error path of the ``->probe`` callback. +Similarly, when the device link is added from supplier's ``->probe`` callback, +``DL_FLAG_AUTOREMOVE_SUPPLIER`` causes the device link to be automatically +purged when the supplier fails to probe or later unbinds. + Limitations =========== diff --git a/drivers/base/core.c b/drivers/base/core.c index 14c1e3151e08..e721218bf352 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -518,6 +518,16 @@ void device_links_driver_cleanup(struct device *dev) WARN_ON(link->flags & DL_FLAG_AUTOREMOVE_CONSUMER); WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND); + + /* + * autoremove the links between this @dev and its consumer + * devices that are not active, i.e. where the link state + * has moved to DL_STATE_SUPPLIER_UNBIND. + */ + if (link->status == DL_STATE_SUPPLIER_UNBIND && + link->flags & DL_FLAG_AUTOREMOVE_SUPPLIER) + kref_put(&link->kref, __device_link_del); + WRITE_ONCE(link->status, DL_STATE_DORMANT); } diff --git a/include/linux/device.h b/include/linux/device.h index 3929805cdd59..e80920452b49 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -787,11 +787,13 @@ enum device_link_state { * AUTOREMOVE_CONSUMER: Remove the link automatically on consumer driver unbind. * PM_RUNTIME: If set, the runtime PM framework will use this link. * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation. + * AUTOREMOVE_SUPPLIER: Remove the link automatically on supplier driver unbind. */ #define DL_FLAG_STATELESS BIT(0) #define DL_FLAG_AUTOREMOVE_CONSUMER BIT(1) #define DL_FLAG_PM_RUNTIME BIT(2) #define DL_FLAG_RPM_ACTIVE BIT(3) +#define DL_FLAG_AUTOREMOVE_SUPPLIER BIT(4) /** * struct device_link - Device link representation.