Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1129156imm; Fri, 29 Jun 2018 11:55:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLTI8Z/w3UBJ++0i4nKIQLLpf031cObvoDp/+BGP+qanQGJRbH/G77xBV/JYFGF3ziFP6NG X-Received: by 2002:a65:4849:: with SMTP id i9-v6mr13627551pgs.350.1530298517694; Fri, 29 Jun 2018 11:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530298517; cv=none; d=google.com; s=arc-20160816; b=DPiDQHo2nRpzv4UpqWWS4ovYGo4d+2cByahNDlPjm+7osVNsul+76S+SUjPCet51/h 3NqDyFjoDxcdk5Ovj8c9WyiggEPUmJ2gMfXnB/WBqGzhAGmlM32i98lqxSLf2E9298HV 3zCvb1nB2nBF9r+a2xMIBxCGrd0glbVG8Kdjulh054OUqJgROUGfG77X8jLO5qesydwy IFuvT/VX0/CPv4ws2vMN6LNY42r6zi06Sz18N3M6S+K8ffEKdeLtX30OJwc9/7PZGb/Z b+TOj+P1nBC2KIrkXndnVzBX64fB0XvyzD+UahQwgIpvmBxLDpJC/mGb8Cvq3qy3/BLZ 8UDQ== 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=OOpqezTYYXcP7ueIysvVv00GVS+t7Jhwq1c/IOtbkww=; b=uTSq1qxcb8VbVtxGIeJNg1xsyKWUT74px8vKJ76/5kGD4Jpsz6xqel9oUYXTCCteO2 4/mpMROzlA1aXS5l+gKjlLywQOXOuDcu5z/8xoIWR7R49KMelR/JdWZYr0A9PVofDc8k tk+oq8/qaIjKPo6BCyZYxhdpEjQhWWPfRFaqEpG8ReGcoBH0Ay4FYR7kvQ1BTlycJk4J dDfWwO7RO6Q6feTvdnzYHOrVcL+qY5YJqDlVI32vD3esOVI8M6gkdzVugOtDKVLRgmqu oF2p/1qEoep+78UEQ4zUCoXITL92IrBJ0QsXtYoir0+x3QM37jWUEwjaR0E7nB86NZVU uZng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=ckQI4mAR; 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 z1-v6si9771578plo.516.2018.06.29.11.55.02; Fri, 29 Jun 2018 11:55:17 -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=ckQI4mAR; 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 S966114AbeF2SZz (ORCPT + 99 others); Fri, 29 Jun 2018 14:25:55 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:59928 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752231AbeF2SZx (ORCPT ); Fri, 29 Jun 2018 14:25:53 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5TINfSJ095728; Fri, 29 Jun 2018 18:25:48 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=OOpqezTYYXcP7ueIysvVv00GVS+t7Jhwq1c/IOtbkww=; b=ckQI4mARGczWfpGSuaR59hwZjwpPlJiN9k9GkgRAo+Y2xlyp+P7N/sr/QBqGjFGOtYDZ rMmmf1altPny2oULA4TrGAD7D5sq5Z7yt8enNVWQ52lqmEU3EUvZevRm26djZDCjaV6s ZSMqijEeJYZBkKJmoUC0R6eD11vtQAkzHkx2BBhLsBDkrzrvWV65bE8+GcmdYc9Z9wjm g/QPuHZPyP4Nir/T3rxHF6Ze1kM0Y3vItJ3a5jAXK+ZNN3GG5vsrFmY6N4bQsmtj5c8x WyICt1SFt0Gv39+Y63mFCPoau5g99YbF5Lcx1eG0W314km7PA1a53fS8txIZjF6Cky1t 6Q== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2jum0afh6x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Jun 2018 18:25:48 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w5TIPmBL017122 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Jun 2018 18:25:48 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w5TIPlVC031722; Fri, 29 Jun 2018 18:25:47 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 29 Jun 2018 11:25:47 -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 v6 1/3] drivers core: refactor device_shutdown Date: Fri, 29 Jun 2018 14:25:39 -0400 Message-Id: <20180629182541.6735-2-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180629182541.6735-1-pasha.tatashin@oracle.com> References: <20180629182541.6735-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8939 signatures=668703 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=760 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1806290195 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 Reviewed-by: Andy Shevchenko --- 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 df3e1a44707a..07380aa0683b 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2802,6 +2802,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. */ @@ -2838,30 +2867,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.18.0