From patchwork Wed Sep 24 06:30:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 4963251 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E9AE09F32B for ; Wed, 24 Sep 2014 09:03:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ABC0620173 for ; Wed, 24 Sep 2014 09:03:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 09B8820136 for ; Wed, 24 Sep 2014 09:03:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753711AbaIXJDR (ORCPT ); Wed, 24 Sep 2014 05:03:17 -0400 Received: from mail-bl2on0105.outbound.protection.outlook.com ([65.55.169.105]:33120 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751247AbaIXJDN (ORCPT ); Wed, 24 Sep 2014 05:03:13 -0400 X-Greylist: delayed 3594 seconds by postgrey-1.27 at vger.kernel.org; Wed, 24 Sep 2014 05:03:13 EDT Received: from BN3PR0301CA0012.namprd03.prod.outlook.com (25.160.180.150) by CY1PR0301MB0619.namprd03.prod.outlook.com (25.160.142.26) with Microsoft SMTP Server (TLS) id 15.0.1034.13; Wed, 24 Sep 2014 06:30:50 +0000 Received: from BN1BFFO11FD020.protection.gbl (2a01:111:f400:7c10::1:122) by BN3PR0301CA0012.outlook.office365.com (2a01:111:e400:4000::22) with Microsoft SMTP Server (TLS) id 15.0.1034.13 via Frontend Transport; Wed, 24 Sep 2014 06:30:50 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1BFFO11FD020.mail.protection.outlook.com (10.58.144.83) with Microsoft SMTP Server (TLS) id 15.0.1029.15 via Frontend Transport; Wed, 24 Sep 2014 06:30:49 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id s8O6UkuE027289; Tue, 23 Sep 2014 23:30:47 -0700 From: Xiubo Li To: CC: , Xiubo Li Subject: [PATCH] spi: Fix possible ZERO_SIZE_PTR pointer dereferencing error. Date: Wed, 24 Sep 2014 14:30:29 +0800 Message-ID: <1411540229-24915-1-git-send-email-Li.Xiubo@freescale.com> X-Mailer: git-send-email 2.1.0.27.g96db324 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(199003)(189002)(20776003)(88136002)(77156001)(36756003)(104166001)(47776003)(106466001)(64706001)(102836001)(50986999)(89996001)(120916001)(99396003)(10300001)(229853001)(84676001)(107046002)(86362001)(74502003)(76482002)(68736004)(4396001)(48376002)(85852003)(46102003)(97736003)(81542003)(50226001)(81342003)(110136001)(31966008)(74662003)(62966002)(77982003)(92566001)(83072002)(19580395003)(44976005)(87286001)(50466002)(104016003)(93916002)(21056001)(92726001)(80022003)(105606002)(95666004)(79102003)(85306004)(83322001)(6806004)(19580405001)(2351001)(87936001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0301MB0619; H:tx30smr01.am.freescale.net; FPR:; MLV:sfv; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0619; X-Forefront-PRVS: 03449D5DD1 Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=Li.Xiubo@freescale.com; X-OriginatorOrg: freescale.com Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Since we cannot make sure the 'n' will always be none zero here, and then if either equal to zero, the kzalloc() will return ZERO_SIZE_PTR, which equals to ((void *)16). So this patch fix this with just doing the zero check before calling kzalloc(). Signed-off-by: Xiubo Li --- drivers/spi/spi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 95cfe3b..e19512f 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -552,6 +552,9 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n) struct boardinfo *bi; int i; + if (!n) + return -EINVAL; + bi = kzalloc(n * sizeof(*bi), GFP_KERNEL); if (!bi) return -ENOMEM;