Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2991537pxv; Sun, 18 Jul 2021 07:28:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhAg+vdSv4JoGPBjdkDX9P74ujBP957ywoCOR5v2KEtqXQw6wXr6PlOv2KrcxRkqu2bRtH X-Received: by 2002:a05:6402:1849:: with SMTP id v9mr28128386edy.108.1626618513691; Sun, 18 Jul 2021 07:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626618513; cv=none; d=google.com; s=arc-20160816; b=X9XEODk9XR5ourLiHtLEVNE6CQJOPX2LaA3I1PNm0x0N0Xjo08oE/eAw4qRY/FLotg UP1chBffNNwJSfameIIrFeyoUz1SX0HTq5Gz0+gKzFQM1QiYg3vf3GJF1N3rFVcHZ7Uy w1Vm8+nngHbxb1QDHETE7Ox1c0vvNu/tAdQUj+3t2gDDkFruC18BuQuGmND/Kh4x5Gbs P7OAef95+jWCfqX3uVw465LRIewaYD+dvkWJStcxOdrMmWS+MTdm9uL6vxl2B875Jn+U 0YRykr1JixatmJIkWQTG0mTtHPGGPGK5XuWNEYcg0Xp+rcNtQSMrOVCeS/QsLBvvsn+j ijTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=pVF5lZ2iihA+m/tLLE/FjsScvihhmweGDR/1MQLDdsg=; b=Ko4656xkowCnqYze08JPYuoXOh+ZX4trjkRDzOOEyzpkSGQTYZxs3oqMObQYGxzJN8 /cvIqPpFQS+5VmO35AozKiiLp/+D1jM6/x0Bsawkotc2d4cp93mKFG1E3fOAlYSov1yC FQhCJu6hnDoafPKDShhEYG5VNzB1f1gdZ+qS/NAuPGdZFsyIWC8SkeOCRbnpr4AxfJ6H 0Ps+4x+ucPH2z/51DbYw1/RV0OeSkvVnHwv6U5UCMdHtWysvaytAbr2RasiqnSdIURlA 5uRwIGOP8ZTSr63ebg49pGWQOCZIxiGhEfBdzPQ8k6brGKc5A0S1uaE2dfUgsGHqN+Aj w2Vg== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r14si15334380edp.449.2021.07.18.07.28.11; Sun, 18 Jul 2021 07:28:33 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233870AbhGROaL (ORCPT + 99 others); Sun, 18 Jul 2021 10:30:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:46140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232973AbhGROaL (ORCPT ); Sun, 18 Jul 2021 10:30:11 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (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 F115D611AB; Sun, 18 Jul 2021 14:27:11 +0000 (UTC) Date: Sun, 18 Jul 2021 15:29:36 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Maury Anderson Subject: Re: [PATCH] iio: potentiometer: max5481: convert probe to device-managed Message-ID: <20210718152936.3d4194e6@jic23-huawei> In-Reply-To: <20210624080641.9953-1-aardelean@deviqon.com> References: <20210624080641.9953-1-aardelean@deviqon.com> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 24 Jun 2021 11:06:41 +0300 Alexandru Ardelean wrote: > The change converts the probe function to use the > devm_iio_device_register() function. > > Before calling that, we need to register an action to store the wiper back > to non-volatile memory when the device is de-registered. > > We don't need to do this if the probe fails, because the only place where > the probe can fail now is devm_iio_device_register() and that shouldn't > create an IIO device (for userspace to poke at) if it fails. > > Signed-off-by: Alexandru Ardelean Hi Alex, This one took a little bit of thought because it's a bit unusual in that that wiper write back isn't technically unwinding anything so doesn't have an obvious match in probe. However, as it logically wants to happen just after we've removed the userspace interfaces, I agree with your logic that it makes sense to do it with a devm triggered call. So, on that basis applied. +CC Maury on basis might still be about on that address and want to express a view on whether this makes sense. Jonathan > --- > drivers/iio/potentiometer/max5481.c | 22 +++++++++------------- > 1 file changed, 9 insertions(+), 13 deletions(-) > > diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c > index 6e22b538091f..098d144a8fdd 100644 > --- a/drivers/iio/potentiometer/max5481.c > +++ b/drivers/iio/potentiometer/max5481.c > @@ -125,6 +125,11 @@ static const struct of_device_id max5481_match[] = { > }; > MODULE_DEVICE_TABLE(of, max5481_match); > > +static void max5481_wiper_save(void *data) > +{ > + max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0); > +} > + > static int max5481_probe(struct spi_device *spi) > { > struct iio_dev *indio_dev; > @@ -136,7 +141,6 @@ static int max5481_probe(struct spi_device *spi) > if (!indio_dev) > return -ENOMEM; > > - spi_set_drvdata(spi, indio_dev); > data = iio_priv(indio_dev); > > data->spi = spi; > @@ -158,18 +162,11 @@ static int max5481_probe(struct spi_device *spi) > if (ret < 0) > return ret; > > - return iio_device_register(indio_dev); > -} > - > -static int max5481_remove(struct spi_device *spi) > -{ > - struct iio_dev *indio_dev = spi_get_drvdata(spi); > - struct max5481_data *data = iio_priv(indio_dev); > - > - iio_device_unregister(indio_dev); > + ret = devm_add_action(&spi->dev, max5481_wiper_save, data); > + if (ret < 0) > + return ret; > > - /* save wiper reg to NV reg */ > - return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0); > + return devm_iio_device_register(&spi->dev, indio_dev); > } > > static const struct spi_device_id max5481_id_table[] = { > @@ -187,7 +184,6 @@ static struct spi_driver max5481_driver = { > .of_match_table = max5481_match, > }, > .probe = max5481_probe, > - .remove = max5481_remove, > .id_table = max5481_id_table, > }; >