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: 1617681 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 8A3ECDFFAD for ; Fri, 19 Oct 2012 10:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030319Ab2JSKLA (ORCPT ); Fri, 19 Oct 2012 06:11:00 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:62758 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030297Ab2JSKK6 (ORCPT ); Fri, 19 Oct 2012 06:10:58 -0400 Received: by mail-we0-f174.google.com with SMTP id t9so151821wey.19 for ; Fri, 19 Oct 2012 03:10:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=8mABF11CNYjRCoOBYE6sCjTiKSTdDNSKQLsPFz2Aqq0=; b=GOELTs58l9zA8JKjnbOhie2W7GYacNT1psTxW43GZBT4BUxzGkGnUlLtCj5tnIH+9c QmPM5vPU0NRpPB4A0IjGdGXgj+kv/osvXdeYRg0FneRJSSdEkoPRCFxRvWiHDk8oITLG AYO6NVM58BUr3YPoaVjQM+PXh1RsKeXevT9q48jGOg5G03tESW/JyUAw04xketWzVobB q1COhFQ0wrwacbILrsrXS8yMwU1DHdBwqMXutWOj0Q6Lq6yLtw15vdQp5zkZ3ZQJZtWN 9ELt7A8bzMN0OFuljNziGzOPBcRZLaXsNO7HvGpnxSdajlQbm/0+NAqRHGKU4zg30+1k VVYg== 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: ALoCoQnOSWnuW0y4Q41IzyG0/pSfLc5tJnmvLUV/1m1dt2ijcLDVNgVzvHaXuuxbxIRM/s3zyijZ Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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);