From patchwork Mon Mar 31 18:29:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 3917431 Return-Path: X-Original-To: patchwork-linux-arm-msm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 68E6B9F370 for ; Mon, 31 Mar 2014 18:29:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9F768201F2 for ; Mon, 31 Mar 2014 18:29:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D52720212 for ; Mon, 31 Mar 2014 18:29:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753448AbaCaS3a (ORCPT ); Mon, 31 Mar 2014 14:29:30 -0400 Received: from smtp.codeaurora.org ([198.145.11.231]:40959 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753176AbaCaS33 (ORCPT ); Mon, 31 Mar 2014 14:29:29 -0400 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 32AFD13F479; Mon, 31 Mar 2014 18:29:29 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id 1F4CD13F562; Mon, 31 Mar 2014 18:29:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from [10.46.167.8] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5E92513F479; Mon, 31 Mar 2014 18:29:28 +0000 (UTC) Message-ID: <5339B407.1050308@codeaurora.org> Date: Mon, 31 Mar 2014 11:29:27 -0700 From: Stephen Boyd User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Dmitry Torokhov CC: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.org, Arnd Bergmann Subject: Re: [PATCH] Input: pmic8xxx-pwrkey - Set sane default for debounce time References: <1396289664-31893-1-git-send-email-sboyd@codeaurora.org> <20140331182315.GA9198@core.coreip.homeip.net> In-Reply-To: <20140331182315.GA9198@core.coreip.homeip.net> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 03/31/14 11:23, Dmitry Torokhov wrote: > On Mon, Mar 31, 2014 at 11:14:24AM -0700, Stephen Boyd wrote: >> If the debounce time is 0 our usage of ilog2() later on in this >> driver will cause undefined behavior. If CONFIG_OF=n this fact is >> evident to the compiler, and it emits a call to ____ilog2_NaN() >> which doesn't exist. Fix this by setting a sane default for >> debounce. >> >> Reported-by: Arnd Bergmann >> Signed-off-by: Stephen Boyd >> --- >> drivers/input/misc/pmic8xxx-pwrkey.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/input/misc/pmic8xxx-pwrkey.c b/drivers/input/misc/pmic8xxx-pwrkey.c >> index 1cb8fda7a166..27add04676e1 100644 >> --- a/drivers/input/misc/pmic8xxx-pwrkey.c >> +++ b/drivers/input/misc/pmic8xxx-pwrkey.c >> @@ -92,7 +92,7 @@ static int pmic8xxx_pwrkey_probe(struct platform_device *pdev) >> bool pull_up; >> >> if (of_property_read_u32(pdev->dev.of_node, "debounce", &kpd_delay)) >> - kpd_delay = 0; >> + kpd_delay = 15625; > What if somebody supplied 0 via DT? Can we check and return -EINVAL? Sure. Here's a v2. -----8<------ From: Stephen Boyd Subject: [PATCH v2] Input: pmic8xxx-pwrkey - Set sane default for debounce time If the debounce time is 0 our usage of ilog2() later on in this driver will cause undefined behavior. If CONFIG_OF=n this fact is evident to the compiler, and it emits a call to ____ilog2_NaN() which doesn't exist. Fix this by setting a sane default for debounce and failing to probe if debounce is 0 in the DT. Reported-by: Arnd Bergmann Signed-off-by: Stephen Boyd --- drivers/input/misc/pmic8xxx-pwrkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/misc/pmic8xxx-pwrkey.c b/drivers/input/misc/pmic8xxx-pwrkey.c index 1cb8fda7a166..3fb161902cc6 100644 --- a/drivers/input/misc/pmic8xxx-pwrkey.c +++ b/drivers/input/misc/pmic8xxx-pwrkey.c @@ -92,11 +92,11 @@ static int pmic8xxx_pwrkey_probe(struct platform_device *pdev) bool pull_up; if (of_property_read_u32(pdev->dev.of_node, "debounce", &kpd_delay)) - kpd_delay = 0; + kpd_delay = 15625; pull_up = of_property_read_bool(pdev->dev.of_node, "pull-up"); - if (kpd_delay > 62500) { + if (kpd_delay > 62500 || kpd_delay == 0) { dev_err(&pdev->dev, "invalid power key trigger delay\n"); return -EINVAL; }