From patchwork Thu Apr 20 14:38:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 9690665 X-Patchwork-Delegate: geert@linux-m68k.org 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 5B03F60383 for ; Thu, 20 Apr 2017 14:39:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D18D26E54 for ; Thu, 20 Apr 2017 14:39:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 402652848B; Thu, 20 Apr 2017 14:39:14 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1123326E54 for ; Thu, 20 Apr 2017 14:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967046AbdDTOjM (ORCPT ); Thu, 20 Apr 2017 10:39:12 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:33550 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966132AbdDTOjL (ORCPT ); Thu, 20 Apr 2017 10:39:11 -0400 Received: by mail-oi0-f68.google.com with SMTP id a189so10323442oib.0 for ; Thu, 20 Apr 2017 07:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=f+TwZKAOE746SXgJTdvyruIWKJjdgfeXJv8t7WTutBA=; b=DMX9/ivWrR/mFg6isD4z1amCGL7VrvD/O3BTLurgJjjMgqmtq83IwrUR2j1hMVdmZw Z28eqzTcuQlcY8HVmb1mTSH/JQZTE0G236irhwVdo8Mkb/vVnmj0lfP3Erfydzd0FZdf DjzOKLnENuweAJCDAvgqMv8Vx9izra4XLt/apYKVHb0xylwChvaAeFtrt3D62NSrBXVA JZq9QR+gZHSTGM7czIzoeiELNwK0Up9gYUFtfdSB+/d5WuHbDAVZmLd9BzyzWowQsrAp 23DVcHKCCU/HAxAT/ZyVDTWi+U6FAM+FnqFuo3z9XgVr4Fbjr0k42gaZ+lvuuR2yNlNE QEJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=f+TwZKAOE746SXgJTdvyruIWKJjdgfeXJv8t7WTutBA=; b=jPiwLEV4Q+JWFH9D8kt0Xy8hJnIrbND1ltQL4P/JPY/nwU2rJynq+81KN0gCVI72NY 8HgNtG7kZAIQEhCkxP/5KDXgstmogB02zESgA0STqdzYQXomNska7qGrm5YVKBMk3Yos B+fJhLDK0ViHtxKDNWIXDdh+XHiwe5ayGgs1VZDI5sKvSLwbhKrtLXRI7aV8iTF3YPxf GcSuW0FZ1SxZfFajJwYjluoKDT1qVhWSew9FuuG+0LXbQSQbnS6IwGKjbND8zlsp/rY6 tNu9hKrmyBBI71M57CO7MbREbJRAUDMvaCnBJgEtLtEc5SLGbQj452gEeECsn/QHltq2 ASDw== X-Gm-Message-State: AN3rC/6TdH886wG6QTs0I9k0bNeFPEgtPdu5fSwBX6iYJkEwxCymbate wR8w0z5eb1RGEQ== X-Received: by 10.157.39.161 with SMTP id c30mr4425424otb.135.1492699150721; Thu, 20 Apr 2017 07:39:10 -0700 (PDT) Received: from kurokawa.lan ([195.140.253.167]) by smtp.gmail.com with ESMTPSA id d8sm2597101otd.45.2017.04.20.07.39.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 07:39:10 -0700 (PDT) From: Marek Vasut X-Google-Original-From: Marek Vasut To: alsa-devel@alsa-project.org Cc: Marek Vasut , Geert Uytterhoeven , Hiroyuki Yokoyama , Kuninori Morimoto , Mark Brown , linux-renesas-soc@vger.kernel.org Subject: [PATCH] ASoC: rsnd: Fix possible NULL pointer dereference Date: Thu, 20 Apr 2017 16:38:58 +0200 Message-Id: <20170420143858.32150-1-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In case the "clock-frequency" DT property is not present, the of_find_property(np, "clock-frequency", NULL) will return NULL and the subsequent req_size = prop->length / sizeof(u32); will trigger a NULL pointer dereference. This patch adds check for the NULL return value and propagates the error into the caller of the function. Signed-off-by: Marek Vasut Cc: Geert Uytterhoeven Cc: Hiroyuki Yokoyama Cc: Kuninori Morimoto Cc: Mark Brown Cc: linux-renesas-soc@vger.kernel.org --- sound/soc/sh/rcar/adg.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c index 96fef91b480c..a7cbe7e89dfc 100644 --- a/sound/soc/sh/rcar/adg.c +++ b/sound/soc/sh/rcar/adg.c @@ -425,8 +425,7 @@ static void rsnd_adg_get_clkin(struct rsnd_priv *priv, dev_dbg(dev, "clk %d : %p : %ld\n", i, clk, clk_get_rate(clk)); } -static void rsnd_adg_get_clkout(struct rsnd_priv *priv, - struct rsnd_adg *adg) +static int rsnd_adg_get_clkout(struct rsnd_priv *priv, struct rsnd_adg *adg) { struct clk *clk; struct device *dev = rsnd_priv_to_dev(priv); @@ -459,7 +458,10 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, * ADG supports BRRA/BRRB output only * this means all clkout0/1/2/3 will be same rate */ - prop = of_find_property(np, "clock-frequency", NULL);; + prop = of_find_property(np, "clock-frequency", NULL); + if (!prop) + return -EINVAL; + req_size = prop->length / sizeof(u32); of_property_read_u32_array(np, "clock-frequency", req_rate, req_size); @@ -568,6 +570,7 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv, dev_dbg(dev, "clkout %d : %p : %ld\n", i, clk, clk_get_rate(clk)); dev_dbg(dev, "BRGCKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n", ckr, rbga, rbgb); + return 0; } int rsnd_adg_probe(struct rsnd_priv *priv) @@ -589,7 +592,9 @@ int rsnd_adg_probe(struct rsnd_priv *priv) return ret; rsnd_adg_get_clkin(priv, adg); - rsnd_adg_get_clkout(priv, adg); + ret = rsnd_adg_get_clkout(priv, adg); + if (ret) + return ret; if (of_get_property(np, "clkout-lr-asynchronous", NULL)) adg->flags = LRCLK_ASYNC;