From patchwork Thu Aug 11 15:20:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 73758 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp163494qga; Thu, 11 Aug 2016 08:21:14 -0700 (PDT) X-Received: by 10.66.242.166 with SMTP id wr6mr18206569pac.147.1470928872019; Thu, 11 Aug 2016 08:21:12 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q77si3659846pfj.63.2016.08.11.08.21.07; Thu, 11 Aug 2016 08:21:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752534AbcHKPVF (ORCPT + 27 others); Thu, 11 Aug 2016 11:21:05 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:34678 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbcHKPVB (ORCPT ); Thu, 11 Aug 2016 11:21:01 -0400 Received: by mail-oi0-f67.google.com with SMTP id t127so591361oie.1 for ; Thu, 11 Aug 2016 08:21:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KZsSlcl8O3ryUs6a9yfXvS+Jg+9yK/X8dS2lHeh/540=; b=TltkjZN3CCb01b6HSlJAmppsKhsEmKJoWbe8Ps4KxeMFJP2ZKHkymBcAjNSyAQsk1a 5olOQvHZMQxwr3dwME16h+0kHF8YHs8zbWlWZS/4XiablcKzj7HzZ1SOKn587O724yWp zbd8/HruVs412oBi3o7OBMDFRrF4JcRSn4J/pYSmk/18nFpnG8GgFY8Ni28OG2vOZvc+ 1ocJ0k0lZtCgNFWXdW0m+f9w5p1awnBdB7wYju0VDZsvMfPuJUqaGi2N7jW3zmRfw0Km G3ZoihA7HC/94Wr+CBOOZ14l5G8Sz8+GOsZ3R6v29QTXYoPMBwpXYxeqXnQBo3EEFYsu UAvw== X-Gm-Message-State: AEkoousGC2PpSnzzBZmoS/ITGpd1jVzhGrYPzWiFEOJoGatQWFQOpJw/gXO6Brreb4Mmbw== X-Received: by 10.157.48.112 with SMTP id w45mr2465663otd.153.1470928860456; Thu, 11 Aug 2016 08:21:00 -0700 (PDT) Received: from rob-hp-laptop.herring.priv (72-48-98-129.dyn.grandenetworks.net. [72.48.98.129]) by smtp.googlemail.com with ESMTPSA id 88sm1451466otm.25.2016.08.11.08.20.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Aug 2016 08:20:59 -0700 (PDT) From: Rob Herring To: Greg Kroah-Hartman Cc: Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH] driver core: add test of driver remove calls during probe Date: Thu, 11 Aug 2016 10:20:58 -0500 Message-Id: <20160811152058.31698-1-robh@kernel.org> X-Mailer: git-send-email 2.9.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In recent discussions on ksummit-discuss[1], it was suggested to do a sequence of probe, remove, probe for testing driver remove paths. This adds a kconfig option for said test. [1] https://lists.linuxfoundation.org/pipermail/ksummit-discuss/2016-August/003459.html Suggested-by: Arnd Bergmann Cc: Greg Kroah-Hartman Signed-off-by: Rob Herring --- drivers/base/Kconfig | 10 ++++++++++ drivers/base/dd.c | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) -- 2.9.2 diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index 98504ec..fdf44ca 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -212,6 +212,16 @@ config DEBUG_DEVRES If you are unsure about this, Say N here. +config DEBUG_TEST_DRIVER_REMOVE + bool "Test driver remove calls during probe" + depends on DEBUG_KERNEL + help + Say Y here if you want the Driver core to test driver remove functions + by calling probe, remove, probe. This tests the remove path without + having to unbind the driver or unload the driver module. + + If you are unsure about this, say N here. + config SYS_HYPERVISOR bool default n diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 16688f5..4910e6d 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -329,6 +329,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) { int ret = -EPROBE_DEFER; int local_trigger_count = atomic_read(&deferred_trigger_count); + bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE); if (defer_all_probes) { /* @@ -346,6 +347,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) drv->bus->name, __func__, drv->name, dev_name(dev)); WARN_ON(!list_empty(&dev->devres_head)); +re_probe: dev->driver = drv; /* If using pinctrl, bind pins now before probing */ @@ -383,6 +385,25 @@ static int really_probe(struct device *dev, struct device_driver *drv) goto probe_failed; } + if (test_remove) { + test_remove = false; + + if (dev->bus && dev->bus->remove) + dev->bus->remove(dev); + else if (drv->remove) + drv->remove(dev); + + devres_release_all(dev); + driver_sysfs_remove(dev); + dev->driver = NULL; + dev_set_drvdata(dev, NULL); + if (dev->pm_domain && dev->pm_domain->dismiss) + dev->pm_domain->dismiss(dev); + pm_runtime_reinit(dev); + + goto re_probe; + } + pinctrl_init_done(dev); if (dev->pm_domain && dev->pm_domain->sync)