From patchwork Mon Oct 5 14:45:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7328231 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 B6981BEEA4 for ; Mon, 5 Oct 2015 14:52:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CBE442069F for ; Mon, 5 Oct 2015 14:52:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D4E7C20688 for ; Mon, 5 Oct 2015 14:52:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752454AbbJEOv7 (ORCPT ); Mon, 5 Oct 2015 10:51:59 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:34110 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752079AbbJEOuq (ORCPT ); Mon, 5 Oct 2015 10:50:46 -0400 Received: by wicfx3 with SMTP id fx3so123891403wic.1; Mon, 05 Oct 2015 07:50:45 -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=dWkC5TYoP/djvfj5nYsCl9qsUQmJkeVJEclmXnsU2i8=; b=pM4Dcfz+O6I9mInPd6mnnhtRC+IEI7PF4yiBCSZd+udY24v8rvENtMGu1EUk3NPKPb q2J9b1Ze6X/NaZ3vz5iPSXxpB06HUnlB+74Yf98RI1KUQ3lNSiqQI+jCX73rA6EvfSFN atJnO41d8XNGE7iANRi3S4k3PRy3OVHkT5BlFX6D6tbyzLy53+mUhj6Hg/5dL9Fffs3s W4R4qM5pu5YQHBDveUMkCRrFvU7gTwAa1P1Xw4pN5t8uCM1JxHzWd6u4Fz9NjZXqL65E 5C2MI9FjN6rsMykGS/Mbgv1w5dzkw++crV4xwGLOV1CFqHpW0hwp+jdbAqzA+jFynAb4 Wt6g== X-Received: by 10.195.11.40 with SMTP id ef8mr30732637wjd.103.1444056644978; Mon, 05 Oct 2015 07:50:44 -0700 (PDT) Received: from cizrna.lan ([109.72.12.225]) by smtp.gmail.com with ESMTPSA id cv4sm27330030wjc.17.2015.10.05.07.50.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2015 07:50:43 -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 v9 1/4] device core: add device_is_bound() Date: Mon, 5 Oct 2015 16:45:29 +0200 Message-Id: <1444056332-30246-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1444056332-30246-1-git-send-email-tomeu.vizoso@collabora.com> References: <1444056332-30246-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=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 --- 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 */