From patchwork Fri Jun 17 05:16:49 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: 9182467 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 D3B606075D for ; Fri, 17 Jun 2016 05:16:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B38ED28396 for ; Fri, 17 Jun 2016 05:16:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9568E2839C; Fri, 17 Jun 2016 05:16:56 +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 80A7928396 for ; Fri, 17 Jun 2016 05:16:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751111AbcFQFQy (ORCPT ); Fri, 17 Jun 2016 01:16:54 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:46034 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750774AbcFQFQx (ORCPT ); Fri, 17 Jun 2016 01:16:53 -0400 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8W0283OHC2WRB0@mailout4.samsung.com>; Fri, 17 Jun 2016 14:16:50 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.115]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 64.25.05251.2C783675; Fri, 17 Jun 2016 14:16:50 +0900 (KST) X-AuditID: cbfee691-f79196d000001483-aa-576387c27aab Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 63.84.06706.2C783675; Thu, 16 Jun 2016 22:16:50 -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 <0O8W00K4BHC05K90@mmp2.samsung.com>; Fri, 17 Jun 2016 14:16:50 +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 v2] mmc: dw_mmc: remove UBSAN warning in dw_mci_setup_bus() Date: Fri, 17 Jun 2016 14:16:49 +0900 Message-id: <1466140609-5773-1-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-reply-to: <1465358840-22826-1-git-send-email-sw0312.kim@samsung.com> References: <1465358840-22826-1-git-send-email-sw0312.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFLMWRmVeSWpSXmKPExsWyRsSkWPdQe3K4waVvphY3frWxWlzeNYfN 4sj/fkaLGZNfslkcXxvuwOpx59oeNo++LasYPT5vkgtgjuKySUnNySxLLdK3S+DKmLLqGUvB IemKtW2tTA2MF8W6GDk5JARMJDYt3MkCYYtJXLi3nq2LkYtDSGAFo8T/fSuZYIrW3D/JApGY xSjR+auBGcL5wSgxe8VtZpAqNgEdif1LfrOCJEQEWhkl9qyaxQiSEBbwlpjd0gVmswioShy4 vwbM5hVwlZj66ikjxAoFiQX33gLt5uDgFHCXWHTDBcQUEnCTuLvNC2SkhMBnNomP13+wQ4wR kPg2+RALSI2EgKzEpgPMEFMkJQ6uuMEygVFoASPDKkbR1ILkguKk9CJTve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CcRpKrS78tw8WuXzjOfHcubt+77sWMDq+pOpYIVUuICLcFrC7TeT1pydpqRv+JX2WmS n9gSvqcpsRRnJBpqMRcVJwIAQ4/wj5oCAAA= DLP-Filter: 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(). 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 warnings are caused because of shift with more than 31 on 32 bit variable, so this patch fixes to keep both clock and divider instead of shift. Signed-off-by: Seung-Woo Kim --- drivers/mmc/host/dw_mmc.c | 8 +++++--- drivers/mmc/host/dw_mmc.h | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 2cc6123..d05c8cc 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 (clock != slot->__clk_old || div != slot->__div_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, @@ -1128,8 +1129,9 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) /* inform CIU */ mci_send_cmd(slot, sdmmc_cmd_bits, 0); - /* keep the clock with reflecting clock dividor */ - slot->__clk_old = clock << div; + /* keep the clock and clock divider */ + slot->__clk_old = clock; + slot->__div_old = div; } host->current_speed = clock; diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h index 1e8d838..fdfc3f5 100644 --- a/drivers/mmc/host/dw_mmc.h +++ b/drivers/mmc/host/dw_mmc.h @@ -245,9 +245,10 @@ extern int dw_mci_resume(struct dw_mci *host); * @queue_node: List node for placing this node in the @queue list of * &struct dw_mci. * @clock: Clock rate configured by set_ios(). Protected by host->lock. - * @__clk_old: The last updated clock with reflecting clock divider. - * Keeping track of this helps us to avoid spamming the console - * with CONFIG_MMC_CLKGATE. + * @__clk_old: The last updated clock. + * @__div_old: The last updated clock divider. + * Keeping track of clock and clock divider helps us to avoid spamming + * the console with CONFIG_MMC_CLKGATE. * @flags: Random state bits associated with the slot. * @id: Number of this slot. * @sdio_id: Number of this slot in the SDIO interrupt registers. @@ -263,6 +264,7 @@ struct dw_mci_slot { unsigned int clock; unsigned int __clk_old; + unsigned int __div_old; unsigned long flags; #define DW_MMC_CARD_PRESENT 0