From patchwork Fri Oct 2 07:14:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7313681 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 3D13FBEEA4 for ; Fri, 2 Oct 2015 07:18:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6070620857 for ; Fri, 2 Oct 2015 07:18:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A9D22078D for ; Fri, 2 Oct 2015 07:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751906AbbJBHSc (ORCPT ); Fri, 2 Oct 2015 03:18:32 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:33297 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751425AbbJBHQl (ORCPT ); Fri, 2 Oct 2015 03:16:41 -0400 Received: by wiclk2 with SMTP id lk2so20965423wic.0; Fri, 02 Oct 2015 00:16:40 -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=jGBtHVs9eOebX120J0IIatS16RAFw5O4byt7q5/8wHE=; b=z6endfy2c7VZfWBmw2z4Qu4APennhfNpxMBwl5CJNS7jW8EuihAKvdWhwscQctjM9U UnFh5afzn1ajaoNR6w7XBfPPjqzJLIXoypVISBc38/rWXMf0KOL0SxgT4XLh/dyQuOfM Hvgi8lSZ8xbHJCMKizyqatcpV7c2WYnsJ8jI98OloHKFlTZP/PERbpmAqVgmF6hzld5Z KUeU9feZjUh+Kqw6H4IB0Vo7K0ZQny1NstxiApyKtkvpuolEA3La5TjXLw02zsgf5Cb+ xvKdefeXOay/SoJq9j6hBhfPM6kpDLrj0aWqN5JoZqhxoqxcQzQD7J/wkOMBuKgFgSs/ +k2w== X-Received: by 10.180.36.212 with SMTP id s20mr2765911wij.14.1443770199995; Fri, 02 Oct 2015 00:16:39 -0700 (PDT) Received: from cizrna.lan ([109.72.12.253]) by smtp.gmail.com with ESMTPSA id ry1sm9840153wjb.24.2015.10.02.00.16.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 00:16:38 -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 v8 1/4] device core: add device_is_bound() Date: Fri, 2 Oct 2015 09:14:28 +0200 Message-Id: <1443770071-2570-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443770071-2570-1-git-send-email-tomeu.vizoso@collabora.com> References: <1443770071-2570-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,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham 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 --- Changes in v8: - Add device_is_bound() drivers/base/dd.c | 9 +++++++-- include/linux/device.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index be0eb4639128..f2007fa7316f 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -192,9 +192,14 @@ static int deferred_probe_initcall(void) } late_initcall(deferred_probe_initcall); +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 +550,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 */