From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752826AbcFJB3J (ORCPT ); Thu, 9 Jun 2016 21:29:09 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:50542 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750995AbcFJB3C convert rfc822-to-8bit (ORCPT ); Thu, 9 Jun 2016 21:29:02 -0400 X-AuditID: cbfee68e-f79b26d0000013da-88-575a17db8714 MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8BIT Message-id: <575A17F5.1050609@samsung.com> Date: Fri, 10 Jun 2016 10:29:25 +0900 From: Seung-Woo Kim Reply-to: sw0312.kim@samsung.com User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 To: Jaehoon Chung Cc: ulf.hansson@linaro.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Seung-Woo Kim Subject: Re: [PATCH] mmc: dw_mmc: remove UBSAN warning in dw_mci_setup_bus() References: <1465358840-22826-1-git-send-email-sw0312.kim@samsung.com> <5759633E.7090706@samsung.com> In-reply-to: <5759633E.7090706@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsWyRsSkQPe2eFS4wYL/OhY3frWxWlzeNYfN 4sj/fkaLGZNfslkcXxvuwOpx59oeNo++LasYPT5vkgtgjuKySUnNySxLLdK3S+DKmPQpteCh RkVnh3QD42HFLkZODgkBE4mnXyYwQthiEhfurWfrYuTiEBJYwShx485eJpiiLYfnsUIkZjFK fF08lQ0kwSsgKPFj8j0WEJtZQF1i0rxFzBC2iMTcK1Oh4toSyxa+ZoZofsAocW7CSnaIZi2J xb/awYpYBFQlvjzfDXYGm4COxP4lv1lBbCEBBYkrE48B1XNwiAqESezcnA4SFgFqvX5kIhvE /FqJfRP7wQ4VFvCRuNY6GWrX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ezkgjvaWGgEG9KYmVValF+fFFpTmrxIUZToF8nMkuJJucDU0xeSbyhsYmZ kaWRuaGFkbG5kjjv4//rwoQE0hNLUrNTUwtSi2D6mDg4pRoYex0Z7j3t3Xfz4/1JLXuyvsrw uO144+X/rmmq38PvP44t63g/z2FOz6qoaWL6zy6FvJqae/po+57rCSq7XzwSvXS+InC2/57Z +x7a93RdOCn7wMzu2SXeXx/OSTpPDy9OXlHQ9kzku4PZnunx3Zsjpk+x6Msw09bjrJ8qqnPQ s3h5jt+jlWWcR5VYijMSDbWYi4oTAfRwHOf5AgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jaehoon, On 2016년 06월 09일 21:38, Jaehoon Chung wrote: > Hi Seung-Woo, > > On 06/08/2016 01:07 PM, Seung-Woo Kim wrote: >> 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 > > The below message can be discarded. You are right, like above message, below part can be replaced as [...]. > >> [] 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 || > > Well, we don't expect that clock is 0. > if clock is 0, it should be passed to " if (!clock)".. > > During initializing card, clock is 400KHz or less..I understood what you want to fix. > But I taught this is not correct. It seems slot->__clk_old is not really clock but a kind of value to store both clock and div in one variable. And at least, my compiler calculates right shift with more than 32 as 0. I am not sure there is other proper value for the case. By the way, in my test environment, clock is calculated as like following steps: mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot req 400000Hz, actual 400000HZ div = 250) mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot req 200000000Hz, actual 200000000HZ div = 0) mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot req 52000000Hz, actual 50000000HZ div = 2) mmc_host mmc0: Bus speed (slot 0) = 400000000Hz (slot req 52000000Hz, actual 50000000HZ div = 4) mmc_host mmc0: Bus speed (slot 0) = 400000000Hz (slot req 200000000Hz, actual 200000000HZ div = 1) and only the first case is reported as the warning. If you let me know any proper value, then I will fix with the value. Thanks, - Seung-Woo Kim > > >> + 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; > > Also, clock is not 0.. > > > Best Regards, > Jaehoon Chung > >> } >> >> host->current_speed = clock; >> > > > -- Seung-Woo Kim Samsung Software R&D Center --