From patchwork Fri Jul 20 14:46:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Maxime_Roussin-B=C3=A9langer?= X-Patchwork-Id: 10537631 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 86F906029B for ; Fri, 20 Jul 2018 14:47:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7487B28AD0 for ; Fri, 20 Jul 2018 14:47:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6896E28B5F; Fri, 20 Jul 2018 14:47:14 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 0466228AD0 for ; Fri, 20 Jul 2018 14:47:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731546AbeGTPfu (ORCPT ); Fri, 20 Jul 2018 11:35:50 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:35035 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731771AbeGTPfu (ORCPT ); Fri, 20 Jul 2018 11:35:50 -0400 Received: by mail-qt0-f193.google.com with SMTP id a5-v6so10473913qtp.2 for ; Fri, 20 Jul 2018 07:47:12 -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=i2VFKNjlOAQ4EoyzeQqU1WF6P1n+5mesbomrjHk7hlo=; b=caChAMRNuzij+4aL2oTpmckMvtxjDmy2MKDh/E/fZ//viyHKgnQTcZ0p+RXupGEcaD OPxK5fzEz92yhWLwjNqyyXPufo/+mZQDI2Gmzk9XTXakqcShVpeHnGJm1+yuXgX8r0ls wv7hoQ4kFWtDzaZmFkL5DVUK0NMgZaqM57xZCl3GFdeTdNvdvFXldUJK31Fy/rJivVCz PTwSPTRMmtmZDrO1tVc1zp4/EEJHyACZNCxVUnasjeZp/dg7qJY7No2OiYLeqWOGcYsn yq/iPjqyuFE8ovgNrOSUDaoZXk+Rgut9fs8M7uDA3F2zp/RXO4zJZvbFBH55TRHcjiME qN7A== 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=i2VFKNjlOAQ4EoyzeQqU1WF6P1n+5mesbomrjHk7hlo=; b=TSmH4kGVmP3xOHiUTX9ZJHCg57fpcCnA4zzJqqbZBj/TcSoTR7JXR1GYzVZPbBtGLA E3igNzekhfvfy+CTgnuZrkgUg+P4w/genEkMeT+BXvaf2np44vT2HYOarGXgutE1GL8h b4vy6nODP3dR+du+wCJKHzszbuUMnfKg1YmQJIVnRIA8Iu0Uq8Rwb/yrAi6fy7XrhnCY ghs3tVWXTsVe+C0PEaAJPuCV2jF6NKeSi5+OQOe6kH2Znxwtm2xv2f+FZi9330IzyB3P rSrR38i1YKPNX2YK6KaH2IX1lqUjK+ZadUsX+fbIrriqGG0qrRXtmgEt4gIigWcq8tmN nRxA== X-Gm-Message-State: AOUpUlGIHzjAzzplh3YvYAxad1fO0cwY65dxEdjvyOTvuwDtbPxS3NIl tMeXApoZCYyQfynCtFN6YMI= X-Google-Smtp-Source: AAOMgpcNjj8dlbT4m2LEeTFzvJB17hAKEY1qbvuukC6FmK7YyRcdBLWWNGKLlWuNPPq0+rQSGutN3A== X-Received: by 2002:ac8:f24:: with SMTP id e33-v6mr2241775qtk.301.1532098032350; Fri, 20 Jul 2018 07:47:12 -0700 (PDT) Received: from mbedesk.Sonatest.net (ipagstaticip-d73c7528-4de5-0861-800b-03d8b15e3869.sdsl.bell.ca. [174.94.156.236]) by smtp.gmail.com with ESMTPSA id r13-v6sm1324294qti.70.2018.07.20.07.47.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jul 2018 07:47:11 -0700 (PDT) From: =?UTF-8?q?Maxime=20Roussin-B=C3=A9langer?= To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Jonathan Cameron , =?UTF-8?q?Maxime=20Roussin-B=C3=A9langer?= Subject: [PATCH] hwmon: (iio_hwmon) Use devm functions Date: Fri, 20 Jul 2018 10:46:57 -0400 Message-Id: <20180720144657.21577-1-maxime.roussinbelanger@gmail.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 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_iio_channel_get_all() to automatically release channels. Use devm_hwmon_device_register_with_groups() to automatically unregister the device. Signed-off-by: Maxime Roussin-BĂ©langer Acked-by: Jonathan Cameron --- drivers/hwmon/iio_hwmon.c | 43 ++++++++++----------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c index 69031a0f7ed2..5cbd87b00ce0 100644 --- a/drivers/hwmon/iio_hwmon.c +++ b/drivers/hwmon/iio_hwmon.c @@ -73,17 +73,16 @@ static int iio_hwmon_probe(struct platform_device *pdev) if (dev->of_node && dev->of_node->name) name = dev->of_node->name; - channels = iio_channel_get_all(dev); + channels = devm_iio_channel_get_all(dev); if (IS_ERR(channels)) { if (PTR_ERR(channels) == -ENODEV) return -EPROBE_DEFER; return PTR_ERR(channels); } st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); if (st == NULL) { - ret = -ENOMEM; - goto error_release_channels; + return -ENOMEM; } st->channels = channels; @@ -96,21 +95,19 @@ static int iio_hwmon_probe(struct platform_device *pdev) st->num_channels + 1, sizeof(*st->attrs), GFP_KERNEL); if (st->attrs == NULL) { - ret = -ENOMEM; - goto error_release_channels; + return -ENOMEM; } for (i = 0; i < st->num_channels; i++) { a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL); if (a == NULL) { - ret = -ENOMEM; - goto error_release_channels; + return -ENOMEM; } sysfs_attr_init(&a->dev_attr.attr); ret = iio_get_channel_type(&st->channels[i], &type); if (ret < 0) - goto error_release_channels; + return ret; switch (type) { case IIO_VOLTAGE: @@ -134,12 +131,10 @@ static int iio_hwmon_probe(struct platform_device *pdev) humidity_i++); break; default: - ret = -EINVAL; - goto error_release_channels; + return -EINVAL; } if (a->dev_attr.attr.name == NULL) { - ret = -ENOMEM; - goto error_release_channels; + return -ENOMEM; } a->dev_attr.show = iio_hwmon_read_val; a->dev_attr.attr.mode = S_IRUGO; @@ -152,31 +147,16 @@ static int iio_hwmon_probe(struct platform_device *pdev) sname = devm_kstrdup(dev, name, GFP_KERNEL); if (!sname) { - ret = -ENOMEM; - goto error_release_channels; + return -ENOMEM; } strreplace(sname, '-', '_'); - st->hwmon_dev = hwmon_device_register_with_groups(dev, sname, st, - st->groups); + st->hwmon_dev = devm_hwmon_device_register_with_groups(dev, sname, st, + st->groups); if (IS_ERR(st->hwmon_dev)) { - ret = PTR_ERR(st->hwmon_dev); - goto error_release_channels; + return PTR_ERR(st->hwmon_dev); } platform_set_drvdata(pdev, st); - return 0; - -error_release_channels: - iio_channel_release_all(channels); - return ret; -} - -static int iio_hwmon_remove(struct platform_device *pdev) -{ - struct iio_hwmon_state *st = platform_get_drvdata(pdev); - - hwmon_device_unregister(st->hwmon_dev); - iio_channel_release_all(st->channels); return 0; } @@ -193,7 +173,6 @@ static struct platform_driver __refdata iio_hwmon_driver = { .of_match_table = iio_hwmon_of_match, }, .probe = iio_hwmon_probe, - .remove = iio_hwmon_remove, }; module_platform_driver(iio_hwmon_driver);