From patchwork Wed Jun 12 13:08:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 17830 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5C0E723903 for ; Wed, 12 Jun 2013 13:09:05 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id hu16sf641779qab.0 for ; Wed, 12 Jun 2013 06:09:05 -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=ES6FCV4hCoKH/1d7lEPGPN8iRFD7Qfuasu7eaUGGXv0=; b=iBRXrv1wDTgt3q51O5Dk4N764YwIRNWNSH4pSrcHc4qRouaPAQx6qU99DNOIq2TWTh Fs+KbfSc+OxpBSjIomsLwu47aE+28pCAqNixFKD0As3hekU88VVFp9reOPHwBRKDTYQa lrmDIkRpdkYz8GTsuNaDHYC47i3yWhJho4pYWjrXGLfVk51k8gDwleA3DAuShI75JFTQ uBB7kdZYxtDbZlUGxxxWYpMhV+eBWX3T4Xr2u6tdQ/pbJ3GZZkiTogAvDlkm++x1aCBz lk8pJLtf6sm7/5eela24cQQtiZldsNKqABF97H2wxthEtBHvFDgg1V2EBKGBe7ElxM9T wjvA== X-Received: by 10.236.194.33 with SMTP id l21mr7464948yhn.42.1371042545141; Wed, 12 Jun 2013 06:09:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.24.51 with SMTP id r19ls2394427qef.73.gmail; Wed, 12 Jun 2013 06:09:04 -0700 (PDT) X-Received: by 10.58.225.228 with SMTP id rn4mr9691909vec.35.1371042544817; Wed, 12 Jun 2013 06:09:04 -0700 (PDT) Received: from mail-vb0-x234.google.com (mail-vb0-x234.google.com [2607:f8b0:400c:c02::234]) by mx.google.com with ESMTPS id tq4si8586717vdc.1.2013.06.12.06.09.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Jun 2013 06:09:04 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::234 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:c02::234; Received: by mail-vb0-f52.google.com with SMTP id f12so5214583vbg.39 for ; Wed, 12 Jun 2013 06:09:04 -0700 (PDT) X-Received: by 10.52.53.36 with SMTP id y4mr8055789vdo.51.1371042544706; Wed, 12 Jun 2013 06:09:04 -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.58.191.99 with SMTP id gx3csp143393vec; Wed, 12 Jun 2013 06:09:04 -0700 (PDT) X-Received: by 10.181.12.1 with SMTP id em1mr4519268wid.4.1371042543742; Wed, 12 Jun 2013 06:09:03 -0700 (PDT) Received: from mail-wi0-x22d.google.com (mail-wi0-x22d.google.com [2a00:1450:400c:c05::22d]) by mx.google.com with ESMTPS id s3si859738wia.10.2013.06.12.06.09.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Jun 2013 06:09:03 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c05::22d is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=2a00:1450:400c:c05::22d; Received: by mail-wi0-f173.google.com with SMTP id hq4so459196wib.0 for ; Wed, 12 Jun 2013 06:09:03 -0700 (PDT) X-Received: by 10.194.84.74 with SMTP id w10mr12150085wjy.52.1371042543318; Wed, 12 Jun 2013 06:09:03 -0700 (PDT) Received: from mai.home (AToulouse-654-1-404-219.w82-125.abo.wanadoo.fr. [82.125.3.219]) by mx.google.com with ESMTPSA id x13sm24555864wib.3.2013.06.12.06.09.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Jun 2013 06:09:02 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl Cc: linux-pm@vger.kernel.org, linaro-kernel@lists.linaro.org, patches@linaro.org Subject: [PATCH 6/8] cpuidle: Encapsulate code in __cpuidle_unregister_device Date: Wed, 12 Jun 2013 15:08:53 +0200 Message-Id: <1371042535-22630-6-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1371042535-22630-1-git-send-email-daniel.lezcano@linaro.org> References: <1371042535-22630-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQk3jgMrjL5gZlmEm7v705xjyzVKTPDAQhozX7uDtadEoT2MC28Un4vfvI7KT9yBhNrQpoSL X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::234 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 this function. Signed-off-by: Daniel Lezcano --- drivers/cpuidle/cpuidle.c | 62 +++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 52ec46b..bdb7180 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 @@ -374,24 +381,15 @@ static int __cpuidle_register_device(struct cpuidle_device *dev) 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);