From patchwork Fri Sep 20 17:07:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 20481 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8BE1D23906 for ; Fri, 20 Sep 2013 17:07:43 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id u18sf580405qcx.6 for ; Fri, 20 Sep 2013 10:07:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=hyfH173AbU9hLCowPY1R4DSnW9gmQMEh2NSy/PvxgW0=; b=d1/8Zd1X2xV3gRq9jLT/LNkN7eUdPE+97AmKYi2Bv/LRVGgXHH3aXA7qH7JZabKGfr 3kQg+aH8tXY2NKxuZ3VCbtCiW4indg/GvUA4OvgUE1aRvM+l48Cx8mfjbjo/kKU5EA8o 4e7fjPJ1C75/gtnPHSY8kqbZiDlWErTC9cKFteBLJM5ddMzusQ4MO//Wf2pVwBjxLR48 lC2pNEE22MnhtWZDw3TAaTzqw4Y68YPEcxQELiGt90BIkLCWg8rqDUBXQQWajCygeSpU BMw6lcwqJ3XK98T7SelinU0DON2FshqDiQTXhKLTIcIAcKAgQTVIpcsVQdEg3x1EJ629 6l3A== X-Gm-Message-State: ALoCoQkjB8OFuW24ol+FBkwbziXM5QiOTGfCCyfoH0HaAwzVZAVd/K8Wxwjo9FpK2BA4wXLB9E5H X-Received: by 10.236.142.38 with SMTP id h26mr409565yhj.57.1379696862961; Fri, 20 Sep 2013 10:07:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.99.72 with SMTP id eo8ls338580qeb.41.gmail; Fri, 20 Sep 2013 10:07:42 -0700 (PDT) X-Received: by 10.221.47.193 with SMTP id ut1mr7279222vcb.8.1379696862800; Fri, 20 Sep 2013 10:07:42 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id s17si3233065vcu.14.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Sep 2013 10:07:42 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ld13so521281vcb.11 for ; Fri, 20 Sep 2013 10:07:42 -0700 (PDT) X-Received: by 10.220.91.16 with SMTP id k16mr7384301vcm.21.1379696862700; Fri, 20 Sep 2013 10:07:42 -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.220.174.196 with SMTP id u4csp29002vcz; Fri, 20 Sep 2013 10:07:42 -0700 (PDT) X-Received: by 10.68.190.197 with SMTP id gs5mr9201303pbc.90.1379696861418; Fri, 20 Sep 2013 10:07:41 -0700 (PDT) Received: from mail-pb0-f52.google.com (mail-pb0-f52.google.com [209.85.160.52]) by mx.google.com with ESMTPS id gg2si13180521pac.217.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Sep 2013 10:07:41 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.52 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.160.52; Received: by mail-pb0-f52.google.com with SMTP id wz12so608043pbc.39 for ; Fri, 20 Sep 2013 10:07:40 -0700 (PDT) X-Received: by 10.66.163.164 with SMTP id yj4mr10123460pab.91.1379696860541; Fri, 20 Sep 2013 10:07:40 -0700 (PDT) Received: from localhost ([122.167.152.64]) by mx.google.com with ESMTPSA id pu5sm20239382pac.21.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 20 Sep 2013 10:07:39 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, srivatsa.bhat@linux.vnet.ibm.com, linus.walleij@linaro.org, Viresh Kumar Subject: [PATCH] cpufreq: check cpufreq driver is valid and cpufreq isn't disabled in cpufreq_get() Date: Fri, 20 Sep 2013 22:37:31 +0530 Message-Id: <389fbc3c8ad7c339cd2d9572d73c355b7b967823.1379669625.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.180 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: , cpufreq_get() can be called from external drivers which might not be aware if cpufreq driver is registered or not. And so we should actually check if cpufreq driver is registered or not and also if cpufreq is active or disabled, at the beginning of cpufreq_get(). Otherwise call to lock_policy_rwsem_read() might hit BUG_ON(!policy). Reported-and-Tested-by: Linus Walleij Signed-off-by: Viresh Kumar Reviewed-by: Srivatsa S. Bhat --- For 3.12. drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 82ecbe3..db004a8 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1460,6 +1460,9 @@ unsigned int cpufreq_get(unsigned int cpu) { unsigned int ret_freq = 0; + if (cpufreq_disabled() || !cpufreq_driver) + return -ENOENT; + if (!down_read_trylock(&cpufreq_rwsem)) return 0;