From patchwork Tue Oct 27 14:38:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7497191 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 50719BEEA4 for ; Tue, 27 Oct 2015 14:42:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 62B1C20924 for ; Tue, 27 Oct 2015 14:42:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6274020918 for ; Tue, 27 Oct 2015 14:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932465AbbJ0OjW (ORCPT ); Tue, 27 Oct 2015 10:39:22 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:37723 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932247AbbJ0OjU (ORCPT ); Tue, 27 Oct 2015 10:39:20 -0400 Received: by wicfv8 with SMTP id fv8so165639105wic.0; Tue, 27 Oct 2015 07:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Uu1rJHcBfOpFM+QrkPLTnbI8NwkLmv2i7+URmW1n/Bw=; b=dSoYgWgNllfxkovARG1arRolQsnItu8+RkEFYM47hUr4ZZ2AwmU3PbLqN9X7oAGltG iNhwGIJdF/OLcJ039VXBo2PFUnVGIBepbAe5dw+ncNkAzd6seELVqb9eOaQ0Ggewl3Q7 df+UjUOVT3TGDeA01OSmCzajWeBj3r9vKygY/63O2aMnQSVNQtqliOXhfEH8dSqjyhw0 YLdPgyc6OcqkDmLHSYBdpQpzSglgR8EEl6Cozv1ZNKam88UMSBqTaqYZgozG7uTczZyv K46hgPGi9omjLaSakdzDkmUgdLosjF07O8bOLbawwZ3S/QSy+7BOwxZRb+SNUbnNv9Ll KqUQ== X-Received: by 10.180.99.69 with SMTP id eo5mr28662697wib.73.1445956759262; Tue, 27 Oct 2015 07:39:19 -0700 (PDT) Received: from cizrna.lan ([109.72.12.201]) by smtp.gmail.com with ESMTPSA id n17sm2717046wmg.17.2015.10.27.07.39.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Oct 2015 07:39:18 -0700 (PDT) From: Tomeu Vizoso To: linux-pm@vger.kernel.org, Alan Stern , "Rafael J. Wysocki" , martyn.welch@collabora.co.uk, Ulf Hansson Cc: Tomeu Vizoso , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v11 1/4] device core: add device_is_bound() Date: Tue, 27 Oct 2015 15:38:48 +0100 Message-Id: <1445956731-6304-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1445956731-6304-1-git-send-email-tomeu.vizoso@collabora.com> References: <1445956731-6304-1-git-send-email-tomeu.vizoso@collabora.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds a function that tells whether a device is already bound to a driver. This is needed to warn when there is an attempt to change the PM domain of a device that has finished probing already. The reason why we want to enforce that is because in the general case that can cause problems and also that we can simplify code quite a bit if we can always assume that. Signed-off-by: Tomeu Vizoso Reviewed-by: Ulf Hansson Acked-by: Greg Kroah-Hartman --- Changes in v9: - Add docs noting the need for the device lock to be held before calling device_is_bound() Changes in v8: - Add device_is_bound() drivers/base/dd.c | 18 ++++++++++++++++-- include/linux/device.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index be0eb4639128..d662ed5d08f4 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -192,9 +192,23 @@ static int deferred_probe_initcall(void) } late_initcall(deferred_probe_initcall); +/** + * device_is_bound() - Check if device is bound to a driver + * @dev: device to check + * + * Returns true if passed device has already finished probing successfully + * against a driver. + * + * This function must be called with the device lock held. + */ +bool device_is_bound(struct device *dev) +{ + return klist_node_attached(&dev->p->knode_driver); +} + static void driver_bound(struct device *dev) { - if (klist_node_attached(&dev->p->knode_driver)) { + if (device_is_bound(dev)) { printk(KERN_WARNING "%s: device %s already bound\n", __func__, kobject_name(&dev->kobj)); return; @@ -545,7 +559,7 @@ static int __device_attach(struct device *dev, bool allow_async) device_lock(dev); if (dev->driver) { - if (klist_node_attached(&dev->p->knode_driver)) { + if (device_is_bound(dev)) { ret = 1; goto out_unlock; } diff --git a/include/linux/device.h b/include/linux/device.h index 5d7bc6349930..9b41c05fb479 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1035,6 +1035,8 @@ extern int __must_check driver_attach(struct device_driver *drv); extern void device_initial_probe(struct device *dev); extern int __must_check device_reprobe(struct device *dev); +extern bool device_is_bound(struct device *dev); + /* * Easy functions for dynamically creating devices on the fly */