From patchwork Mon Aug 18 09:08:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 380772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E4A6F14010B for ; Mon, 18 Aug 2014 19:13:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751733AbaHRJNP (ORCPT ); Mon, 18 Aug 2014 05:13:15 -0400 Received: from mail-bl2lp0208.outbound.protection.outlook.com ([207.46.163.208]:23123 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751722AbaHRJNP (ORCPT ); Mon, 18 Aug 2014 05:13:15 -0400 Received: from BN3PR0301CA0070.namprd03.prod.outlook.com (25.160.152.166) by CY1PR0301MB0619.namprd03.prod.outlook.com (25.160.142.26) with Microsoft SMTP Server (TLS) id 15.0.1005.10; Mon, 18 Aug 2014 09:12:58 +0000 Received: from BY2FFO11FD017.protection.gbl (2a01:111:f400:7c0c::178) by BN3PR0301CA0070.outlook.office365.com (2a01:111:e400:401e::38) with Microsoft SMTP Server (TLS) id 15.0.1010.18 via Frontend Transport; Mon, 18 Aug 2014 09:12:57 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD017.mail.protection.outlook.com (10.1.14.105) with Microsoft SMTP Server (TLS) id 15.0.1010.11 via Frontend Transport; Mon, 18 Aug 2014 09:12:57 +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 s7I9CswT025871; Mon, 18 Aug 2014 02:12:55 -0700 From: Xiubo Li To: , CC: Xiubo Li Subject: [PATCH] pwm: Fix possible ZERO_SIZE_PTR pointer dereferencing error. Date: Mon, 18 Aug 2014 17:08:44 +0800 Message-ID: <1408352924-19122-1-git-send-email-Li.Xiubo@freescale.com> X-Mailer: git-send-email 1.8.5 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019005)(6009001)(189002)(199003)(575784001)(97736001)(74662001)(62966002)(92726001)(86362001)(31966008)(19580405001)(77156001)(85306004)(6806004)(46102001)(83322001)(19580395003)(93916002)(68736004)(50986999)(77982001)(88136002)(89996001)(92566001)(85852003)(21056001)(4396001)(50226001)(74502001)(87286001)(83072002)(107046002)(105606002)(99396002)(80022001)(76482001)(84676001)(229853001)(106466001)(104016003)(95666004)(104166001)(20776003)(50466002)(26826002)(36756003)(48376002)(44976005)(47776003)(81342001)(79102001)(64706001)(102836001)(81542001)(87936001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0301MB0619; H:tx30smr01.am.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:; X-Forefront-PRVS: 03077579FF 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-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org Since we cannot make sure the 'chip->npwm' 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/pwm/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 4b66bf0..786d0f1 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -236,7 +236,7 @@ int pwmchip_add(struct pwm_chip *chip) int ret; if (!chip || !chip->dev || !chip->ops || !chip->ops->config || - !chip->ops->enable || !chip->ops->disable) + !chip->ops->enable || !chip->ops->disable || !chip->npwm) return -EINVAL; mutex_lock(&pwm_lock);