Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7015898ybi; Thu, 1 Aug 2019 01:57:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzofl0EM9mW9/ra6l6VOdA4VUUlvR0z6KcCtxJPmMNXr6NYoMqBHeS3qY1zmCsMpvVmfNY X-Received: by 2002:a65:52ca:: with SMTP id z10mr68381632pgp.424.1564649824944; Thu, 01 Aug 2019 01:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564649824; cv=none; d=google.com; s=arc-20160816; b=xZVbTH3tz9IjZCM1w/gJ6YiagcfvvqqGue9I+fvzOJ17aSJEeMpibYgSfMWfjHQn/0 yGVx5nAQA5G4ZnySQavzNXQi4lIgiatjyCIWMJ7oJLylCPO/W/VpLWIDDb7KEuSNYT0T uy3imdMGNU3zALKEbXTd//y27kAFHx1ubh5oohOr33W+ACD9vVdl4emRt+mRbHIN8mmu 5Iv7MPbaXXq32Kov3qW5D4OLEVPBjFo5X1eqmI5PkgUG9RQQFwA87S36ViCLi9lXuQrq 9fKvsb2Wt8g/wCCIbRfUlXgqrF3cBW0Ai25mqHL77Hs/iuBqW9s4p+XGH32443oPNG5e dASg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=FEKRFdCKMpkSeVMIdG4ipy7CLi0KrDkFAlXZaWu5PvE=; b=w14A4hfQKUYwrwSuoU5ofWVomGsq9kTn30DoKdvedkOKf8re/d9qKjv3JobrtBB+T6 +N6kN7Q9+MSLGrEuX9PawHiUiZw05bfeBjrCp3ZKOFLHI5mG1yXFvkUlkdZe3h5YLa6i L5VTPy7xdIicYsnN+Uht1Wf80YayWoQ+7ZkUumUTyXMSii/2A6sksOTvXwtJpw7cP/Dg xkrSIXhZ8nii/nDmNDjRWTND2CE+B4eennIYQmzAfHlcULC5tsifuxMB7s/hz/l7cKEW PGEUcAo95RgWXYC86FpSe+CEatHtc0urQpsmsUNkemQtH6Y25+uzIHVKZF/yc0Kr35bq 6fcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=QYIPysX3; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si30976642plr.211.2019.08.01.01.56.48; Thu, 01 Aug 2019 01:57:04 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=QYIPysX3; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730926AbfHAHgL (ORCPT + 99 others); Thu, 1 Aug 2019 03:36:11 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42830 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbfHAHgL (ORCPT ); Thu, 1 Aug 2019 03:36:11 -0400 Received: by mail-pf1-f194.google.com with SMTP id q10so33519120pff.9; Thu, 01 Aug 2019 00:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FEKRFdCKMpkSeVMIdG4ipy7CLi0KrDkFAlXZaWu5PvE=; b=QYIPysX3gk7gePWu04a+uSdFFoECYk9d4x7/ixCMLdWbWsxKefmv4UOXOAx2qZoKdz XZVDLd+G4Nr3SbkCiwypxC93qWVuZxG/jH1ejT1g/Hi5U3UG/A+PI7ZN2eR7TTDqwjPL 5EmiHAT6IqEqIi3IDrkvYuCDyht8SnnNAoSZn8wS5QgZ2VyPMBjHESGYbTwaOZAvtxnG mArp7Oal41UErDsI+W9jp4ETWvRFK73LJKqgnFnN0PR92/o162HnPrn3SD5G63/P1HNa tBBAVnJ8Lk2B29yIcVApDPfIWO2CKzZfEcXh/lk+KeHUsLWWKlEH+vSxY0lQRsYcK0zz VTkQ== 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=FEKRFdCKMpkSeVMIdG4ipy7CLi0KrDkFAlXZaWu5PvE=; b=DNDcMmJwtmInoYFD3NReVhHPxrAeqbM5sxLPGG6HlxugD/JLFcSQ7rnzLryLw5jKuz 5+pRGIZwqBaalDUo5s9oJMFxoxyv4h9bqCkzqAJvAtpRGYGzGFgMtDyI23uA0lRpIY5Q yqL8mUzxfnGg08KIlDIxi/mfmE6u/7BAJh9YiPAnTv5QkK6cB+b6TWgTLIQCtxHE/SRV 4SttNhhxp5L56F4BEgh6LolYLOIrxrLiTxGMyrLSNj0Qmwh4QbR6A+IwHeedB91aAuH/ QX0/d/Jm30la69sGUVvRlVZRwpL0uTZ8uGknrYitbob+Sah3L2FYdHtbr06V+HODunbM HuzA== X-Gm-Message-State: APjAAAW+CLdl4Tbc2w98c4KZYc63VDbfi4GqTwUp6LEqgKRtNDdfJ5x2 mXO4tuD9jm58280MWvIueis= X-Received: by 2002:a63:dd0b:: with SMTP id t11mr77496230pgg.410.1564644970565; Thu, 01 Aug 2019 00:36:10 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id e13sm88345565pff.45.2019.08.01.00.36.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 00:36:10 -0700 (PDT) From: Chuhong Yuan Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Brian Masney , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v4 2/4] iio: tsl2772: Use devm_add_action_or_reset for tsl2772_chip_off Date: Thu, 1 Aug 2019 15:36:05 +0800 Message-Id: <20190801073605.9635-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use devm_add_action_or_reset to call tsl2772_chip_off when the device is removed. This also fixes the issue that the chip is turned off before the device is unregistered. Fixes: 4e24c1719f34 ("staging: iio: tsl2x7x: rename driver to tsl2772") Signed-off-by: Chuhong Yuan --- Changes in v4: - Split v3 into three patches. - Revise description to make it more precise. drivers/iio/light/tsl2772.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c index 29cfd8ae2700..e866ae40f157 100644 --- a/drivers/iio/light/tsl2772.c +++ b/drivers/iio/light/tsl2772.c @@ -860,6 +860,13 @@ static int tsl2772_chip_off(struct iio_dev *indio_dev) return tsl2772_write_control_reg(chip, 0x00); } +static void tsl2772_chip_off_action(void *data) +{ + struct iio_dev *indio_dev = data; + + tsl2772_chip_off(indio_dev); +} + /** * tsl2772_invoke_change - power cycle the device to implement the user * parameters @@ -1877,9 +1884,14 @@ static int tsl2772_probe(struct i2c_client *clientp, if (ret < 0) return ret; + ret = devm_add_action_or_reset(&clientp->dev, + tsl2772_chip_off_action, + indio_dev); + if (ret < 0) + return ret; + ret = iio_device_register(indio_dev); if (ret) { - tsl2772_chip_off(indio_dev); dev_err(&clientp->dev, "%s: iio registration failed\n", __func__); return ret; @@ -1926,8 +1938,6 @@ static int tsl2772_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); - tsl2772_chip_off(indio_dev); - iio_device_unregister(indio_dev); return 0; -- 2.20.1