From patchwork Wed Oct 31 16:44:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12639 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 BDDAE23EFB for ; Wed, 31 Oct 2012 16:45:03 +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 5D039A183CC for ; Wed, 31 Oct 2012 16:45:03 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so2267660iej.11 for ; Wed, 31 Oct 2012 09:45:03 -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=hlN9OSacdJAV2NegQ0oC+ACkPmKr6V6rbnhNnFrWa+6x0L816PNPZBYYV5NDvLxFxi Dex3IWTT22zSvKjqvlW66srdVq2EPgIKPje9OLbgaINvYa3Uhnu1K2JrDIwA2J+vCYR8 DFxxTv/1m0MFt96DZ3m5nU+4D2JRTj7i/5UbKyGWNCj+GVZfLC0X1ZThVMfMrQLnYu/i uFx3vVrvJltObpCnmgva12FVq1VlfwMxI/r0fQn9bhZd9qNpH/n80xagP88KKQJPTTho AfOB0+hzOmfFIPnXyMGtFtytnqwNsM8Ia2SCFMp1ilOQLWwVUllH9PmO4XNrYcEdqKfV Pyrw== Received: by 10.43.7.132 with SMTP id oo4mr32008392icb.6.1351701903104; Wed, 31 Oct 2012 09:45:03 -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 n20csp653072igt; Wed, 31 Oct 2012 09:45:02 -0700 (PDT) Received: by 10.204.148.146 with SMTP id p18mr11763946bkv.51.1351701901652; Wed, 31 Oct 2012 09:45:01 -0700 (PDT) Received: from mail-bk0-f50.google.com (mail-bk0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id fk9si5868631bkc.55.2012.10.31.09.45.01 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 31 Oct 2012 09:45:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=209.85.214.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.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-bk0-f50.google.com with SMTP id q16so834989bkw.37 for ; Wed, 31 Oct 2012 09:45:01 -0700 (PDT) Received: by 10.204.157.145 with SMTP id b17mr11300686bkx.68.1351701900948; Wed, 31 Oct 2012 09:45:00 -0700 (PDT) Received: from localhost.localdomain ([91.224.175.20]) by mx.google.com with ESMTPS id e13sm3909744bkw.12.2012.10.31.09.44.58 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 31 Oct 2012 09:45:00 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl Cc: linux-pm@vger.kernel.org, pdeschrijver@nvidia.com, lorenzo.pieralisi@arm.com, linaro-dev@lists.linaro.org Subject: [PATCH V3 2/4] cpuidle: move driver checking within the lock section Date: Wed, 31 Oct 2012 17:44:46 +0100 Message-Id: <1351701888-19963-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1351701888-19963-1-git-send-email-daniel.lezcano@linaro.org> References: <1351701888-19963-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQljdUyfuzQXZ3c3beAtQ3XuofPm7a6/lmDJgjYQB//GC43fdB6h7rimup4fLoOLDERIs+Z+ 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);