From patchwork Thu Jan 7 15:46:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7978211 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 4A691BEEE5 for ; Thu, 7 Jan 2016 15:47:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 756A02012D for ; Thu, 7 Jan 2016 15:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89B182011B for ; Thu, 7 Jan 2016 15:47:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753643AbcAGPqh (ORCPT ); Thu, 7 Jan 2016 10:46:37 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:37802 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753621AbcAGPqf (ORCPT ); Thu, 7 Jan 2016 10:46:35 -0500 Received: by mail-wm0-f41.google.com with SMTP id f206so129923604wmf.0; Thu, 07 Jan 2016 07:46:35 -0800 (PST) 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=64eN1v69lHLUkptULrF6jgcrd0HnUq65gitMT9kj/eU=; b=fHek2XML9iHJxQGoD6u5pVQLoNjetRrAxxchXX6UR53uGzgn3L05YlBJ2TiYbFdXfT XuvqMiFgJhEaTyq9dnYIhNLIqKs3OH/8I82de0/uYVZ8afhvDYE6mc5uN2B645Unbe38 TTpAV4L5C8wif1NIhZeJVc263LH0A9GUqTLygZzhsqj3Q/1x8R/Aa2FsHHRiEO8c7102 A39qzpB8ug4aUVyViY7BJ9Otro9zad5JmZSlkY93KW/WZoPg1KxmNZPVGuv6zzri7mho aZ/9b2O/noAac/8AUY8HMwJrKvG2jHjWjtl5QcsCWomaDJjHvcCN7JT0f2IohE4L9NBq wLHQ== X-Received: by 10.28.18.21 with SMTP id 21mr16520171wms.11.1452181594709; Thu, 07 Jan 2016 07:46:34 -0800 (PST) Received: from cizrna.lan ([109.72.12.126]) by smtp.gmail.com with ESMTPSA id g187sm14145570wmf.8.2016.01.07.07.46.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jan 2016 07:46:33 -0800 (PST) From: Tomeu Vizoso To: linux-pm@vger.kernel.org, Alan Stern , "Rafael J. Wysocki" , martyn.welch@collabora.co.uk, Ulf Hansson , Daniel Kurtz Cc: Tomeu Vizoso , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v12 1/4] device core: add device_is_bound() Date: Thu, 7 Jan 2016 16:46:12 +0100 Message-Id: <1452181575-9206-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452181575-9206-1-git-send-email-tomeu.vizoso@collabora.com> References: <1452181575-9206-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 7399be790b5d..13a0d66e5782 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -223,9 +223,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; @@ -601,7 +615,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 f627ba20a46c..6d6f1fec092f 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1044,6 +1044,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 */