From patchwork Fri Oct 4 15:07:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11174837 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 362791747 for ; Fri, 4 Oct 2019 15:08:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B1FD222C2 for ; Fri, 4 Oct 2019 15:08:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570201680; bh=/KV5I5DAghrskNH9QDWgNaeNLl+MrlIiwz5apfW4Vrg=; h=From:To:Subject:Date:List-ID:From; b=FrbHPwcE5X/UWK6ze0apvVpZnYhabDwGWHVaL7j30UmDSlqE41xw+aizwR74VTlle gEFyuKXpSnWOUYSOHnieewuUmKzIPy3DHnZjRHCjEDAmckDq9aSnmo8w0/nYB7aU/q EydqJe9G/ztsYHuaWSF1db/uRrEtIb7Z6HF7rd7U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389196AbfJDPHr (ORCPT ); Fri, 4 Oct 2019 11:07:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:50348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388802AbfJDPHq (ORCPT ); Fri, 4 Oct 2019 11:07:46 -0400 Received: from localhost.localdomain (unknown [194.230.155.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1AB92207FF; Fri, 4 Oct 2019 15:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570201666; bh=/KV5I5DAghrskNH9QDWgNaeNLl+MrlIiwz5apfW4Vrg=; h=From:To:Subject:Date:From; b=OGWg8NtvNyerybT+VfuS22mipc6Oq+DcD1Z8b/NRsfgNtU+fi5fFNWhlzLyLr4abK zcEUcMR0ODI6gine4L3mMTJiPnQlvO9Tb7aumA5IrUBoDCICHdx7W3waD0UV0sTKr6 I44zsBDOCS3Ya+4oGQmhNliofFEwAkYvvR2GW4sY= From: Krzysztof Kozlowski To: Sebastian Reichel , Krzysztof Kozlowski , "Gustavo A. R. Silva" , Linus Walleij , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFT 1/3] power: supply: ab8500: Cleanup probe in reverse order Date: Fri, 4 Oct 2019 17:07:36 +0200 Message-Id: <20191004150738.6542-1-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org It is logical to cleanup in probe's error path in reverse order to previous actions. It also makes easier to add additional goto labels within this error path. Signed-off-by: Krzysztof Kozlowski Acked-by: Linus Walleij --- Not marking as cc-stable as this was not reproduced and not tested. --- drivers/power/supply/ab8500_btemp.c | 4 ++-- drivers/power/supply/ab8500_fg.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c index 8fe81259bfd9..a167938e32f2 100644 --- a/drivers/power/supply/ab8500_btemp.c +++ b/drivers/power/supply/ab8500_btemp.c @@ -1104,13 +1104,13 @@ static int ab8500_btemp_probe(struct platform_device *pdev) return ret; free_irq: - power_supply_unregister(di->btemp_psy); - /* We also have to free all successfully registered irqs */ for (i = i - 1; i >= 0; i--) { irq = platform_get_irq_byname(pdev, ab8500_btemp_irq[i].name); free_irq(irq, di); } + + power_supply_unregister(di->btemp_psy); free_btemp_wq: destroy_workqueue(di->btemp_wq); return ret; diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 6fc4bc30644c..36bbb8ea05da 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -3212,15 +3212,15 @@ static int ab8500_fg_probe(struct platform_device *pdev) return ret; free_irq: - power_supply_unregister(di->fg_psy); - /* We also have to free all registered irqs */ + irq = platform_get_irq_byname(pdev, ab8500_fg_irq_bh[0].name); + free_irq(irq, di); for (i = 0; i < ARRAY_SIZE(ab8500_fg_irq_th); i++) { irq = platform_get_irq_byname(pdev, ab8500_fg_irq_th[i].name); free_irq(irq, di); } - irq = platform_get_irq_byname(pdev, ab8500_fg_irq_bh[0].name); - free_irq(irq, di); + + power_supply_unregister(di->fg_psy); free_inst_curr_wq: destroy_workqueue(di->fg_wq); return ret; From patchwork Fri Oct 4 15:07:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11174833 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9748C1599 for ; Fri, 4 Oct 2019 15:07:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 75872222C9 for ; Fri, 4 Oct 2019 15:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570201671; bh=qYioEzDmICb0pDIcd2sao32iGGG/DdI1z0g1uD+bG7w=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=c4rspyAkyuSsW+t4xd6SdGBBDKwAzXwbt94+lg4GrloxTJVBnbam5BalIinYi372L Os24ohjkPH1JRmqAjRKiR6dSF5uWq+q3lsRAEfQnso3RX0cs1I/vxJ/PW99nfABKPQ OeTcyjZR3TNnfbNfcCG2l1oakxPe+fT0Njult7+o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389312AbfJDPHu (ORCPT ); Fri, 4 Oct 2019 11:07:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:50402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388802AbfJDPHt (ORCPT ); Fri, 4 Oct 2019 11:07:49 -0400 Received: from localhost.localdomain (unknown [194.230.155.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F257521D81; Fri, 4 Oct 2019 15:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570201668; bh=qYioEzDmICb0pDIcd2sao32iGGG/DdI1z0g1uD+bG7w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QxMOULfhqAHILdyIZyGrilDN3NMOHFLVFs1DQK2m3A3Kgc53Sy9lrgf6WfAxseFC7 z/lVWyJmrLK/sgW43+7YUZGRN5UNjWPy69Cgt2uB4Pdv/a3PxmdjvZmBIc5ZgVPMqg 1nZLHnCqZVXtqEkiGjZZ4X0sMtIH74tEyFJS6YWA= From: Krzysztof Kozlowski To: Sebastian Reichel , Krzysztof Kozlowski , "Gustavo A. R. Silva" , Linus Walleij , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFT 2/3] power: supply: ab8500_fg: Do not free non-requested IRQs in probe's error path Date: Fri, 4 Oct 2019 17:07:37 +0200 Message-Id: <20191004150738.6542-2-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191004150738.6542-1-krzk@kernel.org> References: <20191004150738.6542-1-krzk@kernel.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When requesting interrupt fails, free only interrupts already requested, not all of them. Signed-off-by: Krzysztof Kozlowski --- Not marking as cc-stable as this was not reproduced and not tested. --- drivers/power/supply/ab8500_fg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 36bbb8ea05da..7d879589adc2 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -3158,7 +3158,7 @@ static int ab8500_fg_probe(struct platform_device *pdev) if (ret != 0) { dev_err(di->dev, "failed to request %s IRQ %d: %d\n", ab8500_fg_irq_th[i].name, irq, ret); - goto free_irq; + goto free_irq_th; } dev_dbg(di->dev, "Requested %s IRQ %d: %d\n", ab8500_fg_irq_th[i].name, irq, ret); @@ -3173,7 +3173,7 @@ static int ab8500_fg_probe(struct platform_device *pdev) if (ret != 0) { dev_err(di->dev, "failed to request %s IRQ %d: %d\n", ab8500_fg_irq_bh[0].name, irq, ret); - goto free_irq; + goto free_irq_th; } dev_dbg(di->dev, "Requested %s IRQ %d: %d\n", ab8500_fg_irq_bh[0].name, irq, ret); @@ -3215,7 +3215,9 @@ static int ab8500_fg_probe(struct platform_device *pdev) /* We also have to free all registered irqs */ irq = platform_get_irq_byname(pdev, ab8500_fg_irq_bh[0].name); free_irq(irq, di); - for (i = 0; i < ARRAY_SIZE(ab8500_fg_irq_th); i++) { +free_irq_th: + while (--i >= 0) { + /* Last assignment of i from primary interrupt handlers */ irq = platform_get_irq_byname(pdev, ab8500_fg_irq_th[i].name); free_irq(irq, di); } From patchwork Fri Oct 4 15:07:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11174835 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD53E112B for ; Fri, 4 Oct 2019 15:07:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAF0A222C2 for ; Fri, 4 Oct 2019 15:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570201679; bh=QJNtgzf3I7MaqgTwW24kwXRCqf/tm/P6Sh5Bo/9VnwA=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=dhYQKEaCLM3Z3xJ3UzjneTCm6bOkwws0KT02a4/dz0//+A3pSZ7VBmfhpU61OkSAF nd0nUlDsXK/15LgLDlzsl/ovQTbiw4CLJ0/nVJLWUD/1ArkhJR/kO5+Yn9sfagbKwz bSdUj8QVAZk6PTFP4TNWol4pYu/Iaa9g9/IzXR3I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389320AbfJDPHy (ORCPT ); Fri, 4 Oct 2019 11:07:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:50480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388802AbfJDPHw (ORCPT ); Fri, 4 Oct 2019 11:07:52 -0400 Received: from localhost.localdomain (unknown [194.230.155.145]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 693762133F; Fri, 4 Oct 2019 15:07:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570201671; bh=QJNtgzf3I7MaqgTwW24kwXRCqf/tm/P6Sh5Bo/9VnwA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=2UDp5dGGX/8FZNXAiEEBqoJAFgg5033UO0O6fs41817qSowaRVAFmPLAoNAzdNUfA kMA/TAU/YvtqPXUVIgec3b6V5kJLk80ctVeIpX8TdaF00KqX8iJkt5/+xsHnISBlRU nBhxCvmbyupeqamN5SvFZLpmyDrbtTJzKOJqLNak= From: Krzysztof Kozlowski To: Sebastian Reichel , Krzysztof Kozlowski , "Gustavo A. R. Silva" , Linus Walleij , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFT 3/3] power: supply: ab8500: Handle invalid IRQ from platform_get_irq_byname() Date: Fri, 4 Oct 2019 17:07:38 +0200 Message-Id: <20191004150738.6542-3-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191004150738.6542-1-krzk@kernel.org> References: <20191004150738.6542-1-krzk@kernel.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org platform_get_irq_byname() might return -errno which later would be cast to an unsigned int and used in request_irq(). Signed-off-by: Krzysztof Kozlowski --- Not marking as cc-stable as this was not reproduced and not tested. --- drivers/power/supply/ab8500_btemp.c | 5 +++++ drivers/power/supply/ab8500_charger.c | 5 +++++ drivers/power/supply/ab8500_fg.c | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c index a167938e32f2..cfd8152bf8fc 100644 --- a/drivers/power/supply/ab8500_btemp.c +++ b/drivers/power/supply/ab8500_btemp.c @@ -1082,6 +1082,11 @@ static int ab8500_btemp_probe(struct platform_device *pdev) /* Register interrupts */ for (i = 0; i < ARRAY_SIZE(ab8500_btemp_irq); i++) { irq = platform_get_irq_byname(pdev, ab8500_btemp_irq[i].name); + if (irq < 0) { + ret = irq; + goto free_irq; + } + ret = request_threaded_irq(irq, NULL, ab8500_btemp_irq[i].isr, IRQF_SHARED | IRQF_NO_SUSPEND, ab8500_btemp_irq[i].name, di); diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c index e51d0e72beea..7ad23df6f75a 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -3556,6 +3556,11 @@ static int ab8500_charger_probe(struct platform_device *pdev) /* Register interrupts */ for (i = 0; i < ARRAY_SIZE(ab8500_charger_irq); i++) { irq = platform_get_irq_byname(pdev, ab8500_charger_irq[i].name); + if (irq < 0) { + ret = irq; + goto free_irq; + } + ret = request_threaded_irq(irq, NULL, ab8500_charger_irq[i].isr, IRQF_SHARED | IRQF_NO_SUSPEND, ab8500_charger_irq[i].name, di); diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 7d879589adc2..01f3da103813 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -3151,6 +3151,11 @@ static int ab8500_fg_probe(struct platform_device *pdev) /* Register primary interrupt handlers */ for (i = 0; i < ARRAY_SIZE(ab8500_fg_irq_th); i++) { irq = platform_get_irq_byname(pdev, ab8500_fg_irq_th[i].name); + if (irq < 0) { + ret = irq; + goto free_irq_th; + } + ret = request_irq(irq, ab8500_fg_irq_th[i].isr, IRQF_SHARED | IRQF_NO_SUSPEND, ab8500_fg_irq_th[i].name, di); @@ -3166,6 +3171,11 @@ static int ab8500_fg_probe(struct platform_device *pdev) /* Register threaded interrupt handler */ irq = platform_get_irq_byname(pdev, ab8500_fg_irq_bh[0].name); + if (irq < 0) { + ret = irq; + goto free_irq_th; + } + ret = request_threaded_irq(irq, NULL, ab8500_fg_irq_bh[0].isr, IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT, ab8500_fg_irq_bh[0].name, di);