From patchwork Mon Jun 22 07:31:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 6653691 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 154FFC05AD for ; Mon, 22 Jun 2015 07:31:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E6CE20511 for ; Mon, 22 Jun 2015 07:31:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43C012062F for ; Mon, 22 Jun 2015 07:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756105AbbFVHbe (ORCPT ); Mon, 22 Jun 2015 03:31:34 -0400 Received: from baptiste.telenet-ops.be ([195.130.132.51]:53614 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755995AbbFVHbd (ORCPT ); Mon, 22 Jun 2015 03:31:33 -0400 Received: from ayla.of.borg ([84.193.93.87]) by baptiste.telenet-ops.be with bizsmtp id jKXW1q0051t5w8s01KXW4v; Mon, 22 Jun 2015 09:31:31 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1Z6wCX-0006CQ-SZ; Mon, 22 Jun 2015 09:31:29 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1Z6wCZ-000789-OF; Mon, 22 Jun 2015 09:31:31 +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: Mon, 22 Jun 2015 09:31:22 +0200 Message-Id: <1434958282-27376-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434622954-26747-3-git-send-email-geert+renesas@glider.be> References: <1434622954-26747-3-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=-8.3 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 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index cdd547bd67df8218..60e0309dd8dd0264 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(); } @@ -2183,6 +2191,7 @@ int genpd_dev_pm_attach(struct device *dev) { struct of_phandle_args pd_args; struct generic_pm_domain *pd; + unsigned int i; int ret; if (!dev->of_node) @@ -2218,10 +2227,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(); }