From patchwork Thu Jun 5 03:46:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonghwa Lee X-Patchwork-Id: 4300821 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AB7E8BEEA7 for ; Thu, 5 Jun 2014 03:46:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D5920202F2 for ; Thu, 5 Jun 2014 03:46:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D922420254 for ; Thu, 5 Jun 2014 03:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751140AbaFEDqa (ORCPT ); Wed, 4 Jun 2014 23:46:30 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:49756 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751667AbaFEDq3 (ORCPT ); Wed, 4 Jun 2014 23:46:29 -0400 Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N6O00JAGFTCWU30@mailout3.samsung.com> for linux-pm@vger.kernel.org; Thu, 05 Jun 2014 12:46:24 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.116]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id CF.91.19452.018EF835; Thu, 05 Jun 2014 12:46:24 +0900 (KST) X-AuditID: cbfee68e-b7fb96d000004bfc-da-538fe810d715 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 8B.E4.07139.018EF835; Thu, 05 Jun 2014 12:46:24 +0900 (KST) Received: from localhost.localdomain ([10.252.82.199]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N6O00GKOFT9N2Q0@mmp2.samsung.com>; Thu, 05 Jun 2014 12:46:24 +0900 (KST) From: Jonghwa Lee To: linux-pm@vger.kernel.org Cc: dbaryshkov@gmail.com, dwmw2@infradead.org, Tomasz Figa Subject: [PATCH 3/4] power: max17042_battery: Fix deadlock caused by deferred initialization Date: Thu, 05 Jun 2014 12:46:16 +0900 Message-id: <1401939977-20328-4-git-send-email-jonghwa3.lee@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1401939977-20328-1-git-send-email-jonghwa3.lee@samsung.com> References: <1401939977-20328-1-git-send-email-jonghwa3.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrALMWRmVeSWpSXmKPExsWyRsSkRFfgRX+wwcdHphaTnrxntpi4cjKz xefeI4wW62e8ZnFg8dg56y67x+YVWh59W1YxenzeJBfAEsVlk5Kak1mWWqRvl8CVsXZqD2vB bfGKlp+7WRoY9wh3MXJwSAiYSLw8wNfFyAlkiklcuLeerYuRi0NIYCmjxLWF95ghEiYSd3vO skIkpjNK9B/8yg7htDFJnPy/nx2kik1AR+L/vptgtoiAjMTUK/tZQWxmAX+JTfs3gMWFBeIk fk3fB2azCKhKbHjzlAXE5hXwkDj87Bk7xEUKEnMm2YCEOQU8Jb78OssGYgsBlfTv/MkEsldC 4DebxK+DB1gh5ghIfJt8iAWiV1Zi0wGooyUlDq64wTKBUXgBI8MqRtHUguSC4qT0IiO94sTc 4tK8dL3k/NxNjMDQPf3vWd8OxpsHrA8xJgONm8gsJZqcDwz9vJJ4Q2MzIwtTE1NjI3NLM9KE lcR5Fz1MChISSE8sSc1OTS1ILYovKs1JLT7EyMTBKdXAmLR9+b5U2YauotuWMtcC3l2beI1D NT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loop: Reflected Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.5 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 From: Tomasz Figa There is no need to defer chip initialization from probe. In addition, current implementation caused a deadlock, which made boot hang from time to time. This patch removes deffered initialization and adds chip initialization to probe, before the power supply is registered. Signed-off-by: Tomasz Figa Acked-by: Jonghwa Lee Acked-by: MyungJoo Ham --- drivers/power/max17042_battery.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c index cee3912..0178a32 100644 --- a/drivers/power/max17042_battery.c +++ b/drivers/power/max17042_battery.c @@ -76,8 +76,6 @@ struct max17042_chip { enum max170xx_chip_type chip_type; enum max17042_operation_mode mode; struct max17042_platform_data *pdata; - struct work_struct work; - int init_complete; }; static enum power_supply_property max17042_battery_props[] = { @@ -108,9 +106,6 @@ static int max17042_get_property(struct power_supply *psy, int ret; u32 data; - if (!chip->init_complete) - return -EAGAIN; - switch (psp) { case POWER_SUPPLY_PROP_PRESENT: ret = regmap_read(map, MAX17042_STATUS, &data); @@ -609,7 +604,7 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) return IRQ_HANDLED; } -static void max17042_init_worker(struct work_struct *work) +static int max17042_init_worker(struct max17042_chip *chip) { struct max17042_chip *chip = container_of(work, struct max17042_chip, work); @@ -619,10 +614,10 @@ static void max17042_init_worker(struct work_struct *work) if (chip->pdata->enable_por_init && chip->pdata->config_data) { ret = max17042_init_chip(chip); if (ret) - return; + return ret; } - chip->init_complete = 1; + return 0; } #ifdef CONFIG_OF @@ -738,12 +733,6 @@ static int max17042_probe(struct i2c_client *client, chip->pdata->init_data[i].addr, chip->pdata->init_data[i].data); - ret = power_supply_register(&client->dev, &chip->battery); - if (ret) { - dev_err(&client->dev, "failed: power supply register\n"); - return ret; - } - if (client->irq) { ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, max17042_thread_handler, @@ -763,10 +752,17 @@ static int max17042_probe(struct i2c_client *client, regmap_read(chip->regmap, MAX17042_STATUS, &val); if (val & STATUS_POR_BIT) { - INIT_WORK(&chip->work, max17042_init_worker); - schedule_work(&chip->work); - } else { - chip->init_complete = 1; + ret = max17042_init_worker(chip); + if (ret) { + dev_err(&client->dev, "failed: init chip\n"); + return ret; + } + } + + ret = power_supply_register(&client->dev, &chip->battery); + if (ret) { + dev_err(&client->dev, "failed: power supply register\n"); + return ret; } return 0;