From patchwork Mon May 11 07:35:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6373621 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EDF6DBEEE1 for ; Mon, 11 May 2015 07:35:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0DD8A2024F for ; Mon, 11 May 2015 07:35:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1FCCE2022D for ; Mon, 11 May 2015 07:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752199AbbEKHfd (ORCPT ); Mon, 11 May 2015 03:35:33 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:8032 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752712AbbEKHfd (ORCPT ); Mon, 11 May 2015 03:35:33 -0400 Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie3.idc.renesas.com with ESMTP; 11 May 2015 16:35:32 +0900 Received: from relmlac2.idc.renesas.com (relmlac2.idc.renesas.com [10.200.69.22]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id 1FBAB4B65F; Mon, 11 May 2015 16:35:32 +0900 (JST) Received: by relmlac2.idc.renesas.com (Postfix, from userid 0) id 0D5E32806E; Mon, 11 May 2015 16:35:32 +0900 (JST) Received: from relmlac2.idc.renesas.com (localhost [127.0.0.1]) by relmlac2.idc.renesas.com (Postfix) with ESMTP id 080A62806D; Mon, 11 May 2015 16:35:32 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac2.idc.renesas.com with ESMTP id SAA10809; Mon, 11 May 2015 16:35:32 +0900 X-IronPort-AV: E=Sophos;i="5.13,404,1427727600"; d="scan'208";a="185903460" Received: from mail-sg1lp0091.outbound.protection.outlook.com (HELO APAC01-SG1-obe.outbound.protection.outlook.com) ([207.46.51.91]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 11 May 2015 16:35:30 +0900 Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none; Received: from morimoto-PC.renesas.com (211.11.155.132) by SIXPR06MB320.apcprd06.prod.outlook.com (10.141.125.150) with Microsoft SMTP Server (TLS) id 15.1.154.19; Mon, 11 May 2015 07:35:28 +0000 Message-ID: <87sib336w4.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 2/2 v2] mmc: cast unsigned int to typeof(sector_t) to avoid unexpected error User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") To: Ulf Hansson CC: , , , , Jaehoon Chung , Chris Ball , Seungwon Jeon , =?ISO-8859-1?Q?=22Gr=E9gory_Soutad?= =?ISO-8859-1?Q?=E9=22?= , , In-Reply-To: <87vbfz36yh.wl%kuninori.morimoto.gx@renesas.com> References: <87wq1n5bht.wl%kuninori.morimoto.gx@renesas.com> <87vbfz36yh.wl%kuninori.morimoto.gx@renesas.com> Date: Mon, 11 May 2015 07:35:28 +0000 X-Originating-IP: [211.11.155.132] X-ClientProxiedBy: TY1PR01CA0045.jpnprd01.prod.outlook.com (25.164.162.155) To SIXPR06MB320.apcprd06.prod.outlook.com (10.141.125.150) X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SIXPR06MB320; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:SIXPR06MB320; BCL:0; PCL:0; RULEID:; SRVR:SIXPR06MB320; X-Forefront-PRVS: 05739BA1B5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(53416004)(42186005)(77096005)(229853001)(77156002)(92566002)(50466002)(87976001)(4001350100001)(46406003)(19580405001)(5001960100002)(19580395003)(110136002)(15975445007)(46102003)(2950100001)(189998001)(33646002)(66066001)(122386002)(47776003)(40100003)(86362001)(54356999)(76176999)(36756003)(50986999)(62966003)(93886004); DIR:OUT; SFP:1102; SCL:1; SRVR:SIXPR06MB320; H:morimoto-PC.renesas.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2015 07:35:28.4683 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB320 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kuninori Morimoto card->csd.capacity is defined as "unsigned int", and sector_t is defined as "u64" or "unsigned long" (depends on CONFIG_LBDAF). Thus, sector_t data might have strange data (see below). This patch cast it to typeof(sector_t) Special thanks to coverity ex) if sector_t was u64 unsigned int data; sector_t sector; data = 0x800000; sector = (data << 8); // 0xffffffff80000000 sector = (((typeof(sector_t))data) << 8); // 0x80000000 or data = 0x80000000; sector = (data << 8); // 0x0 sector = (((typeof(sector_t))data) << 8); // 0x8000000000 Signed-off-by: Kuninori Morimoto --- v1 -> v2 - tidyup log comment - tidyup line over 80 characters drivers/mmc/card/block.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 60f7141..029a872 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -2217,7 +2217,8 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card) * The CSD capacity field is in units of read_blkbits. * set_capacity takes units of 512 bytes. */ - size = card->csd.capacity << (card->csd.read_blkbits - 9); + size = (typeof(sector_t))card->csd.capacity + << (card->csd.read_blkbits - 9); } return mmc_blk_alloc_req(card, &card->dev, size, false, NULL,