From patchwork Thu Jun 18 10:22:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 6635031 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1AA0D9F1C1 for ; Thu, 18 Jun 2015 10:22:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3576D2064C for ; Thu, 18 Jun 2015 10:22:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 40B0420687 for ; Thu, 18 Jun 2015 10:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755116AbbFRKWp (ORCPT ); Thu, 18 Jun 2015 06:22:45 -0400 Received: from xavier.telenet-ops.be ([195.130.132.52]:57230 "EHLO xavier.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754162AbbFRKWm (ORCPT ); Thu, 18 Jun 2015 06:22:42 -0400 Received: from ayla.of.borg ([84.193.93.87]) by xavier.telenet-ops.be with bizsmtp id hmNf1q00e1t5w8s01mNfTs; Thu, 18 Jun 2015 12:22:41 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1Z5Wxz-0004xH-Dp; Thu, 18 Jun 2015 12:22:39 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1Z5Wy0-0006yC-IM; Thu, 18 Jun 2015 12:22:40 +0200 From: Geert Uytterhoeven To: Daniel Lezcano , Thomas Gleixner , "Rafael J. Wysocki" , Kevin Hilman , Ulf Hansson Cc: Magnus Damm , Laurent Pinchart , linux-pm@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/2] PM / Domains: Avoid infinite loops in attach/detach code Date: Thu, 18 Jun 2015 12:22:34 +0200 Message-Id: <1434622954-26747-3-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434622954-26747-1-git-send-email-geert+renesas@glider.be> References: <1434622954-26747-1-git-send-email-geert+renesas@glider.be> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If pm_genpd_{add,remove}_device() keeps on failing with -EAGAIN, we end up with an infinite loop in genpd_dev_pm_{at,de}tach(). This may happen due to a genpd.prepared_count imbalance. This is a bug elsewhere, but it will result in a system lock up, possibly during reboot of an otherwise functioning system. To avoid this, put a limit on the maximum number of loop iterations, including a simple back-off mechanism. If the limit is reached, the operation will just fail. An error message is already printed. Signed-off-by: Geert Uytterhoeven --- drivers/base/power/domain.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index cdd547bd67df8218..aa06f60b98b8af35 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -6,6 +6,7 @@ * This file is released under the GPLv2. */ +#include #include #include #include @@ -19,6 +20,9 @@ #include #include +#define GENPD_RETRIES 20 +#define GENPD_DELAY_US 10 + #define GENPD_DEV_CALLBACK(genpd, type, callback, dev) \ ({ \ type (*__routine)(struct device *__d); \ @@ -2131,6 +2135,7 @@ EXPORT_SYMBOL_GPL(of_genpd_get_from_provider); static void genpd_dev_pm_detach(struct device *dev, bool power_off) { struct generic_pm_domain *pd; + unsigned int i; int ret = 0; pd = pm_genpd_lookup_dev(dev); @@ -2139,10 +2144,13 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off) dev_dbg(dev, "removing from PM domain %s\n", pd->name); - while (1) { + for (i = 0; i < GENPD_RETRIES; i++) { ret = pm_genpd_remove_device(pd, dev); if (ret != -EAGAIN) break; + + if (i > GENPD_RETRIES / 2) + udelay(GENPD_DELAY_US); cond_resched(); } @@ -2218,10 +2226,13 @@ int genpd_dev_pm_attach(struct device *dev) dev_dbg(dev, "adding to PM domain %s\n", pd->name); - while (1) { + for (i = 0; i < GENPD_RETRIES; i++) { ret = pm_genpd_add_device(pd, dev); if (ret != -EAGAIN) break; + + if (i > GENPD_RETRIES / 2) + udelay(GENPD_DELAY_US); cond_resched(); }