From patchwork Mon Apr 28 17:57:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 29268 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 91F9A20553 for ; Mon, 28 Apr 2014 18:01:55 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id oy12sf28634878veb.3 for ; Mon, 28 Apr 2014 11:01:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=p3OrUa0MogGAqjpcRYmFw7Y4mutlS+KhF0djS6IOkFg=; b=H5I5bZGukB2bixeeNS+HNQs1IY073t3h0noxwrCHnbxaEmedPWM6WYSBxPux5+eH4v Q0BhQRtfsO+ubbMDpFSusMfuSxq+dTB6nTjzQpuAjHyVHr7htAdmQ3jAncok0HJzfts1 bZWl1JzsOQAbWgoMTXnqlbCIwBm8LQWeQELvn/wUYLF7t/zjPuSd627+X8D5W816KXEl nUdNzmtNEHICMENsLMaQrPKzPC1LsK3oWb9sj4qanXao936Qz1j27elJeSMHUhqOR2Az Q9/gzgVSxrD2q+wxnZAcczFOPZdtprbjnR5Q2ZSRI9mRNynJ0Un+voib4ojTecYj+VNS +vFQ== X-Gm-Message-State: ALoCoQnPfhYaMMcDGXPYg7nWFgi5gaORB/oLhlLxpsUdB2H6iuTktQkX4ZI9RjpUJFrImaj163nP X-Received: by 10.58.154.228 with SMTP id vr4mr14089823veb.0.1398708115369; Mon, 28 Apr 2014 11:01:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.115 with SMTP id i106ls2790315qgd.97.gmail; Mon, 28 Apr 2014 11:01:55 -0700 (PDT) X-Received: by 10.58.195.202 with SMTP id ig10mr1650503vec.33.1398708115186; Mon, 28 Apr 2014 11:01:55 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id j20si3824884vcx.127.2014.04.28.11.01.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Apr 2014 11:01:55 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id ib6so2172520vcb.19 for ; Mon, 28 Apr 2014 11:01:55 -0700 (PDT) X-Received: by 10.52.37.196 with SMTP id a4mr2440225vdk.33.1398708115054; Mon, 28 Apr 2014 11:01:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp136169vcb; Mon, 28 Apr 2014 11:01:49 -0700 (PDT) X-Received: by 10.140.92.99 with SMTP id a90mr33232345qge.34.1398708103363; Mon, 28 Apr 2014 11:01:43 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id j6si8203993qan.170.2014.04.28.11.01.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Apr 2014 11:01:43 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wepqc-0005PI-5l; Mon, 28 Apr 2014 18:00:10 +0000 Received: from fw-tnat.austin.arm.com ([217.140.110.23] helo=collaborate-mta1.arm.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WeppI-000364-AN for linux-arm-kernel@lists.infradead.org; Mon, 28 Apr 2014 17:58:49 +0000 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.45]) by collaborate-mta1.arm.com (Postfix) with ESMTP id AB62013FF2A; Mon, 28 Apr 2014 12:58:17 -0500 (CDT) From: Pawel Moll To: Grant Likely , Rob Herring , Samuel Ortiz , Lee Jones , Arnd Bergmann , Greg Kroah-Hartman , Russell King Subject: [PATCH 10/10] hwmon: vexpress: Use devm helper for hwmon device registration Date: Mon, 28 Apr 2014 18:57:57 +0100 Message-Id: <1398707877-22596-11-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1398707877-22596-1-git-send-email-pawel.moll@arm.com> References: <1398707877-22596-1-git-send-email-pawel.moll@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140428_105848_473834_46D0BA74 X-CRM114-Status: GOOD ( 13.78 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: Pawel Moll , Guenter Roeck , linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org, arm@kernel.org, linux-arm-kernel@lists.infradead.org, Jean Delvare X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Use devm_hwmon_device_register_with_groups instead of the old-style manual attributes and hwmon device registration. Also, unwind the attribute group macros for better code readability. Cc: Jean Delvare Cc: Guenter Roeck Cc: lm-sensors@lm-sensors.org Signed-off-by: Pawel Moll --- drivers/hwmon/vexpress.c | 91 ++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 61 deletions(-) diff --git a/drivers/hwmon/vexpress.c b/drivers/hwmon/vexpress.c index d853332..ed6bf0e 100644 --- a/drivers/hwmon/vexpress.c +++ b/drivers/hwmon/vexpress.c @@ -27,17 +27,8 @@ struct vexpress_hwmon_data { struct device *hwmon_dev; struct regmap *reg; - const char *name; }; -static ssize_t vexpress_hwmon_name_show(struct device *dev, - struct device_attribute *dev_attr, char *buffer) -{ - struct vexpress_hwmon_data *data = dev_get_drvdata(dev); - - return sprintf(buffer, "%s\n", data->name); -} - static ssize_t vexpress_hwmon_label_show(struct device *dev, struct device_attribute *dev_attr, char *buffer) { @@ -95,16 +86,6 @@ static umode_t vexpress_hwmon_attr_is_visible(struct kobject *kobj, return attr->mode; } -static DEVICE_ATTR(name, S_IRUGO, vexpress_hwmon_name_show, NULL); - -#define VEXPRESS_HWMON_ATTRS(_name, _label_attr, _input_attr) \ -struct attribute *vexpress_hwmon_attrs_##_name[] = { \ - &dev_attr_name.attr, \ - &dev_attr_##_label_attr.attr, \ - &sensor_dev_attr_##_input_attr.dev_attr.attr, \ - NULL \ -} - struct vexpress_hwmon_type { const char *name; const struct attribute_group **attr_groups; @@ -114,10 +95,13 @@ struct vexpress_hwmon_type { static DEVICE_ATTR(in1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, vexpress_hwmon_u32_show, NULL, 1000); -static VEXPRESS_HWMON_ATTRS(volt, in1_label, in1_input); static struct attribute_group vexpress_hwmon_group_volt = { .is_visible = vexpress_hwmon_attr_is_visible, - .attrs = vexpress_hwmon_attrs_volt, + .attrs = (struct attribute *[]) { + &dev_attr_in1_label.attr, + &sensor_dev_attr_in1_input.dev_attr.attr, + NULL + }, }; static struct vexpress_hwmon_type vexpress_hwmon_volt = { .name = "vexpress_volt", @@ -131,10 +115,13 @@ static struct vexpress_hwmon_type vexpress_hwmon_volt = { static DEVICE_ATTR(curr1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, vexpress_hwmon_u32_show, NULL, 1000); -static VEXPRESS_HWMON_ATTRS(amp, curr1_label, curr1_input); static struct attribute_group vexpress_hwmon_group_amp = { .is_visible = vexpress_hwmon_attr_is_visible, - .attrs = vexpress_hwmon_attrs_amp, + .attrs = (struct attribute *[]) { + &dev_attr_curr1_label.attr, + &sensor_dev_attr_curr1_input.dev_attr.attr, + NULL + }, }; static struct vexpress_hwmon_type vexpress_hwmon_amp = { .name = "vexpress_amp", @@ -147,10 +134,13 @@ static struct vexpress_hwmon_type vexpress_hwmon_amp = { static DEVICE_ATTR(temp1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, vexpress_hwmon_u32_show, NULL, 1000); -static VEXPRESS_HWMON_ATTRS(temp, temp1_label, temp1_input); static struct attribute_group vexpress_hwmon_group_temp = { .is_visible = vexpress_hwmon_attr_is_visible, - .attrs = vexpress_hwmon_attrs_temp, + .attrs = (struct attribute *[]) { + &dev_attr_temp1_label.attr, + &sensor_dev_attr_temp1_input.dev_attr.attr, + NULL + }, }; static struct vexpress_hwmon_type vexpress_hwmon_temp = { .name = "vexpress_temp", @@ -163,10 +153,13 @@ static struct vexpress_hwmon_type vexpress_hwmon_temp = { static DEVICE_ATTR(power1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, vexpress_hwmon_u32_show, NULL, 1); -static VEXPRESS_HWMON_ATTRS(power, power1_label, power1_input); static struct attribute_group vexpress_hwmon_group_power = { .is_visible = vexpress_hwmon_attr_is_visible, - .attrs = vexpress_hwmon_attrs_power, + .attrs = (struct attribute *[]) { + &dev_attr_power1_label.attr, + &sensor_dev_attr_power1_input.dev_attr.attr, + NULL + }, }; static struct vexpress_hwmon_type vexpress_hwmon_power = { .name = "vexpress_power", @@ -179,10 +172,13 @@ static struct vexpress_hwmon_type vexpress_hwmon_power = { static DEVICE_ATTR(energy1_label, S_IRUGO, vexpress_hwmon_label_show, NULL); static SENSOR_DEVICE_ATTR(energy1_input, S_IRUGO, vexpress_hwmon_u64_show, NULL, 1); -static VEXPRESS_HWMON_ATTRS(energy, energy1_label, energy1_input); static struct attribute_group vexpress_hwmon_group_energy = { .is_visible = vexpress_hwmon_attr_is_visible, - .attrs = vexpress_hwmon_attrs_energy, + .attrs = (struct attribute *[]) { + &dev_attr_energy1_label.attr, + &sensor_dev_attr_energy1_input.dev_attr.attr, + NULL + }, }; static struct vexpress_hwmon_type vexpress_hwmon_energy = { .name = "vexpress_energy", @@ -218,7 +214,6 @@ MODULE_DEVICE_TABLE(of, vexpress_hwmon_of_match); static int vexpress_hwmon_probe(struct platform_device *pdev) { - int err; const struct of_device_id *match; struct vexpress_hwmon_data *data; const struct vexpress_hwmon_type *type; @@ -232,45 +227,19 @@ static int vexpress_hwmon_probe(struct platform_device *pdev) if (!match) return -ENODEV; type = match->data; - data->name = type->name; data->reg = devm_regmap_init_vexpress_config(&pdev->dev); - if (!data->reg) - return -ENODEV; - - err = sysfs_create_groups(&pdev->dev.kobj, type->attr_groups); - if (err) - goto error; - - data->hwmon_dev = hwmon_device_register(&pdev->dev); - if (IS_ERR(data->hwmon_dev)) { - err = PTR_ERR(data->hwmon_dev); - goto error; - } + if (IS_ERR(data->reg)) + return PTR_ERR(data->reg); - return 0; - -error: - sysfs_remove_group(&pdev->dev.kobj, match->data); - return err; -} - -static int vexpress_hwmon_remove(struct platform_device *pdev) -{ - struct vexpress_hwmon_data *data = platform_get_drvdata(pdev); - const struct of_device_id *match; - - hwmon_device_unregister(data->hwmon_dev); - - match = of_match_device(vexpress_hwmon_of_match, &pdev->dev); - sysfs_remove_group(&pdev->dev.kobj, match->data); + data->hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, + type->name, data, type->attr_groups); - return 0; + return PTR_ERR_OR_ZERO(data->hwmon_dev); } static struct platform_driver vexpress_hwmon_driver = { .probe = vexpress_hwmon_probe, - .remove = vexpress_hwmon_remove, .driver = { .name = DRVNAME, .owner = THIS_MODULE,