From patchwork Mon Sep 4 06:52:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 111532 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1147274qge; Sun, 3 Sep 2017 23:52:37 -0700 (PDT) X-Received: by 10.98.130.193 with SMTP id w184mr10543321pfd.218.1504507957089; Sun, 03 Sep 2017 23:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504507957; cv=none; d=google.com; s=arc-20160816; b=SgSBpXYYD/R4WcnxhFe+Z2qZ+yZwgsDnP6aFmB0byr3F46Lze7UTSkvKcSO0JRYlRX JOd3cATRmKC3JkIJa8aBTUottcvQiIq0Febz5g49kX39rfr7zya8NIA0FakqkU38LQCJ gdESuTB+bb0Yt0dFwHLe753//oGXf6mBvgOKZc2NZRM5VpVYFSUIOqMwNcj4k+sBjFY/ 5xcUe7t1xOxcPNcUkmGJV9UKqH0mZKUeXG+h/FyjRaWTUhT/rfgS8JQ8or2klxht2RAB Y3zcsZ36UFot9qBNhKn/OWsQ0EmrtYWKwEbFBGqcfau+2fZc849y8d+/UH3F1fT3UaQC 6NfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=SfEEtN2Kg06DHI0nmRFVnEkU6eYwlpL2c4UGs2S467M=; b=kVjiG2SOdrPivVn0SsThaBVDJD22uVGZZT4RrOK5Fnz76dt0dHkisY/DTQiezJM2NT 0qZZj3elyk/Ty2AO2KTDr1O6WdHNnP94RHYNjdquR0Vt6RT8nTbqItA7ApHPtcoPYAM+ gYH8Hma6a8OSld/Rr9wTAPkMVCav6UdIFc77lrP1uo8kGKQBPK1kP/BhUFpleA81T3vt 4yMov7ejLnkHux0umvnQUv2L9fbAeZ7/eDKH31m6nS5caishJFxxcN/zQDisKuoFHYRJ 4YDR2wcHkVG3tYJhtxQoTScwGYGnf5Y/yr/s/USZ+E1S8xoQve3UmZSag/pDHTWEFcrI CyGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YYwNHu7S; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 90si4912704plb.338.2017.09.03.23.52.36; Sun, 03 Sep 2017 23:52:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YYwNHu7S; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751949AbdIDGwf (ORCPT + 12 others); Mon, 4 Sep 2017 02:52:35 -0400 Received: from mail-pg0-f50.google.com ([74.125.83.50]:36393 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751151AbdIDGwe (ORCPT ); Mon, 4 Sep 2017 02:52:34 -0400 Received: by mail-pg0-f50.google.com with SMTP id r133so16343382pgr.3 for ; Sun, 03 Sep 2017 23:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=SfEEtN2Kg06DHI0nmRFVnEkU6eYwlpL2c4UGs2S467M=; b=YYwNHu7SRf143tynzS4lD44h+DdUnGSyZxvMkmEmDiYt3a3B0g5zqUibZxXqjISipE Gm666EuHrBTtgHlxxNhSerUfKgc4fy/NA0+qiQgNxGGvhIKA5L45zQfaGnbJDmusGP/q 6ho00rtgyE7LejEzM5xEEyzIIKuZblBYb2OOk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SfEEtN2Kg06DHI0nmRFVnEkU6eYwlpL2c4UGs2S467M=; b=lLz4dNTuxnEeQZHCHQE4skSIo2p89fJZStH9ZAk1rxczbSJMXiY+ljDkifOgvlTkqW WdhKPXfN0BqTWEa+3YbvwlxgwYT3OZrsKmxs/YumzQeSUxXuDZ6NST0P/Gzr2E084p0/ hZ/dEeORMzixBBTbVqS172W9gwfNA3proI2jz3T4RQM8BswPL9FCwWTuBT0cfNoYPsCW F8/XRXBpGs0HaJKf62KVgvCZ3NNHDaNRmtH2HZCdWK9n95omba/weByZXmzufq1ZUAu1 iM0wradWDL75ChwTaqWfvk0f9Eyn2RUu9p2KtF8e++LdzE8nNMnoXVgtyvg81CFyEJ4r pB2g== X-Gm-Message-State: AHPjjUiN48+P3iPFATqAoFK8B2kj1czICFPRYQWjma1Ix7MIocQtUzjI ylOOFKcfqGoqNVSJyQ9+5w== X-Google-Smtp-Source: ADKCNb6WktkrBM8UL4TgSwwcRL1DdTTEf6UAIXVR5O9w5TtrNkjWZZhQDeVezJ36u1GUJq5VSo35KQ== X-Received: by 10.98.71.14 with SMTP id u14mr10287052pfa.315.1504507954103; Sun, 03 Sep 2017 23:52:34 -0700 (PDT) Received: from localhost.localdomain (li1068-205.members.linode.com. [106.184.3.205]) by smtp.gmail.com with ESMTPSA id 73sm9792919pfu.3.2017.09.03.23.52.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Sep 2017 23:52:33 -0700 (PDT) From: Leo Yan To: "Rafael J. Wysocki" , Daniel Lezcano , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan , Stefan Wahren Subject: [PATCH 1/2] ARM: cpuidle: refine failure handling in init flow Date: Mon, 4 Sep 2017 14:52:13 +0800 Message-Id: <1504507934-14218-1-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org After applied Stefan Wahren patch ("ARM: cpuidle: Avoid memleak if init fail") there have no memleak issue, but the code is not consistent to handle initialization failure between driver registration and device registration. And when device registration fails, it misses to unregister the driver. So this patch is to refine failure handling in init flow, it adds two 'goto' tags: when register device fails, it goto 'init_dev_fail' tag and free 'dev' structure and unregister driver; when register driver fails, it goto 'init_drv_fail' tag and free 'drv' structure. Cc: Daniel Lezcano Cc: Stefan Wahren Signed-off-by: Leo Yan --- drivers/cpuidle/cpuidle-arm.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c index 52a7505..f419f6a 100644 --- a/drivers/cpuidle/cpuidle-arm.c +++ b/drivers/cpuidle/cpuidle-arm.c @@ -86,10 +86,13 @@ static int __init arm_idle_init(void) for_each_possible_cpu(cpu) { + drv = NULL; + dev = NULL; + drv = kmemdup(&arm_idle_driver, sizeof(*drv), GFP_KERNEL); if (!drv) { ret = -ENOMEM; - goto out_fail; + goto init_drv_fail; } drv->cpumask = (struct cpumask *)cpumask_of(cpu); @@ -104,13 +107,13 @@ static int __init arm_idle_init(void) ret = dt_init_idle_driver(drv, arm_idle_state_match, 1); if (ret <= 0) { ret = ret ? : -ENODEV; - goto init_fail; + goto init_drv_fail; } ret = cpuidle_register_driver(drv); if (ret) { pr_err("Failed to register cpuidle driver\n"); - goto init_fail; + goto init_drv_fail; } /* @@ -128,14 +131,14 @@ static int __init arm_idle_init(void) if (ret) { pr_err("CPU %d failed to init idle CPU ops\n", cpu); - goto out_fail; + goto init_dev_fail; } dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) { pr_err("Failed to allocate cpuidle device\n"); ret = -ENOMEM; - goto out_fail; + goto init_dev_fail; } dev->cpu = cpu; @@ -143,15 +146,19 @@ static int __init arm_idle_init(void) if (ret) { pr_err("Failed to register cpuidle device for CPU %d\n", cpu); - kfree(dev); - goto out_fail; + goto init_dev_fail; } } return 0; -init_fail: + +init_dev_fail: + kfree(dev); + cpuidle_unregister_driver(drv); + +init_drv_fail: kfree(drv); -out_fail: + while (--cpu >= 0) { dev = per_cpu(cpuidle_devices, cpu); cpuidle_unregister_device(dev);