Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4776417imm; Mon, 18 Jun 2018 23:00:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLiti96oy0IXrqi3QirrjglnfRqi9zFFM3NbOwiqbHwB3Y2wj9HWVa0XmVtXbxNq8h+ts8M X-Received: by 2002:a65:64d3:: with SMTP id t19-v6mr13658463pgv.148.1529388033609; Mon, 18 Jun 2018 23:00:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529388033; cv=none; d=google.com; s=arc-20160816; b=iQujezxmJMhFaD+jBJYwfBI1y+VXUNyTkkvsho9VD412iIkkn06nzgdqE3koZ+shXR c7RNXtEMNle344dtU9EKWKGZBOkpHjoDPsIGMdDzDJN5+X98MO0Xnn8/yfaEGj+Be/FB T3RkUYPXZbfJ23X8KJOHduapw/oqsGr9MX6r7kIjcTSJC8wvlQ4vlM5NXHLcQKyHcYyG Qc/j1d6RMAubP6gQVQSdijODPRI2Wd3pspKXFZXP/433kw7+/upC7mgy7kResPEICFtx aAHL9t68cToLb3nydpywx2h3ZWsu/C+Yj3C0uGd8d9U6hei3/S0JuSHhcg8NPVVimt7l 08GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=QAFQsduN0andwcj07zm0A0NY5Hpx3yINz+kHSIPmU+Y=; b=XZpCji18AxWiGsPkSpfWN7ngnnOoZ++acXurHNKKzwf9RDSBAu4voRXnQFnuognCiW x12bVOk3Ec/uaGnjCmHyROpUQjTUy32Ic5/vt93L3J3roxgfGQ/pA+Df8eXz171MGCM/ qQAhvV6uN7CtYWv7yKfluvkDCq7Yk5sGpGl72ilqMbQyffZgqTtkU0RLpqJCjNx7AZV4 km/GjTXzHm3Vle3YMZaWJfhTZBvzUj79IY1KFMytebez07BgCP58k7mUF/t4GIxP6m/3 KL/84FjxMsSEqJjMdpOxevkU499HeToghwEaYnShHK0aaZUli7kE8q3KLgPoe1bz35nh IUMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x20-v6si13814437pge.395.2018.06.18.23.00.19; Mon, 18 Jun 2018 23:00:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937256AbeFSF7e (ORCPT + 99 others); Tue, 19 Jun 2018 01:59:34 -0400 Received: from www381.your-server.de ([78.46.137.84]:46415 "EHLO www381.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755830AbeFSF7c (ORCPT ); Tue, 19 Jun 2018 01:59:32 -0400 Received: from [78.46.172.2] (helo=sslproxy05.your-server.de) by www381.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1fV9fr-0002sa-6D; Tue, 19 Jun 2018 07:59:27 +0200 Received: from [188.174.124.246] (helo=[192.168.178.37]) by sslproxy05.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1fV9fq-0009yq-VA; Tue, 19 Jun 2018 07:59:27 +0200 Subject: Re: [PATCH] staging:iio:adc:ad7816: Backward resources cleanups in probe To: Karim Eshapa Cc: Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org References: <20180618233851.7992-1-karim.eshapa@gmail.com> From: Lars-Peter Clausen Message-ID: <0e5bb02e-a19a-3b6a-f1a6-98bb89a6d9b8@metafoo.de> Date: Tue, 19 Jun 2018 07:59:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180618233851.7992-1-karim.eshapa@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.99.3/24676/Tue Jun 19 06:38:11 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/19/2018 01:38 AM, Karim Eshapa wrote: > Backward cleanups for all resources allocated in probing > in case of failure at any regestering or allocation step. Hi, Thanks for the patch. Resources that are allocated with devm_ are freed automatically in case of an error, so this patch should not be necessary. > > Signed-off-by: Karim Eshapa > --- > drivers/staging/iio/adc/ad7816.c | 22 +++++++++++++++++----- > 1 file changed, 17 insertions(+), 5 deletions(-) > > diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c > index bf76a8620bdb..5ff14c830451 100644 > --- a/drivers/staging/iio/adc/ad7816.c > +++ b/drivers/staging/iio/adc/ad7816.c > @@ -373,7 +373,7 @@ static int ad7816_probe(struct spi_device *spi_dev) > if (ret) { > dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n", > chip->rdwr_pin); > - return ret; > + goto device_free; > } > gpio_direction_input(chip->rdwr_pin); > ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin, > @@ -381,7 +381,7 @@ static int ad7816_probe(struct spi_device *spi_dev) > if (ret) { > dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n", > chip->convert_pin); > - return ret; > + goto free_rdwr_pin; > } > gpio_direction_input(chip->convert_pin); > ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin, > @@ -389,7 +389,7 @@ static int ad7816_probe(struct spi_device *spi_dev) > if (ret) { > dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n", > chip->busy_pin); > - return ret; > + goto free_convert_pin; > } > gpio_direction_input(chip->busy_pin); > > @@ -407,17 +407,29 @@ static int ad7816_probe(struct spi_device *spi_dev) > indio_dev->name, > indio_dev); > if (ret) > - return ret; > + goto free_busy_pin; > } > > ret = devm_iio_device_register(&spi_dev->dev, indio_dev); > if (ret) > - return ret; > + goto free_dev_irq; > > dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n", > indio_dev->name); > > return 0; > +free_dev_irq: > + devm_free_irq(&spi_dev->dev, spi_dev->irq, indio_dev); > +free_busy_pin: > + devm_gpio_free(&spi_dev->dev, chip->busy_pin); > +free_convert_pin: > + devm_gpio_free(&spi_dev->dev, chip->convert_pin); > +free_rdwr_pin: > + devm_gpio_free(&spi_dev->dev, chip->rdwr_pin); > +device_free: > + devm_iio_device_free(&spi_dev->dev, indio_dev); > + > + return ret; > } > > static const struct spi_device_id ad7816_id[] = { >