From patchwork Wed Feb 28 15:51:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Hao X-Patchwork-Id: 10246951 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 7BB5660211 for ; Wed, 28 Feb 2018 07:41:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6322328905 for ; Wed, 28 Feb 2018 07:41:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57E4728924; Wed, 28 Feb 2018 07:41:29 +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=-5.0 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_HI 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 5792528905 for ; Wed, 28 Feb 2018 07:41:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751570AbeB1Hl1 (ORCPT ); Wed, 28 Feb 2018 02:41:27 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:62786 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbeB1Hl1 (ORCPT ); Wed, 28 Feb 2018 02:41:27 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 253FB4CE1B4A3AFE7BE5; Wed, 28 Feb 2018 15:41:23 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w1S7cNZS096475; Wed, 28 Feb 2018 15:38:23 +0800 (GMT-8) (envelope-from peng.hao2@zte.com.cn) Received: from localhost.localdomain.localdomain ([10.74.120.59]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018022815382953-430129 ; Wed, 28 Feb 2018 15:38:29 +0800 From: Peng Hao To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Peng Hao Subject: [PATCH] hwmon: g762: handle cleanup with devm_add_action Date: Wed, 28 Feb 2018 23:51:46 +0800 Message-Id: <1519833106-74874-1-git-send-email-peng.hao2@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-02-28 15:38:29, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-02-28 15:38:16, Serialize complete at 2018-02-28 15:38:16 X-MAIL: mse01.zte.com.cn w1S7cNZS096475 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 Simplify code and use devm_add_action() to handle cleanup. Signed-off-by: Peng Hao --- drivers/hwmon/g762.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c index 6d1208b..48e60d8 100644 --- a/drivers/hwmon/g762.c +++ b/drivers/hwmon/g762.c @@ -128,7 +128,6 @@ enum g762_regs { G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2)) struct g762_data { - struct device *hwmon_dev; struct i2c_client *client; struct clk *clk; @@ -1051,9 +1050,17 @@ static inline int g762_fan_init(struct device *dev) data->fan_cmd1); } +static void g762_remove(void *data) +{ + struct g762_data *g762 = data; + struct i2c_client *client = g762->client; + + g762_of_clock_disable(client); +} static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; + struct device *hwmon_dev; struct g762_data *data; int ret; @@ -1086,10 +1093,12 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) if (ret) goto clock_dis; - data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, - data, g762_groups); - if (IS_ERR(data->hwmon_dev)) { - ret = PTR_ERR(data->hwmon_dev); + devm_add_action(dev, g762_remove, data); + + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, g762_groups); + if (IS_ERR(hwmon_dev)) { + ret = PTR_ERR(hwmon_dev); goto clock_dis; } @@ -1101,23 +1110,12 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) return ret; } -static int g762_remove(struct i2c_client *client) -{ - struct g762_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - g762_of_clock_disable(client); - - return 0; -} - static struct i2c_driver g762_driver = { .driver = { .name = DRVNAME, .of_match_table = of_match_ptr(g762_dt_match), }, .probe = g762_probe, - .remove = g762_remove, .id_table = g762_id, };