From patchwork Thu Jun 30 06:45:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9206687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 947A4607D6 for ; Thu, 30 Jun 2016 06:45:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81B02284BC for ; Thu, 30 Jun 2016 06:45:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71E69284CC; Thu, 30 Jun 2016 06:45:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04442284BC for ; Thu, 30 Jun 2016 06:45:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751383AbcF3Gpb (ORCPT ); Thu, 30 Jun 2016 02:45:31 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:34124 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751203AbcF3Gpa (ORCPT ); Thu, 30 Jun 2016 02:45:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Message-Id:Date:Subject:Cc:To:From; bh=4DDCx0zLLy2x9WvvU+DBJmF1zgGOHtrk7Ca2ySBPXhw=; b=1YKetssRa2XBLw2tYbg4f587aj 74GAtf2bkjRG0wroFxFKi7MrbStPsAINdfQLgps5dMM3Zoi/dbzrY+4iVAeDth3+Z2tyikG494bML CIzpkmItLNH+K5jYXVX8FQeVh9o3gKqlMXTdgjuQmu47jQZ+ddwL6fd+xCuSXFV7HpT02G29vZMGG dFxXEa6Wr7DH8Z+WbOGeltzkH/4ygOfDUFHfjRqyytMqibV2iiw7CIewHpw0ROzSoKOyWlGkNRrTn 45O3qQsCGj3RfafRKqWq6KPCZRrK4VV88HKzRuWpe3qntuHi8nmswvSudhHVmnz/ltN0t2CKw2qe9 g+Cv0o/A==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:54116 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1bIVj5-004EuR-QT; Thu, 30 Jun 2016 06:45:28 +0000 From: Guenter Roeck To: Jean Delvare Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH v3 1/4] hwmon: (lm75) Handle cleanup with devm_add_action Date: Wed, 29 Jun 2016 23:45:25 -0700 Message-Id: <1467269128-7448-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.5.0 X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_add_action() to register the function to restore the original chip configuration. Use devm_hwmon_device_register_with_groups() to register the hwmon device, and drop the remove function as no longer needed. Signed-off-by: Guenter Roeck --- v2, v3: No change drivers/hwmon/lm75.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index 69166ab3151d..0df745501a1f 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -76,7 +76,6 @@ static const u8 LM75_REG_TEMP[3] = { /* Each client has this additional data */ struct lm75_data { struct i2c_client *client; - struct device *hwmon_dev; struct mutex update_lock; u8 orig_conf; u8 resolution; /* In bits, between 9 and 12 */ @@ -185,10 +184,19 @@ static const struct thermal_zone_of_device_ops lm75_of_thermal_ops = { /* device probe and removal */ +static void lm75_remove(void *data) +{ + struct lm75_data *lm75 = data; + struct i2c_client *client = lm75->client; + + i2c_smbus_write_byte_data(client, LM75_REG_CONF, lm75->orig_conf); +} + static int lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; + struct device *hwmon_dev; struct lm75_data *data; int status; u8 set_mask, clr_mask; @@ -298,29 +306,22 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) new |= set_mask; if (status != new) lm75_write_value(client, LM75_REG_CONF, new); - dev_dbg(dev, "Config %02x\n", new); - data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, - data, lm75_groups); - if (IS_ERR(data->hwmon_dev)) - return PTR_ERR(data->hwmon_dev); + devm_add_action(dev, lm75_remove, data); - devm_thermal_zone_of_sensor_register(data->hwmon_dev, 0, - data->hwmon_dev, - &lm75_of_thermal_ops); + dev_dbg(dev, "Config %02x\n", new); - dev_info(dev, "%s: sensor '%s'\n", - dev_name(data->hwmon_dev), client->name); + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, lm75_groups); + if (IS_ERR(hwmon_dev)) + return PTR_ERR(hwmon_dev); - return 0; -} + devm_thermal_zone_of_sensor_register(hwmon_dev, 0, + hwmon_dev, + &lm75_of_thermal_ops); -static int lm75_remove(struct i2c_client *client) -{ - struct lm75_data *data = i2c_get_clientdata(client); + dev_info(dev, "%s: sensor '%s'\n", dev_name(hwmon_dev), client->name); - hwmon_device_unregister(data->hwmon_dev); - lm75_write_value(client, LM75_REG_CONF, data->orig_conf); return 0; } @@ -489,7 +490,6 @@ static struct i2c_driver lm75_driver = { .pm = LM75_DEV_PM_OPS, }, .probe = lm75_probe, - .remove = lm75_remove, .id_table = lm75_ids, .detect = lm75_detect, .address_list = normal_i2c,