From patchwork Tue Oct 28 15:26:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 5178011 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1D332C11AC for ; Tue, 28 Oct 2014 15:27:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EDC9201B4 for ; Tue, 28 Oct 2014 15:27:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 932A2200ED for ; Tue, 28 Oct 2014 15:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754386AbaJ1P1b (ORCPT ); Tue, 28 Oct 2014 11:27:31 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:62330 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754061AbaJ1P12 (ORCPT ); Tue, 28 Oct 2014 11:27:28 -0400 Received: by mail-wg0-f48.google.com with SMTP id m15so1151045wgh.7 for ; Tue, 28 Oct 2014 08:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=1JlPYbaI/elwM7QtQr4+5T98LynJkzBBWRA6WUFtfN8=; b=aQb6RNCNd3LXMsGodLc9zsRjIsT2EJFTRZ8ZpFdHhm4Bqe4zorBxSj/9PzL0B+UDyi d9hYCthStL+2fiNPgyf6nzpMOUtFzCp0tufqYiNVEfRVfGBQ1T/MTVsot8cTPEsTRc4z pC880ekQML1pINZfm+iTky7Kc7zxi25aRnMHIzm3e20tUEmd8Cg8057dluj0U6OmRSFD KbX/L8s1yaBbwoBKgEnXZgYyc7pgdIDqP+bAWM867t7ha1x91o8G6V5rLjU4NF/SjwQW 4yVGMPYy0Lrhxj3jVbtC+l47bZaJsdxZTYGkSBgRRZTv1IKGaxLbwh4ldTn3exhWO3b/ JGFQ== X-Received: by 10.180.219.106 with SMTP id pn10mr5730010wic.63.1414510047365; Tue, 28 Oct 2014 08:27:27 -0700 (PDT) Received: from cizrna.lan (37-48-34-72.tmcz.cz. [37.48.34.72]) by mx.google.com with ESMTPSA id mc4sm2578415wic.6.2014.10.28.08.27.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Oct 2014 08:27:26 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Cc: Javier Martinez Canillas , Tomeu Vizoso , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH 2/2] cpufreq: Guard against not-yet-initialized policies in cpufreq_cpu_get Date: Tue, 28 Oct 2014 16:26:48 +0100 Message-Id: <1414510008-7262-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1414510008-7262-1-git-send-email-tomeu.vizoso@collabora.com> References: <1414510008-7262-1-git-send-email-tomeu.vizoso@collabora.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's a substantial window of opportunity from the time the policy objects are created until they are initialized, causing this: [ 4.651435] ------------[ cut here ]------------ [ 4.651453] WARNING: CPU: 1 PID: 64 at include/linux/kref.h:47 kobject_get+0x64/0x70() [ 4.651463] Modules linked in: [ 4.651473] CPU: 1 PID: 64 Comm: irq/77-tegra-ac Not tainted 3.18.0-rc1-next-20141027ccu-00049-g21a0041 #248 [ 4.651497] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [ 4.651505] [] (show_stack) from [] (dump_stack+0x98/0xd8) [ 4.651515] [] (dump_stack) from [] (warn_slowpath_common+0x70/0x8c) [ 4.651522] [] (warn_slowpath_common) from [] (warn_slowpath_null+0x1c/0x24) [ 4.651530] [] (warn_slowpath_null) from [] (kobject_get+0x64/0x70) [ 4.651539] [] (kobject_get) from [] (cpufreq_cpu_get+0x88/0xc8) [ 4.651547] [] (cpufreq_cpu_get) from [] (cpufreq_get+0xc/0x64) [ 4.651555] [] (cpufreq_get) from [] (actmon_thread_isr+0x140/0x1a4) [ 4.651563] [] (actmon_thread_isr) from [] (irq_thread_fn+0x1c/0x40) [ 4.651570] [] (irq_thread_fn) from [] (irq_thread+0x134/0x174) [ 4.651579] [] (irq_thread) from [] (kthread+0xdc/0xf4) [ 4.651587] [] (kthread) from [] (ret_from_fork+0x14/0x3c) [ 4.651591] ---[ end trace 7f6a15d1272e6ef3 ]--- This commit checks that the policy object has been initialized already before trying to ref it. Signed-off-by: Tomeu Vizoso --- drivers/cpufreq/cpufreq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 644b54e..37cd6c9 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -214,8 +214,12 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) if (cpufreq_driver) { /* get the CPU */ policy = per_cpu(cpufreq_cpu_data, cpu); - if (policy) - kobject_get(&policy->kobj); + if (policy) { + if (!kobject_initialized(&policy->kobj)) + policy = NULL; + else + kobject_get(&policy->kobj); + } } read_unlock_irqrestore(&cpufreq_driver_lock, flags);