From patchwork Tue Jan 27 20:13:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 43847 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f197.google.com (mail-we0-f197.google.com [74.125.82.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1B4A723FFF for ; Tue, 27 Jan 2015 20:14:38 +0000 (UTC) Received: by mail-we0-f197.google.com with SMTP id l61sf8820332wev.0 for ; Tue, 27 Jan 2015 12:14:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=TcAbKzVh6gjLKI/cOeH2McHHJw4EL7LE3i8/RfBcZwc=; b=XKaB2c4jDrXgfyE0WE9Jo3xId4iOOyo39GN86a8PBSKWzsSujyYUnohDUwxpZ8ARss HbZ9395WQK+MKFdzJMkpxKkk0mwUZl517TvusgUUbXRxNlVLJbxzcC4XcHpVOjRa4CYq zCkG5SfMZVFWY/MpRdwnsr8XmrXFYwE+GwXJD8zOlmoagJxYgzDuUOJbK3Hqlv0bIxJS e4pWBQHkW3wYYGVzj5TL926dN5XWopjOT7ogf1V9V3CJjBZ8a0wUk7TyYmozWFqyiq7a H4tlOMfn7wt9NKAx7q5egEfeTPeP4XwZFMW7f13HVeHnXHuo76FFZvqJ/yje++5UTUcu nOAw== X-Gm-Message-State: ALoCoQlpCZj84PbJO1TXH39AwoExvn0hNDHAPZuykndLdJcHeOIv40DjLc+DoBTLZrL1ZHyhaKNF X-Received: by 10.194.221.65 with SMTP id qc1mr521069wjc.7.1422389677406; Tue, 27 Jan 2015 12:14:37 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.132 with SMTP id n4ls85927lae.6.gmail; Tue, 27 Jan 2015 12:14:37 -0800 (PST) X-Received: by 10.112.119.201 with SMTP id kw9mr3781195lbb.99.1422389677254; Tue, 27 Jan 2015 12:14:37 -0800 (PST) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id uk4si2270581lbb.68.2015.01.27.12.14.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 12:14:37 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id hv19so15244593lab.13 for ; Tue, 27 Jan 2015 12:14:37 -0800 (PST) X-Received: by 10.152.44.228 with SMTP id h4mr3911149lam.31.1422389677180; Tue, 27 Jan 2015 12:14:37 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1213884lbj; Tue, 27 Jan 2015 12:14:36 -0800 (PST) X-Received: by 10.112.170.36 with SMTP id aj4mr3897802lbc.3.1422389657888; Tue, 27 Jan 2015 12:14:17 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id n8si2302876lbc.28.2015.01.27.12.14.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 12:14:17 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id p9so15124955lbv.4 for ; Tue, 27 Jan 2015 12:14:17 -0800 (PST) X-Received: by 10.112.12.134 with SMTP id y6mr4001739lbb.34.1422389657592; Tue, 27 Jan 2015 12:14:17 -0800 (PST) Received: from uffe-Latitude-E6430s.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id ya4sm713470lbb.32.2015.01.27.12.14.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jan 2015 12:14:16 -0800 (PST) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Kevin Hilman , linux-pm@vger.kernel.org Cc: Geert Uytterhoeven , Dmitry Torokhov , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Ulf Hansson Subject: [PATCH 6/8] PM / Domains: Free pm_subsys_data in error path in __pm_genpd_add_device() Date: Tue, 27 Jan 2015 21:13:43 +0100 Message-Id: <1422389625-11730-7-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422389625-11730-1-git-send-email-ulf.hansson@linaro.org> References: <1422389625-11730-1-git-send-email-ulf.hansson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The error path in __pm_genpd_add_device() didn't decrease the reference to the struct pm_subsys_data. Let's move the calls to dev_pm_get|put_subsys_data() into genpd_alloc|free_dev_data() to fix this issue and thus prevent a potential memory leakage. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 1f026c1..3bd342f 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1380,18 +1380,30 @@ EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweron); static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev) { struct generic_pm_domain_data *gpd_data; + int ret; + + ret = dev_pm_get_subsys_data(dev); + if (ret) + return ERR_PTR(ret); gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL); - if (!gpd_data) - return NULL; + if (!gpd_data) { + ret = -ENOMEM; + goto err_put; + } return gpd_data; + + err_put: + dev_pm_put_subsys_data(dev); + return ERR_PTR(ret); } static void genpd_free_dev_data(struct device *dev, struct generic_pm_domain_data *gpd_data) { kfree(gpd_data); + dev_pm_put_subsys_data(dev); } /** @@ -1412,8 +1424,8 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, return -EINVAL; gpd_data = genpd_alloc_dev_data(dev); - if (!gpd_data) - return -ENOMEM; + if (IS_ERR(gpd_data)) + return PTR_ERR(gpd_data); genpd_acquire_lock(genpd); @@ -1422,10 +1434,6 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, goto out; } - ret = dev_pm_get_subsys_data(dev); - if (ret) - goto out; - spin_lock_irq(&dev->power.lock); if (dev->power.subsys_data->domain_data) { @@ -1528,7 +1536,6 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, genpd_release_lock(genpd); - dev_pm_put_subsys_data(dev); genpd_free_dev_data(dev, gpd_data); return 0;