From patchwork Tue Aug 2 10:16:46 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: 9255425 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 087F060865 for ; Tue, 2 Aug 2016 10:29:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED7C8284FD for ; Tue, 2 Aug 2016 10:29:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1EEC28513; Tue, 2 Aug 2016 10:29:31 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 2BBF2284FD for ; Tue, 2 Aug 2016 10:29:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752199AbcHBK31 (ORCPT ); Tue, 2 Aug 2016 06:29:27 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:57485 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752020AbcHBK27 (ORCPT ); Tue, 2 Aug 2016 06:28:59 -0400 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OBA01RDU1VYUU80@mailout2.samsung.com>; Tue, 02 Aug 2016 19:16:46 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.112]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id A2.FB.31386.E0370A75; Tue, 2 Aug 2016 19:16:46 +0900 (KST) X-AuditID: cbfee68d-f79286d000007a9a-a2-57a0730ee22d Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 0B.AA.07740.E0370A75; Tue, 2 Aug 2016 03:16:46 -0700 (MST) Received: from localhost.localdomain ([10.113.62.209]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OBA001S41VWQ300@mmp1.samsung.com>; Tue, 02 Aug 2016 19:16:46 +0900 (KST) 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: jy0922.shim@samsung.com, sw0312.kim@samsung.com Subject: [PATCH] pwm: samsung: fix to use lowest div for large enough modulation bits Date: Tue, 02 Aug 2016 19:16:46 +0900 Message-id: <1470133006-4272-1-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrALMWRmVeSWpSXmKPExsWyRsSkQJeveEG4wb930hYv7l1ksXj9wtBi 0+NrrBaXd81hs7h7dxWjxYzz+5gsZkx+yWbxc9c8FgcOj52z7rJ7bF5S79G3ZRWjx+dNcgEs UVw2Kak5mWWpRfp2CVwZB3Y9ZSnYwV/x4MZGpgbGNzxdjJwcEgImEld/P2SBsMUkLtxbz9bF yMUhJLCCUWLL9xusMEUbLz5mhEgsZZTo3DmdFcL5wSjxePJuNpAqNgEdif1LfoN1iAjsZpRo nK7dxcjBwSxgLHH3kjOIKSwQLrFlAwdIBYuAqsTWVxeZQGxeAVeJ3vdTmSB2KUgsuPcW7AgJ gXZ2iRU7HjNBNAhIfJt8iAVkjoSArMSmA8wQ9ZISB1fcYJnAK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AP17dxd+6U3LNjxR9k5W/xx/NEpnVydYbOkLk38 c3Xf2i/cSfKOd6ccnC7B/9w2x/Nj+LnZIY6VUn/fSb2T+T/nv+6iZ2vYHhbGc3lenulVd3Hm mx8GPO8kdzQysAUJeJqq/bx5TVeJpTgj0VCLuag4EQDl8EPToAIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected 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, 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) [...] Signed-off-by: Seung-Woo Kim Reviewed-by: Joonyoung Shim --- The UBSAN warning from ARM is reported with the patch in following link: https://patchwork.kernel.org/patch/9189575/ --- drivers/pwm/pwm-samsung.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c index ada2d32..ff0def6 100644 --- a/drivers/pwm/pwm-samsung.c +++ b/drivers/pwm/pwm-samsung.c @@ -193,9 +193,13 @@ 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 (fls(rate) <= variant->bits) { + div = variant->div_base; + } else { + for (div = variant->div_base; div < 4; ++div) + if ((rate >> (variant->bits + div)) < freq) + break; + } pwm_samsung_set_divisor(chip, chan, BIT(div));