From patchwork Wed Aug 3 19:49:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9262149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 87ACE6048F for ; Wed, 3 Aug 2016 19:50:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C1AC281DB for ; Wed, 3 Aug 2016 19:50:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47B8628306; Wed, 3 Aug 2016 19:50:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB4F1281DB for ; Wed, 3 Aug 2016 19:50:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758192AbcHCTuj (ORCPT ); Wed, 3 Aug 2016 15:50:39 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33258 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753171AbcHCTuh (ORCPT ); Wed, 3 Aug 2016 15:50:37 -0400 Received: by mail-wm0-f67.google.com with SMTP id o80so37851380wme.0 for ; Wed, 03 Aug 2016 12:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=8HGC1DTnC+EO5nNVeZRwa15Q9LB+FUeQLnteUZm2l9Y=; b=dz8OqLcAgJtzSWFfK3ATM1NRH1WqN1rMJt8DKbauAgSNddq9yn5VihixTkXo2jQy1b 5S2DFUgH5z82MR88oO6S3vWZkrsK7eDCqragZjbd2OeLlOcNoGljzXKOobAWT51qx+Fr +xhXIVkngEc+4asbPH5I12sv5Y71jaI++ZAby7Lit46PcfuAYDGrQCSbSCAn/9IjprKz 1LlH3Hf0/nM8Qp0PKJo4z+3YJqVHZQ0+VGpzp/GQlHziK4cVegjeBdaho+NKLT7YqEux Zp23vqIeRuzSTySDs9dnJnkAoHgJVvlKlrzBqS1BKdmv/lm7UWNBP9wl5jDyAcjUlLil H0Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=8HGC1DTnC+EO5nNVeZRwa15Q9LB+FUeQLnteUZm2l9Y=; b=eX7vOmWUUElvD1flZaNHGhdUPDtaQisbLDK4WtYQ9vr8Rji4vNZp+SBw98HjRtZuEf Ep8Xmqnc1Tbpo8EqwTruBFi+TRXZr0DOZcsyfqui0E37Ge8Xv5Rt/7RjFZzEv/+FMOuK 67ktNWk1ctrgLAEYJNas+imARoc+73ryY60oH7+cHYcm2i5bytvfZAy+hpkVP+30z5DV 1n548zyDvBaBqql+0/gfNEq5POkzBb/1ImqrGPA69+ReVCaIzA1w6WRy3lTF1+/R4d8S RNdXm9CGB2i/LfxBTUbnAwQ1H2+RdfwAkuDM0kr3Aan2lsfXpR3A6prnr2jgnC393BD4 vupw== X-Gm-Message-State: AEkooutyHnnvGICQtxQYENuYJdCkpMW2gpMKw3/JDOigDR0kPfP77ufnYqD+gjFxIQAxig== X-Received: by 10.195.12.77 with SMTP id eo13mr56513647wjd.142.1470253758267; Wed, 03 Aug 2016 12:49:18 -0700 (PDT) Received: from ?IPv6:2003:62:5f01:4400:757e:4744:3a80:1de8? (p200300625F014400757E47443A801DE8.dip0.t-ipconnect.de. [2003:62:5f01:4400:757e:4744:3a80:1de8]) by smtp.googlemail.com with ESMTPSA id m62sm9572228wmm.24.2016.08.03.12.49.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Aug 2016 12:49:17 -0700 (PDT) To: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org From: Heiner Kallweit Subject: [PATCH] scsi: core: configure runtime pm before calling device_add in scsi_add_host_with_dma Message-ID: <792dc1a9-2280-d1a2-c088-cfdd28c67df3@gmail.com> Date: Wed, 3 Aug 2016 21:49:03 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Runtime PM should be configured already once we call device_add. See also the description in this mail thread https://lists.linuxfoundation.org/pipermail/linux-pm/2009-November/023198.html or the order of calls e.g. in usb_new_device. The changed order also helps to avoid scenarios where runtime pm for &shost->shost_gendev is activated whilst the parent is suspended, resulting in error message "runtime PM trying to activate child device hostx but parent yyy is not active". In addition properly reverse the runtime pm calls in the error path. Signed-off-by: Heiner Kallweit Acked-by: Alan Stern --- drivers/scsi/hosts.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index ba9af4a..9ab94ad 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -246,10 +246,6 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, shost->dma_dev = dma_dev; - error = device_add(&shost->shost_gendev); - if (error) - goto out_destroy_freelist; - /* * Increase usage count temporarily here so that calling * scsi_autopm_put_host() will trigger runtime idle if there is @@ -260,6 +256,10 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, pm_runtime_enable(&shost->shost_gendev); device_enable_async_suspend(&shost->shost_gendev); + error = device_add(&shost->shost_gendev); + if (error) + goto out_destroy_freelist; + scsi_host_set_state(shost, SHOST_RUNNING); get_device(shost->shost_gendev.parent); @@ -309,6 +309,10 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, out_del_gendev: device_del(&shost->shost_gendev); out_destroy_freelist: + device_disable_async_suspend(&shost->shost_gendev); + pm_runtime_disable(&shost->shost_gendev); + pm_runtime_set_suspended(&shost->shost_gendev); + pm_runtime_put_noidle(&shost->shost_gendev); scsi_destroy_command_freelist(shost); out_destroy_tags: if (shost_use_blk_mq(shost))