Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3121pxv; Thu, 24 Jun 2021 01:08:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZ59icfqoYmQ1SaUkA01KcHpDAGNXzXZRZ9NLNT2euzotaKnnlQ6Fzj4otnVj3vTAs45R1 X-Received: by 2002:a17:906:14c8:: with SMTP id y8mr622571ejc.485.1624522100910; Thu, 24 Jun 2021 01:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624522100; cv=none; d=google.com; s=arc-20160816; b=K9KHroFo6tuDcQw77e9bD/Fzu1mxaVP2rfsAEYmZgFej+9uJdd4bhqq/9mn+c4dR1f RRtUODks/3rLV+IvLaU1qFU/mlScIJs/iqCnuNegbmZecV3Tz7r7anszKGf6CtzKKPIW /cYcravg8BH5AQ8vmcAptisPhJziUU9DBp9qAcCO8f66sQ7qap+ICejr3JJ4ogWYEzV8 IAphL/igAZlPbiaCf8ovgXUvQQqHb6VFyotrJYey4vfDLLbJl52kX82nG+FDnPV0WX5Y FLpEPPIamX86de8JYcQE630iFpaHzFrqbhkPsgZXcQLuF8RzkvMh461n1WnOwnP6aFHf Q29A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=C4nA73tTn4BEbsExo9rREISfJYQH8bIha0KgZwwYk0U=; b=SsBZ9ok0FYgOXR40FgOoAjF5gQGoipw8YiGOQBE+b2kNVmHBecJrOLuh0wPghYEz5O Hp/Jf/JKf2pS4Hq+VaK9mmo4xPSb2Nqg9f7vSXv1lgiMBgVzvdO3IJ6YOZDiLfxFDdXd JWHNcznYYjTO+JZ47jFBMCKvUebJy7W7c3XV0BcSlUdTURSYCY//Epxwm3IcjLCr+VKM EL2xRJt4Hl4B0Vn6JrW9Vv5806rqadR3/ek4wdtOKmCYYoUsocDqe8IG7k7vF8DvW8XD 9qU+Fa/RQef2Q/pBugg3DP9RobgGCKl9moyJjalxKu4HKvxp4t/TYQr8kQYaywu/OlJl fUnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=gqFYvfIi; 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=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s26si2151026ejm.748.2021.06.24.01.07.58; Thu, 24 Jun 2021 01:08:20 -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; dkim=pass header.i=@deviqon.com header.s=google header.b=gqFYvfIi; 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=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231834AbhFXIJS (ORCPT + 99 others); Thu, 24 Jun 2021 04:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231699AbhFXIJR (ORCPT ); Thu, 24 Jun 2021 04:09:17 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74D9AC061574 for ; Thu, 24 Jun 2021 01:06:58 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id s6so7194653edu.10 for ; Thu, 24 Jun 2021 01:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=C4nA73tTn4BEbsExo9rREISfJYQH8bIha0KgZwwYk0U=; b=gqFYvfIiExTkr0Wh6JaJzaLvhcoFitp2BuZafaKV3a5/j/cHyXbJfII9T+NRhZpCZB QSVcdnVjQ9QZ0s0irS6RbkDNmPDV5KunLc30362xlLluuLr6ZmZhfdqFjcgd7k1I8gsz R7LvQzHX4C3rbHGRKpGXtvjTiF0+LGmVpDocRuEDSrlGML98Yei0D3bZB3/da9Tn7V0/ xTK2SaY1kkpfDc+VZwHSmbsU8LRfRGoHix1t8y2ncU6GVH/SeznTO54NvZKwH2hx2PK6 7JB/Zd6lc84XiMGDO5B6vIjZEMuC3o6wMpwWRANN8mEN0vZPDLAr/lKkCAPzOtyj9a6c mGwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=C4nA73tTn4BEbsExo9rREISfJYQH8bIha0KgZwwYk0U=; b=WuY9IxKzIs+s49ElbqyBwNPInwibgWolUFHwYoJK/zufE11FS6RDnNkoASewJtShq8 MLsXaySF0q7lzbsi0pOjHtDta05cDFQO2OvtAaIA1kf26R4LtGe9RKSWgqC6O/yk2zI2 GL4lJdUIy6dwlpECVExMxAJB7FIOp8FXvYClpoI6Yfk49qx4ozKZT2D13sur9byx+PjD KoKS+hpJhP30raMctSKh9nU1HruF02KwN+FL+BI2oXBoBRZK+uVMraNbiOvywrXs8ic5 qr0LdD4glylLXu3lxqCi+qE4jvmuu19P9xSDy/6VH00j9ezTfWzErupJdhw5XDVdaWQj rygw== X-Gm-Message-State: AOAM531PZLzvpFG1iYdiH4BOQ+HM/cZVNQf3xGMrjjKnhel62DuzFNvZ 34gVLD/mgG8n0bJh2+uy5eoR5Q== X-Received: by 2002:aa7:cb90:: with SMTP id r16mr5457088edt.121.1624522017126; Thu, 24 Jun 2021 01:06:57 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id n15sm1392785eds.28.2021.06.24.01.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Jun 2021 01:06:56 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Alexandru Ardelean Subject: [PATCH] iio: potentiometer: max5481: convert probe to device-managed Date: Thu, 24 Jun 2021 11:06:41 +0300 Message-Id: <20210624080641.9953-1-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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, }; -- 2.31.1