From patchwork Wed May 29 17:43:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 17275 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f199.google.com (mail-gg0-f199.google.com [209.85.161.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 30EF425D81 for ; Wed, 29 May 2013 17:43:48 +0000 (UTC) Received: by mail-gg0-f199.google.com with SMTP id q3sf10024662gge.2 for ; Wed, 29 May 2013 10:43:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=DOWn1tqHPoEQkuYXCrhOVyDsXDSdFZ5k4cWNBVl5BgI=; b=R5TAEkZyJLisrab9mi0JK5kDJtnYXWutQ6YWv0GenZR64f2IFgljvnInIQe9HqRpHw NsTpZ7V8tNyLfSuJy9cdQw5YK4ZLQgFRTPx1WTe39GA8Css1yjr9Kntcu/5u+vE15L4G crUPxw1jvAlOlwWqfymAwWxlZnv49e43WSYLfOABN771mk8+nAedYLcpqXB0Rq+U0ylr OMR/0S3vR1YTEowuUcbWDNF2pc5LSkQOZNNij68mRU1hNBN3r/763aFZcKs/yChO23f+ Ye7pYc5mNJsFvtf3zshfbXgTnbg9BGKOm7J1dpyaDJp053ENlKM+kOA2cNRiQdsUQvIK cVFg== X-Received: by 10.224.200.202 with SMTP id ex10mr2164343qab.8.1369849427912; Wed, 29 May 2013 10:43:47 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.134.8 with SMTP id pg8ls4111122qeb.43.gmail; Wed, 29 May 2013 10:43:47 -0700 (PDT) X-Received: by 10.58.144.231 with SMTP id sp7mr2332143veb.34.1369849427749; Wed, 29 May 2013 10:43:47 -0700 (PDT) Received: from mail-ve0-x22f.google.com (mail-ve0-x22f.google.com [2607:f8b0:400c:c01::22f]) by mx.google.com with ESMTPS id zp6si22255403vdb.15.2013.05.29.10.43.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 May 2013 10:43:47 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22f is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22f; Received: by mail-ve0-f175.google.com with SMTP id da11so2484961veb.6 for ; Wed, 29 May 2013 10:43:47 -0700 (PDT) X-Received: by 10.52.34.114 with SMTP id y18mr1984277vdi.56.1369849427624; Wed, 29 May 2013 10:43:47 -0700 (PDT) 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.220.229.199 with SMTP id jj7csp22133vcb; Wed, 29 May 2013 10:43:47 -0700 (PDT) X-Received: by 10.14.47.73 with SMTP id s49mr5111223eeb.113.1369849426523; Wed, 29 May 2013 10:43:46 -0700 (PDT) Received: from mail-we0-x22c.google.com (mail-we0-x22c.google.com [2a00:1450:400c:c03::22c]) by mx.google.com with ESMTPS id v46si21548802een.257.2013.05.29.10.43.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 May 2013 10:43:46 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::22c is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=2a00:1450:400c:c03::22c; Received: by mail-we0-f172.google.com with SMTP id w62so6687957wes.3 for ; Wed, 29 May 2013 10:43:46 -0700 (PDT) X-Received: by 10.180.160.206 with SMTP id xm14mr15930154wib.50.1369849426008; Wed, 29 May 2013 10:43:46 -0700 (PDT) Received: from mai.home (AToulouse-654-1-324-164.w86-199.abo.wanadoo.fr. [86.199.211.164]) by mx.google.com with ESMTPSA id cw8sm32657116wib.7.2013.05.29.10.43.44 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 May 2013 10:43:44 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl Cc: linux-pm@lists.linux-foundation.org, patches@linaro.org, linaro-kernel@lists.linaro.org Subject: [PATCH 5/7] cpuidle: encapsulate code in __cpuidle_unregister_device Date: Wed, 29 May 2013 19:43:32 +0200 Message-Id: <1369849414-7761-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1369849414-7761-1-git-send-email-daniel.lezcano@linaro.org> References: <1369849414-7761-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQlwwh06d9r0zENvnlVDOPiGlzJiArCI2b02VrYgMzyB4C5U8DU+/ecLQoBxbHgGrgpDRuCd X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22f is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 same code is used at different places. Group the common code into a single functions and call the function. Signed-off-by: Daniel Lezcano --- drivers/cpuidle/cpuidle.c | 64 +++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index f359bcb..8957ca5 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -42,8 +42,6 @@ void disable_cpuidle(void) off = 1; } -static int __cpuidle_register_device(struct cpuidle_device *dev); - /** * cpuidle_play_dead - cpu off-lining * @@ -357,6 +355,15 @@ void cpuidle_disable_device(struct cpuidle_device *dev) EXPORT_SYMBOL_GPL(cpuidle_disable_device); +static void __cpuidle_unregister_device(struct cpuidle_device *dev) +{ + struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); + + list_del(&dev->device_list); + per_cpu(cpuidle_devices, dev->cpu) = NULL; + module_put(drv->owner); +} + /** * __cpuidle_register_device - internal register function called before register * and enable routines @@ -366,32 +373,23 @@ EXPORT_SYMBOL_GPL(cpuidle_disable_device); */ static int __cpuidle_register_device(struct cpuidle_device *dev) { - int ret; struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); + int ret; if (!try_module_get(drv->owner)) return -EINVAL; per_cpu(cpuidle_devices, dev->cpu) = dev; list_add(&dev->device_list, &cpuidle_detected_devices); - ret = cpuidle_add_sysfs(dev); - if (ret) - goto err_sysfs; ret = cpuidle_coupled_register_device(dev); - if (ret) - goto err_coupled; + if (ret) { + __cpuidle_unregister_device(dev); + return ret; + } dev->registered = 1; return 0; - -err_coupled: - cpuidle_remove_sysfs(dev); -err_sysfs: - list_del(&dev->device_list); - per_cpu(cpuidle_devices, dev->cpu) = NULL; - module_put(drv->owner); - return ret; } /** @@ -407,22 +405,30 @@ int cpuidle_register_device(struct cpuidle_device *dev) mutex_lock(&cpuidle_lock); - if ((ret = __cpuidle_register_device(dev))) { - mutex_unlock(&cpuidle_lock); - return ret; - } + ret = __cpuidle_register_device(dev); + if (ret) + goto out_unlock; + + ret = cpuidle_add_sysfs(dev); + if (ret) + goto out_unregister; ret = cpuidle_enable_device(dev); - if (ret) { - mutex_unlock(&cpuidle_lock); - return ret; - } + if (ret) + goto out_sysfs; cpuidle_install_idle_handler(); +out_unlock: mutex_unlock(&cpuidle_lock); - return 0; + return ret; + +out_sysfs: + cpuidle_remove_sysfs(dev); +out_unregister: + __cpuidle_unregister_device(dev); + goto out_unlock; } EXPORT_SYMBOL_GPL(cpuidle_register_device); @@ -433,8 +439,6 @@ EXPORT_SYMBOL_GPL(cpuidle_register_device); */ void cpuidle_unregister_device(struct cpuidle_device *dev) { - struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); - if (dev->registered == 0) return; @@ -443,14 +447,12 @@ void cpuidle_unregister_device(struct cpuidle_device *dev) cpuidle_disable_device(dev); cpuidle_remove_sysfs(dev); - list_del(&dev->device_list); - per_cpu(cpuidle_devices, dev->cpu) = NULL; + + __cpuidle_unregister_device(dev); cpuidle_coupled_unregister_device(dev); cpuidle_resume_and_unlock(); - - module_put(drv->owner); } EXPORT_SYMBOL_GPL(cpuidle_unregister_device);