From patchwork Fri Oct 19 10:10:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12365 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D91EE23F58 for ; Fri, 19 Oct 2012 10:10:59 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 8DE11A18744 for ; Fri, 19 Oct 2012 10:10:59 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so335119iej.11 for ; Fri, 19 Oct 2012 03:10:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=8mABF11CNYjRCoOBYE6sCjTiKSTdDNSKQLsPFz2Aqq0=; b=OYziv8uL5rTE+4DXhmOAXwPCWDaH4fFv665Lxs3jUfCVCBYABDGUHwMxx7xUXbxh67 FV0UuQLKIRl0VToIjf/kjJm6pIUVndBiqBh8gG2jp87Ohw66vlHxyFiyj1QnBS7h/d2M GgKf6QCdMgE4eq2ubta/XGiSDY7ZI9Q8uO2rmVJuSNUieiEoMMsqoKPMKUXMDwbeNWkf JVXpMEJCRVFmFR6TENN74Y504n5RssjKeldylXR3jiC2gOYcTGWOYmXdq7K6U0AWi80+ Dz1KpX9Vk8bK80UZ9o6wmGZHg1Af3cY72FXhDAwXB2Wp+S56tTtbTzc8QQQajjShRkLC bbcQ== Received: by 10.50.140.97 with SMTP id rf1mr6023591igb.70.1350641459360; Fri, 19 Oct 2012 03:10:59 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp56182igt; Fri, 19 Oct 2012 03:10:58 -0700 (PDT) Received: by 10.180.82.34 with SMTP id f2mr17779552wiy.17.1350641457528; Fri, 19 Oct 2012 03:10:57 -0700 (PDT) Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com [74.125.82.50]) by mx.google.com with ESMTPS id o11si1292045wee.113.2012.10.19.03.10.57 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 19 Oct 2012 03:10:57 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=74.125.82.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: by mail-wg0-f50.google.com with SMTP id 16so236852wgi.31 for ; Fri, 19 Oct 2012 03:10:57 -0700 (PDT) Received: by 10.216.71.20 with SMTP id q20mr471282wed.172.1350641457032; Fri, 19 Oct 2012 03:10:57 -0700 (PDT) Received: from localhost.localdomain (AToulouse-654-1-1-158.w90-5.abo.wanadoo.fr. [90.5.56.158]) by mx.google.com with ESMTPS id v3sm2565519wiy.5.2012.10.19.03.10.55 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 19 Oct 2012 03:10:56 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl Cc: linux-pm@vger.kernel.org, lorenzo.pieralisi@arm.com, pdeschrijver@nvidia.com, patches@linaro.org, linaro-dev@lists.linaro.org Subject: [PATCH 2/4][V2] cpuidle: move driver checking within the lock section Date: Fri, 19 Oct 2012 12:10:47 +0200 Message-Id: <1350641449-22863-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1350641449-22863-1-git-send-email-daniel.lezcano@linaro.org> References: <1350641449-22863-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQnQd+Nm4378dsZYu0Xw410XT0SN0AG1VAGARPRImlCjMDf390u17csTZwemSSnpfTI9uSIm The code is racy and the check with cpuidle_curr_driver should be done under the lock. I don't find a path in the different drivers where that could happen because the arch specific drivers are written in such way it is not possible to register a driver while it is unregistered, except maybe in a very improbable case when "intel_idle" and "processor_idle" are competing. One could unregister a driver, while the other one is registering. Signed-off-by: Daniel Lezcano Acked-by: Peter De Schrijver --- drivers/cpuidle/driver.c | 10 +--------- 1 files changed, 1 insertions(+), 9 deletions(-) diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index 39ba8e1..3e59075 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -85,17 +85,9 @@ EXPORT_SYMBOL_GPL(cpuidle_get_driver); */ void cpuidle_unregister_driver(struct cpuidle_driver *drv) { - if (drv != cpuidle_curr_driver) { - WARN(1, "invalid cpuidle_unregister_driver(%s)\n", - drv->name); - return; - } - spin_lock(&cpuidle_driver_lock); - - if (!WARN_ON(drv->refcnt > 0)) + if (drv == cpuidle_curr_driver && !WARN_ON(drv->refcnt > 0)) cpuidle_curr_driver = NULL; - spin_unlock(&cpuidle_driver_lock); } EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);