From patchwork Thu Nov 22 07:46:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 10693633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BBDA14BD for ; Thu, 22 Nov 2018 07:54:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 599E92BD04 for ; Thu, 22 Nov 2018 07:54:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DE5E2C5AE; Thu, 22 Nov 2018 07:54:31 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DF7602BD04 for ; Thu, 22 Nov 2018 07:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=QbZmq48hcDXhs65CBtaEmwoidk+X5fkNG6XOyEDlEpY=; b=X+I OoUsCWmmk4Z8JLhdQubQzwCzrzJfA4oJO8b8MOp5Woi4sEJQRkh/HrFfGpArjb+toJ8tgSRSfCFva 0famKYVEQ59okn4eWywUdVaKX44s5W+91uUc6tTtRdsE4tlKyAeD9Jls0m38NCCAI0jPulFa1FQ6B FXDPlidTm5EX1669mGVF2pux2H47KuHAcJ37bK983Idf4DaX7A6lt0AOYEVGLU3BZnpDnjGA27Cro ubS+YVpUvHhYtYwrEhZi4x1fk3Qe/EoSPGXmAzOIxotup61T8V0CcgG8LdD0fUhDTbz1FVyStx0sl F442B9AMrFLFNa44ygSn4Val60wXoJw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPjoh-0006Sc-HA; Thu, 22 Nov 2018 07:54:27 +0000 Received: from www.osadl.org ([62.245.132.105]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPjod-0006Qs-7c; Thu, 22 Nov 2018 07:54:25 +0000 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wAM7nbFG012201; Thu, 22 Nov 2018 08:49:37 +0100 From: Nicholas Mc Guire To: Jonathan Cameron Subject: [PATCH] iio: adc: meson-saradc: check for devm_kasprintf failure Date: Thu, 22 Nov 2018 08:46:43 +0100 Message-Id: <1542872803-29060-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181121_235423_583354_CE6DA095 X-CRM114-Status: UNSURE ( 8.13 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Lars-Peter Clausen , Greg Kroah-Hartman , Martin Blumenstingl , Kevin Hilman , Nicholas Mc Guire , Yixun Lan , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Dan Carpenter , Peter Meerwald-Stadler , Hartmut Knaack , Carlo Caione , linux-amlogic@lists.infradead.org, Xingyu Chen 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 devm_kasprintf() may return NULL on failure of internal allocation thus the assignments to init.name are not safe if not checked. On error meson_sar_adc_clk_init() returns negative values so -ENOMEM in the (unlikely) failure case of devm_kasprintf() should be fine here. Signed-off-by: Nicholas Mc Guire Fixes: 3adbf3427330 ("iio: adc: add a driver for the SAR ADC found in Amlogic Meson SoCs") Acked-by: Martin Blumenstingl --- Problem located with an experimental coccinelle script Patch was compile tested with: multi_v7_defconfig (implies ARCH_MESON=y & MESON_SARADC=y) Patch is against 4.20-rc3 (localversion-next is next-20181122) drivers/iio/adc/meson_saradc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index 028ccd2..672a5de 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -589,6 +589,9 @@ static int meson_sar_adc_clk_init(struct iio_dev *indio_dev, init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%pOF#adc_div", indio_dev->dev.of_node); + if (!init.name) + return -ENOMEM; + init.flags = 0; init.ops = &clk_divider_ops; clk_parents[0] = __clk_get_name(priv->clkin); @@ -608,6 +611,9 @@ static int meson_sar_adc_clk_init(struct iio_dev *indio_dev, init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%pOF#adc_en", indio_dev->dev.of_node); + if (!init.name) + return -ENOMEM; + init.flags = CLK_SET_RATE_PARENT; init.ops = &clk_gate_ops; clk_parents[0] = __clk_get_name(priv->adc_div_clk);