From patchwork Tue Aug 16 14:22:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seung-Woo Kim X-Patchwork-Id: 9284055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9A7D4600CB for ; Tue, 16 Aug 2016 14:22:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DEC128DC6 for ; Tue, 16 Aug 2016 14:22:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8190A28E03; Tue, 16 Aug 2016 14:22:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BBBB28DC6 for ; Tue, 16 Aug 2016 14:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751455AbcHPOWM (ORCPT ); Tue, 16 Aug 2016 10:22:12 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:35896 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750803AbcHPOWL (ORCPT ); Tue, 16 Aug 2016 10:22:11 -0400 Received: by mail-pa0-f68.google.com with SMTP id ez1so5374375pab.3; Tue, 16 Aug 2016 07:22:10 -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=Kb9PJBYkK7nQ/YXClh3pC1fN/KEEW0sv8p9Qs6rdf5Q=; b=DzJ8ZlfazBVjm6Id70ID4ebU8+8ODb8wYLi+MfhmQrv9L4LNlJoD8HB4+Nb5wB9Xws L7WTWLGIi5ZM9Xtgr2VNoPw1Vm9eCoBNJ71vAI/3pltoDbv2JDPVyFwyJQCTeP+AjBx5 0wKeLsXsJ9algoP9t5g6g0a5QycTNSkCy8YOzKcLf41v70B7MKJhZ70Ukn/EV1b/2cfk zfsXLsW39+AVGIPAvKyYD5bv1JW91hyjTr54Q3eSZUqNiFOFHhJNFB5kVBIuBmAv5IJl t9Cotj4Q7MHaa+IELF1fX20nYaiRJaNCMGVALfMMw4iFn8AEMLRhGu/Nj+M8tpWxYDuD MYFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Kb9PJBYkK7nQ/YXClh3pC1fN/KEEW0sv8p9Qs6rdf5Q=; b=RAppW9bB8pBl15DBMIAPGlFoWHO5KA/uLimNnvG/RFNk6TEXFUEUc6QREPDxN8pzXv Vnxpn24iVuYU89yhyO0JF6MpV2XKiOhe7WhLqEQlR9HsbGtxBIbPCmK+FsNFAufE7D3H ILZyEbf3FTrzh9QhXM89PYPNf/oifnImAV75TBl/Cq3fpo6KTdK9QbLpaXhR4XqmnUTr jMQ9T4NJe9h3PC/Ex0MCxBzmqrwyqt/LaZ2QItA9GiF3mGPnW8+8ELzuaa2PcMTiXo9y q2Yg8M8fuLwVRmHxhnrltDqMmtJDrnCAbEmRH580p6n3P8i9diBp6EJlxHrTYOZjXwZQ BAtg== X-Gm-Message-State: AEkooutyFTjEC0njx1foJLXZbYBm5W/jvL1jiouJ5qM8t8RSSQi6wqKHPAADy1hPayL+QQ== X-Received: by 10.66.148.202 with SMTP id tu10mr64458084pab.52.1471357330172; Tue, 16 Aug 2016 07:22:10 -0700 (PDT) Received: from vodka.yonsei.ac.kr ([165.132.120.101]) by smtp.gmail.com with ESMTPSA id e10sm39905934pay.39.2016.08.16.07.22.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Aug 2016 07:22:09 -0700 (PDT) From: Seung-Woo Kim To: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, k.kozlowski@samsung.com, thierry.reding@gmail.com, linux-pwm@vger.kernel.org Cc: tomasz.figa@gmail.com, sw0312.kim@samsung.com, jy0922.shim@samsung.com, krzk@kernel.org Subject: [PATCH v2] pwm: samsung: fix to use lowest div for large enough modulation bits Date: Tue, 16 Aug 2016 23:22:01 +0900 Message-Id: <20160816142201.12672-1-sw0312.kim@samsung.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <1470133006-4272-1-git-send-email-sw0312.kim@samsung.com> References: <1470133006-4272-1-git-send-email-sw0312.kim@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From pwm_samsung_calc_tin(), there is routine to find the lowest divider possible to generate lower frequency than requested one. But it is always possible to generate requested frequency with large enough modulation bits except s3c24xx, so this patch fixes to use lowest div for the case. This patch removes following UBSAN warning: UBSAN: Undefined behaviour in drivers/pwm/pwm-samsung.c:197:13 shift exponent 32 is too large for 32-bit type 'long unsigned int' [...] [] (ubsan_epilogue) from [] (__ubsan_handle_shift_out_of_bounds+0xd8/0x120) [] (__ubsan_handle_shift_out_of_bounds) from [] (pwm_samsung_config+0x508/0x6a4) [] (pwm_samsung_config) from [] (pwm_apply_state+0x174/0x40c) [] (pwm_apply_state) from [] (pwm_fan_probe+0xc8/0x488) [] (pwm_fan_probe) from [] (platform_drv_probe+0x70/0x150) [...] Cc: Tomasz Figa Signed-off-by: Seung-Woo Kim Reviewed-by: Krzysztof Kozlowski --- Changes from v1 * Remove too complex condition, instead, just checking simple variant->bits as Krzysztof's suggestion * Add comment from Tomasz The UBSAN warning from ARM is reported with the patch in following link: https://patchwork.kernel.org/patch/9189575/ --- drivers/pwm/pwm-samsung.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c index ada2d32..f113cda 100644 --- a/drivers/pwm/pwm-samsung.c +++ b/drivers/pwm/pwm-samsung.c @@ -193,9 +193,18 @@ static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *chip, * divider settings and choose the lowest divisor that can generate * frequencies lower than requested. */ - for (div = variant->div_base; div < 4; ++div) - if ((rate >> (variant->bits + div)) < freq) - break; + if (variant->bits < 32) { + /* Only for s3c24xx */ + for (div = variant->div_base; div < 4; ++div) + if ((rate >> (variant->bits + div)) < freq) + break; + } else { + /* + * Other variants have enough counter bits to generate any + * requested rate, so no need to check higher divisors. + */ + div = variant->div_base; + } pwm_samsung_set_divisor(chip, chan, BIT(div));