Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1405026imm; Tue, 15 May 2018 19:41:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoTZgUazfqfnNDTyPwuhd73pHhBnQoZSlfLIM8vtNX3oA6WRx7EYp/2OHCHQtx8fP4V5U+c X-Received: by 2002:a62:1306:: with SMTP id b6-v6mr17492435pfj.58.1526438507219; Tue, 15 May 2018 19:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526438507; cv=none; d=google.com; s=arc-20160816; b=LW8PvPFCcwJsblEc5pqP0vxyRb7dy6ZteVc7XMM927S09LDy4hjxqA9BO6ZslTG0Qr RlaAaOfB9pdyl03u8AlBSWBoVQC3M8il4F5hEPzhb0EJVcVrQTk/oi4Y0mWJmJI2yE8n YdJeFb/JzV1APMYffbN2KvpYKXI1VabcGrBnB8pB2azWmJnBr6Csornq/sQ3yHZjM6an o3YmcE3tn39s3r1fsk1t1d7jyOr0W1/tzHkSqXT2YJgZOga0OcfNZS7WfGAEg6f867qw 9mic6wDwjOHB0u+70XqDAuET6O09TYnW4RWLGoBPH5fnGxoM29GJ/m7UkVxNUEnABAps BsUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=Hs8t4zZRSGbufPSsSfDnPrSaNlQiovxyXlvKOQYaqOo=; b=p4TAYKz4NPVPp3sYGssgGHbIZFRZ0M1P586+GFOBhNdbRlnoXrs6vwYmGG3JWcyq8v fQPxf3QzObVRkb0IxXYJIFizYaiqsuPghZFkjHm4Q/Jou1JnQF5E7ak8EM9yDLADb6Mb VHk9+vxc3sxcEltMvT3yUbM81rOciqJpTwEcQ8ToBNmKEwDbYBbx+PE0VcmNhuuOlnnC ehFPP2KkotrIgUnwUoHrSzvywaN7+XdcqdcC0/DRJFQeTMzb3gRKyldiF3Pxxc0crr1V lMDvg8sRQPcvlrIaUHg7JRWEbE3lNSZuIyIkn52E9YP6tcql5jMo5rzGaCmeq/fhGr+g D+jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=vuPVAJPM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5-v6si1233761pgs.317.2018.05.15.19.41.32; Tue, 15 May 2018 19:41:47 -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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=vuPVAJPM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752060AbeEPCkY (ORCPT + 99 others); Tue, 15 May 2018 22:40:24 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:48400 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbeEPCkW (ORCPT ); Tue, 15 May 2018 22:40:22 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4G2a7qT063569; Wed, 16 May 2018 02:40:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=Hs8t4zZRSGbufPSsSfDnPrSaNlQiovxyXlvKOQYaqOo=; b=vuPVAJPMMVlkPZzx7UWTO7T3qVPdNkIMalM6olGxs/6am25dRthGlGzuhj2Nhcl0qab1 eTXH5azP8o3JS294scK2JLq0NIuHBhKXXMOYD6087BC9cVFTIdjtqirBEAB4BaMrn0sN 5yDWMcDoH9n3SD/M4UkUJT6EWaavE9pU/fBvlulr3OLWGwmfTo5wnd8liJhoyhg0X62x daurzxwIsIPbPEQRpSubQD1HCY3MJLSZ8h9/t3n276xIJzB6vS25ecnxTIG+rSECMb9H w6hZf2s6BO2UxIxxGR74+WupiB4uZzpjGt5ggVHUV91fi4qVvJGu1ssWE0TtVGXvb92X +A== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2hxpvcsf46-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 May 2018 02:40:15 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4G2eFuu009928 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 May 2018 02:40:15 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w4G2eEF7010100; Wed, 16 May 2018 02:40:14 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 15 May 2018 19:40:14 -0700 From: Pavel Tatashin To: pasha.tatashin@oracle.com, steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux-kernel@vger.kernel.org, jeffrey.t.kirsher@intel.com, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, gregkh@linuxfoundation.org, alexander.duyck@gmail.com, tobin@apporbit.com, andy.shevchenko@gmail.com Subject: [PATCH v5 1/3] drivers core: refactor device_shutdown Date: Tue, 15 May 2018 22:40:02 -0400 Message-Id: <20180516024004.28977-2-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516024004.28977-1-pasha.tatashin@oracle.com> References: <20180516024004.28977-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8894 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=722 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805160023 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org device_shutdown() traverses through the list of devices, and calls dev->{bug/driver}->shutdown() for each entry in the list. Refactor the function by keeping device_shutdown() to do the logic of traversing the list of devices, and device_shutdown_one() to perform the actual shutdown operation on one device. Signed-off-by: Pavel Tatashin --- drivers/base/core.c | 50 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index b610816eb887..ed189f6d1a2f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2765,6 +2765,35 @@ int device_move(struct device *dev, struct device *new_parent, } EXPORT_SYMBOL_GPL(device_move); +/* + * device_shutdown_one - call ->shutdown() for the device passed as + * argument. + */ +static void device_shutdown_one(struct device *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); + } + + /* decrement the reference counter */ + put_device(dev); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ @@ -2801,30 +2830,11 @@ void device_shutdown(void) 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_shutdown_one(dev); device_unlock(dev); if (parent) device_unlock(parent); - put_device(dev); put_device(parent); spin_lock(&devices_kset->list_lock); -- 2.17.0