Received: by 10.192.165.156 with SMTP id m28csp2764381imm; Sun, 15 Apr 2018 08:32:32 -0700 (PDT) X-Google-Smtp-Source: AIpwx49ZaVzMJ4slGUaPsLt9vK5IswtMwjnDCoT7RTrGFsausm6bvG7g1vUpRFgyKFszHzZ5mbK8 X-Received: by 2002:a17:902:2983:: with SMTP id h3-v6mr12341673plb.80.1523806352382; Sun, 15 Apr 2018 08:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523806352; cv=none; d=google.com; s=arc-20160816; b=Xi56oF+3L/4fl7luzCQuv3YSFqyU2booBi4EoXf3cUIMgSKOTgst7ofnil1hlkT41r RrwA9hjyQUqfBf2lls5N9ukk9XY2ASLHy6Pq8YddiVY7ZLkpyx9dwfV9xmfQ4+nWxuTJ 8ZtrYuPkFVZBSHFznlbGPjGpGP6wr07tl87asj1kXAQLoaTvcbaZzBl/OfYA2eBSxgDt aM4iVPrCZuyiIKIuxv4licXKU0PUYWlDDPWuPIBvG6/J8kRWavhG+CeF1Wm99O5/57az KdsGnHu0S1gCAgojkCAum4b66kIvGuMPEPnDdOu1c/rm+Z6M8ilKNMB75ISPGNhgMoJE 0KTg== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dmarc-filter:arc-authentication-results; bh=g3olT8wMzdcbEjO67NcjMg42qeqkPuEx7j8MAE0NMsA=; b=NFQAaqvYs/bMs2CovWirZTxH2DcSKQ1JQqpmjSQNKKLVCJ1uss7sli+BO7MvxWVJSF AUfkKG/0wMoqSMmhe/5Of7OKJDsSs1Ca6d/HRj2qv8IyexPCYx2CNkBe/rFEDegsw8jb nIkZdCPRYvLJJpztRQIba9g2eoCDS5Wbm/0H0h8a5LWaHkJApeMY5oa+J432ANreJP0S eizcmkTpA0V+MEIT2IXfA583Gxr21DMVNVoRjH5ZKz8OuCc6SUmMCE5qzkKL3c7LXtQD xklRgQ3wMSSPJqOmG6RwBAbLJ8vfjF4n+JZTzw8dUnc08LriDHeGAvyRjLN/mvXrtZ2P vlNA== 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 p9si7777203pgu.80.2018.04.15.08.32.17; Sun, 15 Apr 2018 08:32:32 -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 S1752567AbeDOPbI convert rfc822-to-8bit (ORCPT + 99 others); Sun, 15 Apr 2018 11:31:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:39654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752371AbeDOPbH (ORCPT ); Sun, 15 Apr 2018 11:31:07 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0C98E2176F; Sun, 15 Apr 2018 15:31:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C98E2176F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jic23@kernel.org Date: Sun, 15 Apr 2018 16:31:01 +0100 From: Jonathan Cameron To: =?UTF-8?B?SGVybsOhbg==?= Gonzalez Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, Michael.Hennerich@analog.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 09/14] staging: iio: ad7746: Add remove() Message-ID: <20180415163101.6ab15cbc@archlinux> In-Reply-To: <1523637411-8531-10-git-send-email-hernan@vanguardiasur.com.ar> References: <1523637411-8531-1-git-send-email-hernan@vanguardiasur.com.ar> <1523637411-8531-10-git-send-email-hernan@vanguardiasur.com.ar> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 13 Apr 2018 13:36:46 -0300 Hernán Gonzalez wrote: > This allows the driver to be probed and removed as a module powering it > down on remove(). > > Signed-off-by: Hernán Gonzalez > --- > drivers/staging/iio/cdc/ad7746.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c > index c29a221..05506bf9 100644 > --- a/drivers/staging/iio/cdc/ad7746.c > +++ b/drivers/staging/iio/cdc/ad7746.c > @@ -775,6 +775,31 @@ static int ad7746_probe(struct i2c_client *client, > return 0; > } > > +static int ad7746_remove(struct i2c_client *client) > +{ > + struct iio_dev *indio_dev = i2c_get_clientdata(client); > + struct ad7746_chip_info *chip = iio_priv(indio_dev); > + unsigned char regval; > + int ret; > + > + mutex_lock(&chip->lock); > + > + regval = chip->config | AD7746_CONF_MODE_PWRDN; > + ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, regval); As this is a one off operation, perhaps it would be better to factor it out to a utility function then use devm_add_action_or_reset in the probe? Also, I am nervous about this change as there doesn't seem to be path in probe by which this is deliberately reversed? It seems to be 'accidentally' handled by the read_raw write to the CFG register. The data sheet doesn't really mention much about this register at all. It may have special requirements to exit from power down - I have no idea, but if it is costless, why do we bother with idle mode? Perhaps Michael can confirm if this is safe to do or not. > + > + mutex_unlock(&chip->lock); > + > + if (ret < 0) { > + dev_warn(&client->dev, "Could NOT Power Down!\n"); > + goto out; > + } > + > + iio_device_unregister(indio_dev); You can't safely do this against the devm_iio_device_register. > + > +out: > + return ret; > +} > + > static const struct i2c_device_id ad7746_id[] = { > { "ad7745", 7745 }, > { "ad7746", 7746 }, > @@ -799,6 +824,7 @@ static struct i2c_driver ad7746_driver = { > .of_match_table = of_match_ptr(ad7746_of_match), > }, > .probe = ad7746_probe, > + .remove = ad7746_remove, > .id_table = ad7746_id, > }; > module_i2c_driver(ad7746_driver);