From patchwork Tue Aug 4 05:48:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 51894 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 7F9EC229FD for ; Tue, 4 Aug 2015 05:51:52 +0000 (UTC) Received: by lbbyj8 with SMTP id yj8sf31548504lbb.3 for ; Mon, 03 Aug 2015 22:51:51 -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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=5fm0lqyH2o/iinAIr7Y3vnOvb47aWfSGoYc5r2W1zgA=; b=mj365DuIah+h8scCM4G2DJWr16z40asTFCBjYsWwoFEw5bEEHJLvVSaTZFtviUK6bd 2YkYGfClM8fxWPxeBxIRZbvOHgqw4Hg1u8JG+cPKjoQrAuKKytRHlxMUS+TN/YmDKcNL xoBYQTb1kiOLHvfkY9ny8IZB4yJMYU9iK7iMQO/mPCfSeN4rMYtpWBX9W6nLnJEG/IiF W4tMJ+QVr4FtCjtzBiqNkYrkpp5mHJbJOES7PeMVHQ3eeBYmEg4lvFeDCA86S3sR9HPz 5Sb9tTgPK/rJJeaqE7Dc1qBX+X3q5vMdrU1PN1PEweTLyRJ1gG1N+pUmmwTV2iP6yjJO TrSQ== X-Gm-Message-State: ALoCoQm62midxG4P7RrCnuv5DVV975hUiE6NScn5Ey/Dd1DZGmQIu6b8+Y6Ra4dv8Wl43MOf7LtE X-Received: by 10.152.115.196 with SMTP id jq4mr572282lab.1.1438667511080; Mon, 03 Aug 2015 22:51:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.199 with SMTP id m7ls665157lam.83.gmail; Mon, 03 Aug 2015 22:51:50 -0700 (PDT) X-Received: by 10.152.43.134 with SMTP id w6mr1319251lal.120.1438667510758; Mon, 03 Aug 2015 22:51:50 -0700 (PDT) Received: from mail-la0-x229.google.com (mail-la0-x229.google.com. [2a00:1450:4010:c03::229]) by mx.google.com with ESMTPS id jr11si3241009lab.115.2015.08.03.22.51.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Aug 2015 22:51:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::229 as permitted sender) client-ip=2a00:1450:4010:c03::229; Received: by labix3 with SMTP id ix3so14586203lab.0 for ; Mon, 03 Aug 2015 22:51:50 -0700 (PDT) X-Received: by 10.152.121.4 with SMTP id lg4mr1471306lab.112.1438667510623; Mon, 03 Aug 2015 22:51:50 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp2226950lba; Mon, 3 Aug 2015 22:51:49 -0700 (PDT) X-Received: by 10.70.32.66 with SMTP id g2mr4213967pdi.82.1438667508769; Mon, 03 Aug 2015 22:51:48 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rl7si30745535pab.173.2015.08.03.22.51.47; Mon, 03 Aug 2015 22:51:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753321AbbHDFvp (ORCPT + 28 others); Tue, 4 Aug 2015 01:51:45 -0400 Received: from m50-112.126.com ([123.125.50.112]:40529 "EHLO m50-112.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753108AbbHDFvm (ORCPT ); Tue, 4 Aug 2015 01:51:42 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp6 (Coremail) with SMTP id j9KowAAXLUKAUsBVumIjAQ--.6195S5; Tue, 04 Aug 2015 13:50:02 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org, Daniel Lezcano Cc: "Rafael J. Wysocki" , linux-pm@vger.kernel.org, Xunlei Pang Subject: [PATCH v2 3/3] cpuidle/coupled: Add sanity check for safe_state_index Date: Tue, 4 Aug 2015 13:48:57 +0800 Message-Id: <1438667337-16903-3-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438667337-16903-1-git-send-email-xlpang@126.com> References: <1438667337-16903-1-git-send-email-xlpang@126.com> X-CM-TRANSID: j9KowAAXLUKAUsBVumIjAQ--.6195S5 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xw1rur1UXry5CryUCw18Grg_yoWkCFb_uw 10qr97Jr1j9F1kKa9Fvwn3Z34I9F45WrWkWr1IvFy5Aw1kZrZ7t3yDZ343Xa1Uuw4akF98 tw4UJ340krykAjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU5jAp5UUUUU== X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiWwtMv1PM+Dgp4wAAs2 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: xlpang@126.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::229 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@126.com; dmarc=fail (p=NONE dis=NONE) header.from=126.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Xunlei Pang Since we're using cpuidle_driver::safe_state_index directly as the target state index, it's better to add the sanity check at the point of registering the driver. Signed-off-by: Xunlei Pang --- drivers/cpuidle/driver.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c index 5db1478..def299e 100644 --- a/drivers/cpuidle/driver.c +++ b/drivers/cpuidle/driver.c @@ -223,10 +223,23 @@ static void poll_idle_init(struct cpuidle_driver *drv) {} static int __cpuidle_register_driver(struct cpuidle_driver *drv) { int ret; +#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED + int i; +#endif if (!drv || !drv->state_count) return -EINVAL; +#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED + for (i = drv->state_count - 1; i >= 0; i--) { + if (cpuidle_state_is_coupled(drv, i) && + (drv->safe_state_index == i || + drv->safe_state_index < 0 || + drv->safe_state_index >= drv->state_count)) + return -EINVAL; + } +#endif + if (cpuidle_disabled()) return -ENODEV;