From patchwork Wed Oct 21 15:34:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7457671 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3EE7E9F1C3 for ; Wed, 21 Oct 2015 15:37:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 67382208A0 for ; Wed, 21 Oct 2015 15:37:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84D2E2089F for ; Wed, 21 Oct 2015 15:37:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755460AbbJUPeq (ORCPT ); Wed, 21 Oct 2015 11:34:46 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:36772 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755174AbbJUPeo (ORCPT ); Wed, 21 Oct 2015 11:34:44 -0400 Received: by wicfx6 with SMTP id fx6so97048036wic.1; Wed, 21 Oct 2015 08:34:43 -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=olbjtBO3IPG8+br9J1HiDSkykwd+FXnWqB3XZvEyt6c=; b=z6atYiRvmYnLfJc4v11AkJEpQrMQKBUtW37PVgEMynOnyeXp1sfVk6ZmO7yloMl6xu L9KsDC2M4vcqNatkJxqnNFimIgAuTXHBVRGJEvYnOszN/QhQn/RluYO83Rng3VY7Uqx0 ROeffeUKigpqSoAuZwHRLE6ik5tJhGLA9EPHS8g4XvFENLsR7hV9PHM6S12Fbp5U6hek Qo8VoHsvaHubBIrtZmh9An3yXO1eiYmX/xMvCtHbVvGY3+5f+HCo7EryVcgeZ15TlHpT PrexqDchO9BuFQGER3DxDb8Z+GTkZQBu2tlPRNE4EiL0AKIkLfHf/v1C0ZpCkcgtDt9P cX7w== X-Received: by 10.180.99.69 with SMTP id eo5mr21772930wib.73.1445441683017; Wed, 21 Oct 2015 08:34:43 -0700 (PDT) Received: from cizrna.lan ([109.72.12.185]) by smtp.gmail.com with ESMTPSA id x9sm11070828wjf.44.2015.10.21.08.34.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Oct 2015 08:34:41 -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 v10 1/4] device core: add device_is_bound() Date: Wed, 21 Oct 2015 17:34:11 +0200 Message-Id: <1445441654-31778-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1445441654-31778-1-git-send-email-tomeu.vizoso@collabora.com> References: <1445441654-31778-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 */