From patchwork Fri Jan 5 00:14:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 10145827 X-Patchwork-Delegate: bhelgaas@google.com 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 5A2D36034B for ; Fri, 5 Jan 2018 00:15:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FAFA1FF2D for ; Fri, 5 Jan 2018 00:15:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8408E27813; Fri, 5 Jan 2018 00:15:26 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 16D0C1FF2D for ; Fri, 5 Jan 2018 00:15:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751239AbeAEAPM (ORCPT ); Thu, 4 Jan 2018 19:15:12 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:54999 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751108AbeAEAPM (ORCPT ); Thu, 4 Jan 2018 19:15:12 -0500 Received: from 79.184.254.214.ipv4.supernova.orange.pl (79.184.254.214) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.82) id 134f8969ac661087; Fri, 5 Jan 2018 01:15:10 +0100 From: "Rafael J. Wysocki" To: Linux PM , Linux PCI Cc: Tony Lindgren , "Rafael J. Wysocki" , JeffyChen , Linux Kernel Mailing List , Bjorn Helgaas , Shawn Lin , Brian Norris , Doug Anderson , Rob Herring , Frank Rowand Subject: [PATCH] PM / wakeup: Do not fail dev_pm_attach_wake_irq() unnecessarily Date: Fri, 05 Jan 2018 01:14:04 +0100 Message-ID: <1542734.kK7NjWylRh@aspire.rjw.lan> In-Reply-To: <6120485.xubBpvge6h@aspire.rjw.lan> References: <20171225114742.18920-1-jeffy.chen@rock-chips.com> <20171228165134.GH3875@atomide.com> <6120485.xubBpvge6h@aspire.rjw.lan> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafael J. Wysocki Returning an error code from dev_pm_attach_wake_irq() if device_wakeup_attach_irq() called by it returns an error is pointless, because the wakeup source used by it may be deleted by user space via sysfs at any time and in particular right after dev_pm_attach_wake_irq() has returned. Moreover, it requires the callers of dev_pm_attach_wake_irq() to create that wakeup source via device_wakeup_enable() upfront, but that obviously is racy with respect to the sysfs-based manipulations of it. To avoid the race, modify dev_pm_attach_wake_irq() to simply call device_wakeup_attach_irq() after checking that the wakeup source it is going to use is there (in which case it cannot fail) and set the power.wakeirq field for the device unconditionally. Tested-by: Tony Lindgren Signed-off-by: Rafael J. Wysocki --- drivers/base/power/wakeirq.c | 9 ++++----- drivers/base/power/wakeup.c | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) Index: linux-pm/drivers/base/power/wakeirq.c =================================================================== --- linux-pm.orig/drivers/base/power/wakeirq.c +++ linux-pm/drivers/base/power/wakeirq.c @@ -33,7 +33,6 @@ static int dev_pm_attach_wake_irq(struct struct wake_irq *wirq) { unsigned long flags; - int err; if (!dev || !wirq) return -EINVAL; @@ -45,12 +44,12 @@ static int dev_pm_attach_wake_irq(struct return -EEXIST; } - err = device_wakeup_attach_irq(dev, wirq); - if (!err) - dev->power.wakeirq = wirq; + dev->power.wakeirq = wirq; + if (dev->power.wakeup) + device_wakeup_attach_irq(dev, wirq); spin_unlock_irqrestore(&dev->power.lock, flags); - return err; + return 0; } /** Index: linux-pm/drivers/base/power/wakeup.c =================================================================== --- linux-pm.orig/drivers/base/power/wakeup.c +++ linux-pm/drivers/base/power/wakeup.c @@ -303,7 +303,7 @@ int device_wakeup_attach_irq(struct devi } if (ws->wakeirq) - return -EEXIST; + dev_err(dev, "Leftover wakeup IRQ found, overriding\n"); ws->wakeirq = wakeirq; return 0;