From patchwork Tue Apr 14 04:07:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6213661 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 6014CBF4A6 for ; Tue, 14 Apr 2015 04:07:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E60C20148 for ; Tue, 14 Apr 2015 04:07:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8241E20145 for ; Tue, 14 Apr 2015 04:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751900AbbDNEHi (ORCPT ); Tue, 14 Apr 2015 00:07:38 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:53136 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751715AbbDNEHh (ORCPT ); Tue, 14 Apr 2015 00:07:37 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie1.idc.renesas.com with ESMTP; 14 Apr 2015 13:07:33 +0900 Received: from relmlac1.idc.renesas.com (relmlac1.idc.renesas.com [10.200.69.21]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id CB5F049C48; Tue, 14 Apr 2015 13:07:33 +0900 (JST) Received: by relmlac1.idc.renesas.com (Postfix, from userid 0) id C33088002F; Tue, 14 Apr 2015 13:07:33 +0900 (JST) Received: from relmlac1.idc.renesas.com (localhost [127.0.0.1]) by relmlac1.idc.renesas.com (Postfix) with ESMTP id A5A458002D; Tue, 14 Apr 2015 13:07:33 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac1.idc.renesas.com with ESMTP id PAE25676; Tue, 14 Apr 2015 13:07:33 +0900 X-IronPort-AV: E=Sophos;i="5.11,573,1422889200"; d="scan'208";a="183975278" Received: from mail-sg1lp0085.outbound.protection.outlook.com (HELO APAC01-SG1-obe.outbound.protection.outlook.com) ([207.46.51.85]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 14 Apr 2015 13:07:32 +0900 Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none; Received: from morimoto-PC.renesas.com (211.11.155.132) by SINPR06MB316.apcprd06.prod.outlook.com (10.141.115.155) with Microsoft SMTP Server (TLS) id 15.1.136.25; Tue, 14 Apr 2015 04:07:30 +0000 Message-ID: <87r3rnbbga.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 1/2] mmc: cast u8 to unsigned long long 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:30 +0000 X-Originating-IP: [211.11.155.132] X-ClientProxiedBy: KAWPR01CA0015.jpnprd01.prod.outlook.com (25.161.24.25) To SINPR06MB316.apcprd06.prod.outlook.com (10.141.115.155) X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SINPR06MB316; X-Microsoft-Antispam-PRVS: X-Forefront-Antispam-Report: BMV:1; SFV:NSPM; SFS:(10019020)(6009001)(47776003)(86362001)(33646002)(42186005)(46406003)(110136001)(66066001)(50986999)(54356999)(2950100001)(19580395003)(76176999)(93886004)(46102003)(83506001)(50466002)(87976001)(92566002)(229853001)(77156002)(15975445007)(4001350100001)(62966003)(122386002)(36756003)(23726002)(77096005)(19580405001)(53416004)(223183001); DIR:OUT; SFP:1102; SCL:1; SRVR:SINPR06MB316; H:morimoto-PC.renesas.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(5002010); SRVR:SINPR06MB316; BCL:0; PCL:0; RULEID:; SRVR:SINPR06MB316; X-Forefront-PRVS: 054642504A X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2015 04:07:30.6362 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SINPR06MB316 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->ext_csd.enhanced_area_offset is defined as "unsigned long long", and, ext_csd[] is defined as u8. unsigned long long data might have strange data if first bit of ext_csd[] was 1. this patch cast it to (unsigned long long) ex) u8 data8; u64 data64; data8 = 0x80; data64 = (data8 << 24); // 0xffffffff80000000 data64 = (((unsigned long long)data8) << 24); // 0x80000000; Reported-by: coverity Signed-off-by: Kuninori Morimoto --- drivers/mmc/core/mmc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index c84131e..c6bb577 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -266,8 +266,10 @@ static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd) * calculate the enhanced data area offset, in bytes */ card->ext_csd.enhanced_area_offset = - (ext_csd[139] << 24) + (ext_csd[138] << 16) + - (ext_csd[137] << 8) + ext_csd[136]; + (((unsigned long long)ext_csd[139]) << 24) + + (((unsigned long long)ext_csd[138]) << 16) + + (((unsigned long long)ext_csd[137]) << 8) + + (((unsigned long long)ext_csd[136])); if (mmc_card_blockaddr(card)) card->ext_csd.enhanced_area_offset <<= 9; /*