From patchwork Mon Sep 24 22:43:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 11696 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 BEC1623E54 for ; Mon, 24 Sep 2012 22:44: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 568EBA18026 for ; Mon, 24 Sep 2012 22:44:03 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so11389513iej.11 for ; Mon, 24 Sep 2012 15:44: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=JfD0kxxL357UsTWLw+tFXGKNaxALajRO4T5w3X7YZK0=; b=A7QnzHjUI1ZXz9xmm63ConJqCtVzKDXc5XEHSNNh61cPWPI616eR/ULhBCTyTMdath QQEY3wUbIQ6he2gw+VIwveBCojmUZuDmDA1cH30YqzJpXjvD96Q8SlNVXSJZAyov8LR1 mQMwTlBkj3mbyRJOjxi4gBIL3C2vwMLXBtbXfaqGp3HHxs1NKzEzdRu4S9SGUFoufKRf uJkHZz+XmWxmjnlU/RVVMgZEisxn4A4ocO8czSxIzXFtBpu9beLmH0CLdGmHwi3O3G9Z ZMgUQ0Rn2kwJMsFHxCjQLUpS1ARWYEwGUcDXMZdp8DCJz3E25rEkt3sm1qO03t1O/eRg vAXg== Received: by 10.42.109.194 with SMTP id m2mr10546296icp.48.1348526643129; Mon, 24 Sep 2012 15:44: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.184.232 with SMTP id ex8csp265887igc; Mon, 24 Sep 2012 15:44:02 -0700 (PDT) Received: by 10.180.74.33 with SMTP id q1mr17242986wiv.4.1348526641441; Mon, 24 Sep 2012 15:44:01 -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 r1si21106082wif.4.2012.09.24.15.44.00 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 15:44:01 -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 wgi16 with SMTP id 16so4956058wgi.31 for ; Mon, 24 Sep 2012 15:44:00 -0700 (PDT) Received: by 10.180.33.111 with SMTP id q15mr7914163wii.20.1348526640814; Mon, 24 Sep 2012 15:44:00 -0700 (PDT) Received: from localhost.localdomain (AToulouse-651-1-259-252.w109-214.abo.wanadoo.fr. [109.214.174.252]) by mx.google.com with ESMTPS id k2sm19286398wiz.7.2012.09.24.15.43.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 15:43:59 -0700 (PDT) From: Daniel Lezcano To: rjw@sisk.pl, lenb@kernel.org Cc: linux-pm@vger.kernel.org, lorenzo.pieralisi@arm.com, pdeschrijver@nvidia.com, linux-acpi@vger.kernel.org, patches@linaro.org, linaro-dev@lists.linaro.org Subject: [PATCH 2/4] cpuidle : move driver checking within the lock section Date: Tue, 25 Sep 2012 00:43:52 +0200 Message-Id: <1348526634-19029-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1348526634-19029-1-git-send-email-daniel.lezcano@linaro.org> References: <1348526634-19029-1-git-send-email-daniel.lezcano@linaro.org> X-Gm-Message-State: ALoCoQmUl0Imf2xehsG3yktZMDkNPkWobjIAJ/D3tuZhGLnNM+0zNn5IUCa0f9i3oCmt3gR04L7i The code checks if the driver is already set without taking the lock, but, right after, it takes the lock to assign the variable. If it is safe to check the variable without lock, then it is safe to assign it without lock. If it is unsafe to assign without a lock, then it is unsafe to check it without a 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 --- drivers/cpuidle/driver.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index 39ba8e1..4a0c4ab 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -85,17 +85,17 @@ EXPORT_SYMBOL_GPL(cpuidle_get_driver); */ void cpuidle_unregister_driver(struct cpuidle_driver *drv) { + spin_lock(&cpuidle_driver_lock); + if (drv != cpuidle_curr_driver) { WARN(1, "invalid cpuidle_unregister_driver(%s)\n", drv->name); - return; + goto out; } - spin_lock(&cpuidle_driver_lock); - if (!WARN_ON(drv->refcnt > 0)) cpuidle_curr_driver = NULL; - +out: spin_unlock(&cpuidle_driver_lock); } EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);