From patchwork Tue Apr 14 04:07:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6213681 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5F05E9F1C4 for ; Tue, 14 Apr 2015 04:08:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 839DB20148 for ; Tue, 14 Apr 2015 04:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 997DF20145 for ; Tue, 14 Apr 2015 04:08:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751893AbbDNEID (ORCPT ); Tue, 14 Apr 2015 00:08:03 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:39144 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751715AbbDNEIC (ORCPT ); Tue, 14 Apr 2015 00:08:02 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie1.idc.renesas.com with ESMTP; 14 Apr 2015 13:08:01 +0900 Received: from relmlac2.idc.renesas.com (relmlac2.idc.renesas.com [10.200.69.22]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 30C8249C6E; Tue, 14 Apr 2015 13:08:01 +0900 (JST) Received: by relmlac2.idc.renesas.com (Postfix, from userid 0) id 2E6562806F; Tue, 14 Apr 2015 13:08:01 +0900 (JST) Received: from relmlac2.idc.renesas.com (localhost [127.0.0.1]) by relmlac2.idc.renesas.com (Postfix) with ESMTP id 2768D2806D; Tue, 14 Apr 2015 13:08:01 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac2.idc.renesas.com with ESMTP id PAJ22179; Tue, 14 Apr 2015 13:08:01 +0900 X-IronPort-AV: E=Sophos;i="5.11,573,1422889200"; d="scan'208";a="185124337" Received: from mail-sg1lp0092.outbound.protection.outlook.com (HELO APAC01-SG1-obe.outbound.protection.outlook.com) ([207.46.51.92]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 14 Apr 2015 13:07:59 +0900 Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none; Received: from morimoto-PC.renesas.com (211.11.155.132) by HKNPR06MB307.apcprd06.prod.outlook.com (10.141.37.27) with Microsoft SMTP Server (TLS) id 15.1.136.25; Tue, 14 Apr 2015 04:07:57 +0000 Message-ID: <87pp77bbfl.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 2/2] mmc: cast unsigned int to typeof(sector_t) to avoid unexpected error User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 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: <87sic3bbhd.wl%kuninori.morimoto.gx@renesas.com> References: <87wq1n5bht.wl%kuninori.morimoto.gx@renesas.com> <87sic3bbhd.wl%kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Date: Tue, 14 Apr 2015 04:07:57 +0000 X-Originating-IP: [211.11.155.132] X-ClientProxiedBy: TY1PR01CA0048.jpnprd01.prod.outlook.com (25.164.162.158) To HKNPR06MB307.apcprd06.prod.outlook.com (10.141.37.27) X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HKNPR06MB307; X-Forefront-Antispam-Report: BMV:1; SFV:NSPM; SFS:(10019020)(6009001)(87976001)(110136001)(76176999)(50466002)(23726002)(83506001)(4001350100001)(46102003)(50986999)(19580405001)(19580395003)(122386002)(229853001)(66066001)(42186005)(86362001)(575784001)(15975445007)(33646002)(36756003)(77156002)(62966003)(2950100001)(92566002)(53416004)(77096005)(47776003)(46406003)(93886004)(54356999); DIR:OUT; SFP:1102; SCL:1; SRVR:HKNPR06MB307; H:morimoto-PC.renesas.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5002010)(5005006); SRVR:HKNPR06MB307; BCL:0; PCL:0; RULEID:; SRVR:HKNPR06MB307; X-Forefront-PRVS: 054642504A X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2015 04:07:57.6250 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HKNPR06MB307 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) sector_t data might have strange data if first bit of unsigned int was 1. this patch cast it to typeof(sector_t) 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 Reported-by: coverity Signed-off-by: Kuninori Morimoto --- drivers/mmc/card/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index c69afb5..4d09b0c 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -2205,7 +2205,7 @@ 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,