From patchwork Wed Aug 24 11:43:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 9297579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1010A607F0 for ; Wed, 24 Aug 2016 11:46:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F245328F29 for ; Wed, 24 Aug 2016 11:46:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4CE028F2E; Wed, 24 Aug 2016 11:46:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7FC7A28F29 for ; Wed, 24 Aug 2016 11:46:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcWbj-0001q2-UO; Wed, 24 Aug 2016 11:44:35 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bcWbe-0001kc-PX for linux-arm-kernel@lists.infradead.org; Wed, 24 Aug 2016 11:44:31 +0000 Received: by mail-wm0-x242.google.com with SMTP id q128so2265584wma.1 for ; Wed, 24 Aug 2016 04:44:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=PFtKMM9MkPXO4o+nG50ZLP2lwe68+GtiJoRjVn3ix6o=; b=hh7/yzueDM9VW/ls6/MEe9P9Qx0zv+bfuMWNbuC7elv+Fy7R78Jag7IkFJmreM+SOw VrkwrDY4Y9WPJ/4giGFBWcexNQfBLNtUqpXNK+3feDla6F9OCLqyaVMQ8XrYJWWy6KvD K83gthPXxrm2dVEfsxYUf+t0tLBjo0Bi4o7Bb7KHjIS3JaQuau5XRlMIjCnsCk7LxiUN xiR9TWlOe5BTvB2QW4R2l51tjzol1K8kyUqojff7aCSqa/pltCNI5DemCsji8tsyned8 vnKnJaNJ6GunWoJMOwQQJ0wuTPzCW+b2edX7SSxsVmnQoYoW4c4X8NwMdNdblPT28Tiz 4O8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PFtKMM9MkPXO4o+nG50ZLP2lwe68+GtiJoRjVn3ix6o=; b=Kbnm4UxSiJQF3kK1WLFCCEB+GtzTTtE7OAZKxBJ82sS2BTv6KNeUsP0DmOGh2Yr3vh OQgN8KDqm3ZsayMzZr863ZHH5fMKdy2/31cjEFRRkqpOi+faATBjxckabSuzCf/wdY1K wkjfuDrNMIjIPIJdZEtxqHzrLOdulHH8WHO7IjGVQSyIUlBYE7lbgnsNMzLicNyWFefl ueXLNv9TvLqU5Ng+gme4cDtGfwW9MeFJiJX/vsPfQ22dinVJCoA6edhpXZlr58r5kGSv 4DBPGqayuognT1E8uj0PBnBDbRH1M3UFkLwwByQ2YrjXf1UjGWjWrq/XDqKVsnbMvm6w +FKQ== X-Gm-Message-State: AEkoouuS2K5w6Sy7x4ant+udQNEBZoVZ9t6lv0t8KpiTHB6st/4ShyCQcFHNFjDz+ZNHMA== X-Received: by 10.28.215.81 with SMTP id o78mr23670373wmg.42.1472039048968; Wed, 24 Aug 2016 04:44:08 -0700 (PDT) Received: from Red.local (ANice-651-1-336-61.w86-205.abo.wanadoo.fr. [86.205.8.61]) by smtp.googlemail.com with ESMTPSA id s184sm33274225wmb.11.2016.08.24.04.44.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Aug 2016 04:44:08 -0700 (PDT) From: LABBE Corentin To: thierry.reding@gmail.com, maxime.ripard@free-electrons.com, wens@csie.org Subject: [PATCH v3] pwm: sun4i: fix a possible NULL dereference Date: Wed, 24 Aug 2016 13:43:58 +0200 Message-Id: <1472039038-4047-1-git-send-email-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.7.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160824_044431_076098_B10402B4 X-CRM114-Status: GOOD ( 11.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, linux-sunxi@googlegroups.com, LABBE Corentin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP of_match_device could return NULL, and so cause a NULL pointer dereference later. For fixing this problem, we use of_device_get_match_data(), this will simplify the code a little by using a standard function for getting the match data. Testing the return value of of_device_get_match_data is also necessary for avoiding a second NULL deref on pwm->data. Reported-by: coverity (CID 1324139) Signed-off-by: LABBE Corentin --- Changes since v2: - Add a test on pwm->data for avoiding a second NULL deref. Changes since v1: - Use of_device_get_match_data() drivers/pwm/pwm-sun4i.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c index 03a99a5..fb76c55 100644 --- a/drivers/pwm/pwm-sun4i.c +++ b/drivers/pwm/pwm-sun4i.c @@ -309,9 +309,6 @@ static int sun4i_pwm_probe(struct platform_device *pdev) struct resource *res; u32 val; int i, ret; - const struct of_device_id *match; - - match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev); pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); if (!pwm) @@ -326,7 +323,9 @@ static int sun4i_pwm_probe(struct platform_device *pdev) if (IS_ERR(pwm->clk)) return PTR_ERR(pwm->clk); - pwm->data = match->data; + pwm->data = of_device_get_match_data(&pdev->dev); + if (!pwm->data) + return -EINVAL; pwm->chip.dev = &pdev->dev; pwm->chip.ops = &sun4i_pwm_ops; pwm->chip.base = -1;