From patchwork Wed Jun 8 04:07:20 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: 9163279 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 A224160572 for ; Wed, 8 Jun 2016 04:07:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8872228353 for ; Wed, 8 Jun 2016 04:07:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D09B28369; Wed, 8 Jun 2016 04:07:01 +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=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 3C5B728353 for ; Wed, 8 Jun 2016 04:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751220AbcFHEG7 (ORCPT ); Wed, 8 Jun 2016 00:06:59 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:41552 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751194AbcFHEG5 (ORCPT ); Wed, 8 Jun 2016 00:06:57 -0400 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8F021S0Q3IPTA0@mailout3.samsung.com>; Wed, 08 Jun 2016 13:06:54 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.113]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id 54.7B.05366.ED997575; Wed, 8 Jun 2016 13:06:54 +0900 (KST) X-AuditID: cbfee68f-f79d26d0000014f6-e7-575799dece85 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 55.16.06706.ED997575; Tue, 7 Jun 2016 21:06:54 -0700 (MST) Received: from localhost.localdomain ([10.113.62.209]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8F00IL7Q3GDH70@mmp2.samsung.com>; Wed, 08 Jun 2016 13:06:54 +0900 (KST) From: Seung-Woo Kim To: jh80.chung@samsung.com, ulf.hansson@linaro.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, sw0312.kim@samsung.com Subject: [PATCH] mmc: dw_mmc: remove UBSAN warning in dw_mci_setup_bus() Date: Wed, 08 Jun 2016 13:07:20 +0900 Message-id: <1465358840-22826-1-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrELMWRmVeSWpSXmKPExsWyRsSkUPfezPBwg6UnZC1u/Gpjtbi8aw6b xZH//YwWMya/ZLM4vjbcgdXjzrU9bB59W1YxenzeJBfAHMVlk5Kak1mWWqRvl8CV0X5gD3PB T8mKZzflGxininUxcnBICJhIfGnU7mLkBDLFJC7cW8/WxcjFISSwglHi7rxGRoiEicTH9pOM EIlZjBL/765jhXB+MEpsbXvIDFLFJqAjsX/Jb7CEiEAro8SeVbPA2oUFPCT+nnzGAmKzCKhK vH+2D8zmFXCTmPz6K9QKBYkF996C7ZYQuM4m8XDrbmaIBgGJb5MPsUDcKiux6QAzRL2kxMEV N1gmMAosYGRYxSiaWpBcUJyUXmSsV5yYW1yal66XnJ+7iREYdKf/PevfwXj3gPUhRgEORiUe 3hN64eFCrIllxZW5hxhNgTZMZJYSTc4HhnZeSbyhsZmRhamJqbG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pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch removes following UBSAN warnings in dw_mci_setup_bus(). The warnings are caused because of shift with more than 31 on 32 bit variable, so this patch fixes to shift only for less than 32. UBSAN: Undefined behaviour in drivers/mmc/host/dw_mmc.c:1102:14 shift exponent 250 is too large for 32-bit type 'unsigned int' Call trace: [] dump_backtrace+0x0/0x380 [] show_stack+0x14/0x20 [] dump_stack+0xe0/0x120 [] ubsan_epilogue+0x18/0x68 [] __ubsan_handle_shift_out_of_bounds+0x18c/0x1bc [] dw_mci_setup_bus+0x3a0/0x438 [...] UBSAN: Undefined behaviour in drivers/mmc/host/dw_mmc.c:1132:27 shift exponent 250 is too large for 32-bit type 'unsigned int' Call trace: [] dump_backtrace+0x0/0x380 [] show_stack+0x14/0x20 [] dump_stack+0xe0/0x120 [] ubsan_epilogue+0x18/0x68 [] __ubsan_handle_shift_out_of_bounds+0x18c/0x1bc [] dw_mci_setup_bus+0x384/0x438 [] dw_mci_set_ios+0x184/0x798 [] mmc_power_up+0x11c/0x260 [] mmc_start_host+0x88/0x100 [] mmc_add_host+0x6c/0x128 [] dw_mci_probe+0x1088/0x1750 [] dw_mci_pltfm_register+0x108/0x178 [] dw_mci_exynos_probe+0x4c/0x88 [] platform_drv_probe+0x78/0x180 [] driver_probe_device+0x144/0x460 [] __driver_attach+0xf4/0x140 [] bus_for_each_dev+0xf0/0x160 [] driver_attach+0x34/0x58 [] bus_add_driver+0x2c0/0x398 [] driver_register+0xbc/0x1e0 [] __platform_driver_register+0x84/0xa8 [] dw_mci_exynos_pltfm_driver_init+0x18/0x20 [] do_one_initcall+0xa0/0x2c8 [] kernel_init_freeable+0x52c/0x5dc [] kernel_init+0x1c/0xf8 [] ret_from_fork+0x10/0x40 Signed-off-by: Seung-Woo Kim --- drivers/mmc/host/dw_mmc.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 2cc6123..dff045e 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -1099,7 +1099,8 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0; - if ((clock << div) != slot->__clk_old || force_clkinit) + if (((div < 32) ? (clock << div) : 0) != slot->__clk_old || + force_clkinit) dev_info(&slot->mmc->class_dev, "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n", slot->id, host->bus_hz, clock, @@ -1129,7 +1130,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) mci_send_cmd(slot, sdmmc_cmd_bits, 0); /* keep the clock with reflecting clock dividor */ - slot->__clk_old = clock << div; + slot->__clk_old = (div < 32) ? (clock << div) : 0; } host->current_speed = clock;