From patchwork Tue Jul 3 06:50:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 938416 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41KZdq694Hz9s29 for ; Tue, 3 Jul 2018 16:55:59 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J6Fzle3x"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41KZdq4bX5zF1Pm for ; Tue, 3 Jul 2018 16:55:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J6Fzle3x"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::242; helo=mail-pf0-x242.google.com; envelope-from=kernelfans@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J6Fzle3x"; dkim-atps=neutral Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41KZXm6G5MzF1NW for ; Tue, 3 Jul 2018 16:51:36 +1000 (AEST) Received: by mail-pf0-x242.google.com with SMTP id b17-v6so531980pfi.0 for ; Mon, 02 Jul 2018 23:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ekKHE1upI1u6JQRCI10SmXBvRXgm/pCCr/snxtYlQNI=; b=J6Fzle3xuXyBrIfVUrAKawmeVV6kFzHf3JZVhUDigezTcrC9fNJ5fdbeVU3Drd0kKV X6G5GsecuddQm1du9kG7HkYKiGIKEjPtc7/IhravSKUIqWPlyTgwuSEyIsAteZ3f0kTF DsewFtxM2fuS0UqKGEBy9SNSBr9p5JMTO0G8y3n+C2H2AYJmWne+MOYP5JvoYNf6ee+I /C8B/xhiGbjUPu5Q26gmSUkVnTTEYQ2NoL31172BC2b1jqN/+BLScnoaPK6zdjpAR3iI +lZKe44PrLi+LRGiC/gB3Kc0JM7ODliHZFLZf3qUelGzuxPkzu3TMriTuIClaOnl6gp7 PT0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ekKHE1upI1u6JQRCI10SmXBvRXgm/pCCr/snxtYlQNI=; b=GE9q1+rh7mBX6znIg8m1gOhRwDKqicAQLF5lFitFDrui1INlOjGPTNX/Kp9ZH2Omee VBZTAkN8r+FeLF88KEkYcxxQ6x5GmeNGy5il41PNnJ1Go0zeu5eRAxtcFFxCaaiFYvU5 3s1Ex4QFJwQXqnG4RZ4tmiVh/xMxGaVDTaRdVNaEgusGT2JY5EL5ddr18ymCBzZsU8N/ R0CWz2AhS/5xQrvvIgqrqB/6ID+Jd1IEDtyo9S/YP5L/oWDbcmO1/4HNCLoa3H4ALW2J lpqC+FGnwhi1XTgsI8tXLW7kdrM1rTxCRGqrV/7NUu9/+H9xyb3mAyf0uqE+7HbKKG16 CQYA== X-Gm-Message-State: APt69E3SeypwT4R95CFvPHW3AC2IUel/yujPFBtiTapJZ1GLY777lUU7 AZUFGCmlSRJofUBq7oowaQ== X-Google-Smtp-Source: AAOMgpcXhK2+wv6kn1QNTEtwzk89l3S+HwU2Q0sPNI/o4r91egKKDeLLprRI33urfADgU5fGOwDxUg== X-Received: by 2002:a62:3101:: with SMTP id x1-v6mr28007532pfx.246.1530600694598; Mon, 02 Jul 2018 23:51:34 -0700 (PDT) Received: from mylaptop.nay.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id e189-v6sm981122pfe.52.2018.07.02.23.51.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jul 2018 23:51:34 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Subject: [PATCHv3 1/4] drivers/base: fold the routine of device's shutdown into a func Date: Tue, 3 Jul 2018 14:50:39 +0800 Message-Id: <1530600642-25090-2-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530600642-25090-1-git-send-email-kernelfans@gmail.com> References: <1530600642-25090-1-git-send-email-kernelfans@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Grygorii Strashko , Greg Kroah-Hartman , "Rafael J . Wysocki" , linuxppc-dev@lists.ozlabs.org, Pingfan Liu , Christoph Hellwig , Bjorn Helgaas , linux-pci@vger.kernel.org, Dave Young Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Pack the code into a function to ease the using and reading. Cc: Greg Kroah-Hartman Cc: Rafael J. Wysocki Cc: Grygorii Strashko Cc: Christoph Hellwig Cc: Bjorn Helgaas Cc: Dave Young Cc: linux-pci@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Pingfan Liu --- drivers/base/core.c | 100 +++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index df3e1a4..a48868f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2802,12 +2802,62 @@ int device_move(struct device *dev, struct device *new_parent, } EXPORT_SYMBOL_GPL(device_move); +static void __device_shutdown(struct device *dev) +{ + struct device *parent; + /* + * hold reference count of device's parent to + * prevent it from being freed because parent's + * lock is to be held + */ + parent = get_device(dev->parent); + get_device(dev); + /* + * Make sure the device is off the kset list, in the + * event that dev->*->shutdown() doesn't remove it. + */ + list_del_init(&dev->kobj.entry); + spin_unlock(&devices_kset->list_lock); + + /* hold lock to avoid race with probe/release */ + if (parent) + device_lock(parent); + device_lock(dev); + + /* Don't allow any more runtime suspends */ + pm_runtime_get_noresume(dev); + pm_runtime_barrier(dev); + + if (dev->class && dev->class->shutdown_pre) { + if (initcall_debug) + dev_info(dev, "shutdown_pre\n"); + dev->class->shutdown_pre(dev); + } + if (dev->bus && dev->bus->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->bus->shutdown(dev); + } else if (dev->driver && dev->driver->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->driver->shutdown(dev); + } + + device_unlock(dev); + if (parent) + device_unlock(parent); + + put_device(dev); + put_device(parent); + spin_lock(&devices_kset->list_lock); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ void device_shutdown(void) { - struct device *dev, *parent; + struct device *dev; spin_lock(&devices_kset->list_lock); /* @@ -2818,53 +2868,7 @@ void device_shutdown(void) while (!list_empty(&devices_kset->list)) { dev = list_entry(devices_kset->list.prev, struct device, kobj.entry); - - /* - * hold reference count of device's parent to - * prevent it from being freed because parent's - * lock is to be held - */ - parent = get_device(dev->parent); - get_device(dev); - /* - * Make sure the device is off the kset list, in the - * event that dev->*->shutdown() doesn't remove it. - */ - list_del_init(&dev->kobj.entry); - spin_unlock(&devices_kset->list_lock); - - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); - device_lock(dev); - - /* Don't allow any more runtime suspends */ - pm_runtime_get_noresume(dev); - pm_runtime_barrier(dev); - - if (dev->class && dev->class->shutdown_pre) { - if (initcall_debug) - dev_info(dev, "shutdown_pre\n"); - dev->class->shutdown_pre(dev); - } - if (dev->bus && dev->bus->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->bus->shutdown(dev); - } else if (dev->driver && dev->driver->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->driver->shutdown(dev); - } - - device_unlock(dev); - if (parent) - device_unlock(parent); - - put_device(dev); - put_device(parent); - - spin_lock(&devices_kset->list_lock); + __device_shutdown(dev); } spin_unlock(&devices_kset->list_lock); }