Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1914574pxk; Sat, 26 Sep 2020 09:21:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3LHayA0nR5SWL2VmiLNtNXbKtY9NbgkX5J3KZPfgeHMaCh+YmRlYhsy2RT7sNrMl26K/u X-Received: by 2002:aa7:c3d4:: with SMTP id l20mr7384900edr.263.1601137274731; Sat, 26 Sep 2020 09:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601137274; cv=none; d=google.com; s=arc-20160816; b=wlQ6+8I1CPzo0ZskSWppKrvoQfBdhop4gQ/JgDCfLSNR6e4rlPIDwR2X0Fk40wMigf M6ZZIkkAiiVufLJbWtySlBkWb3yWKzI/6KRO0GPdsGhGrd6b9iNjXPhbiVmq/uKCOHp0 0RodLMQM+EX/7UBRYSbjOfZ21lh4sr58ii7LuNCV3SuplI/f6OcAP0DIIQSs5TZaNlCj ToFt1ltmWSHfGXjPWoGNq0t6q/tsaoqTBamnFbRY8yaFVxoqMttKU5jLEtJTbBSiTIZI TI7Pz8R9W5S9Pp7jE8VIvMfQRSA5605axWXHisCkpL78LmcQ1yDwO+lVmmMRxdxnyBXr C8tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date; bh=hnWG17dUJpzBXiTkQwSm1Ckn+rczK0ZF/zCc8+5Ukwg=; b=vY+sqMQWYAI8pYbwC1RrhfQsPMIfvhyID5uZqLE14kcqCQb+MulDIeIxNqhToEwVdc HaBKYw3trJijKFRdrF0axYgxOTjooqEevOWNhvByLtdiHooVNA9bR7C0CfmVaPAsde+f QJWIU1Q8xi8KAsnXgG1BlRK/PuL7fjgsQ7BLBB3aDTrk+m3ei4fOsGlwc0VK3HqSdOO1 Ny+Db5rkKVDAi4aYnN6XFT5seR5H38CyhItVOQyofSGTg3Cg28vy5M0qVI+7N+fdT/k0 rcFju3fFc/Hcdd9v6uIx57i+/LTUoLSPtM5AsrIfbyZvMMry4WDnCBvNd3AzYfKRSDrs +YqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q25si4381940edb.467.2020.09.26.09.20.49; Sat, 26 Sep 2020 09:21:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729810AbgIZQTs (ORCPT + 99 others); Sat, 26 Sep 2020 12:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728017AbgIZQTs (ORCPT ); Sat, 26 Sep 2020 12:19:48 -0400 Received: from agrajag.zerfleddert.de (agrajag.zerfleddert.de [IPv6:2a01:4f8:bc:1de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56D16C0613CE; Sat, 26 Sep 2020 09:19:48 -0700 (PDT) Received: by agrajag.zerfleddert.de (Postfix, from userid 1000) id AFB4C5B2057C; Sat, 26 Sep 2020 18:19:46 +0200 (CEST) Date: Sat, 26 Sep 2020 18:19:46 +0200 From: Tobias Jordan To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron Cc: Marek Vasut , Lars-Peter Clausen , Peter Meerwald-Stadler Subject: [PATCH v2] iio: adc: gyroadc: fix leak of device node iterator Message-ID: <20200926161946.GA10240@agrajag.zerfleddert.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add missing of_node_put calls when exiting the for_each_child_of_node loop in rcar_gyroadc_parse_subdevs early. Also add goto-exception handling for the error paths in that loop. Fixes: 059c53b32329 ("iio: adc: Add Renesas GyroADC driver") Signed-off-by: Tobias Jordan --- v2: - added an of_node_put to the non-error "break" at the end - used gotos for the error cases, doesn't look as bad as I thought drivers/iio/adc/rcar-gyroadc.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/rcar-gyroadc.c b/drivers/iio/adc/rcar-gyroadc.c index dcaefc108ff6..9f38cf3c7dc2 100644 --- a/drivers/iio/adc/rcar-gyroadc.c +++ b/drivers/iio/adc/rcar-gyroadc.c @@ -357,7 +357,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) num_channels = ARRAY_SIZE(rcar_gyroadc_iio_channels_3); break; default: - return -EINVAL; + goto err_e_inval; } /* @@ -374,7 +374,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) dev_err(dev, "Failed to get child reg property of ADC \"%pOFn\".\n", child); - return ret; + goto err_of_node_put; } /* Channel number is too high. */ @@ -382,7 +382,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) dev_err(dev, "Only %i channels supported with %pOFn, but reg = <%i>.\n", num_channels, child, reg); - return -EINVAL; + goto err_e_inval; } } @@ -391,7 +391,7 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) dev_err(dev, "Channel %i uses different ADC mode than the rest.\n", reg); - return -EINVAL; + goto err_e_inval; } /* Channel is valid, grab the regulator. */ @@ -401,7 +401,8 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) if (IS_ERR(vref)) { dev_dbg(dev, "Channel %i 'vref' supply not connected.\n", reg); - return PTR_ERR(vref); + ret = PTR_ERR(vref); + goto err_of_node_put; } priv->vref[reg] = vref; @@ -425,8 +426,10 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) * attached to the GyroADC at a time, so if we found it, * we can stop parsing here. */ - if (childmode == RCAR_GYROADC_MODE_SELECT_1_MB88101A) + if (childmode == RCAR_GYROADC_MODE_SELECT_1_MB88101A) { + of_node_put(child); break; + } } if (first) { @@ -435,6 +438,12 @@ static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev) } return 0; + +err_e_inval: + ret = -EINVAL; +err_of_node_put: + of_node_put(child); + return ret; } static void rcar_gyroadc_deinit_supplies(struct iio_dev *indio_dev) -- 2.20.1