From patchwork Thu Jun 12 14:14:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 31830 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B862020AE6 for ; Thu, 12 Jun 2014 14:16:44 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id il7sf2772823vcb.8 for ; Thu, 12 Jun 2014 07:16:44 -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:date:message-id:cc:subject :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=QF+bxfTdTvhZj4I5+b+npFf6cWH/bx718kj++BTnpZM=; b=C73T1NkQD28aEdBqmTK6omxLVZxU3qqC4FpbrrIWMhjDOkzgVq3neyMY6CqZpnx/Ss Gi2/8o3+3gAeqiwYsohRE+8iwgTM7+lZ1k9lYnU35BtdFxRk+Mvyqwt+cqpDc7iVzNjl dgO2amD7iyKvGZNthxOeMibNgX/XQiu9o2dzGkF9qdzx0UQb7B+c5meMcKh+22dRX246 sQRdf7JEk2dbvgMJvPf2lXXlklhRbdH/HZp+0Xg2Z9J2AcUwAj0ABDx2Pozo+2p3QLTy TYDwX8Wc6mcn+os+jfLQtNq6GDArhNCe2igENgrm7Ek+75BLZk5TnjekuxqO9Na+WXPJ 43HQ== X-Gm-Message-State: ALoCoQlEj2SfPeHgZ4sLQOgJkBIWJ9pYph9ltFJPq8Tgp2DozRRpFvelV8aC4jzB7gcQfAKf3EbX X-Received: by 10.58.8.50 with SMTP id o18mr7116799vea.13.1402582604558; Thu, 12 Jun 2014 07:16:44 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.36 with SMTP id o33ls262137qgo.76.gmail; Thu, 12 Jun 2014 07:16:44 -0700 (PDT) X-Received: by 10.221.69.68 with SMTP id yb4mr464380vcb.49.1402582604384; Thu, 12 Jun 2014 07:16:44 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id yi11si364998vdb.1.2014.06.12.07.16.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Jun 2014 07:16:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id il7so842146vcb.26 for ; Thu, 12 Jun 2014 07:16:44 -0700 (PDT) X-Received: by 10.52.135.208 with SMTP id pu16mr8310708vdb.8.1402582604276; Thu, 12 Jun 2014 07:16:44 -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.221.54.6 with SMTP id vs6csp406986vcb; Thu, 12 Jun 2014 07:16:43 -0700 (PDT) X-Received: by 10.194.62.104 with SMTP id x8mr62296591wjr.15.1402582603318; Thu, 12 Jun 2014 07:16:43 -0700 (PDT) Received: from flocki.atrpms.net (m.at.physik.fu-berlin.de. [160.45.254.30]) by mx.google.com with ESMTPS id gt4si3399569wib.64.2014.06.12.07.16.41 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 12 Jun 2014 07:16:42 -0700 (PDT) Received-SPF: none (google.com: lm-sensors-bounces@lm-sensors.org does not designate permitted sender hosts) client-ip=160.45.254.30; Received: from localhost ([::1] helo=m.at.physik.fu-berlin.de) by flocki.atrpms.net with esmtp (Exim 4.80.1) id 1Wv5ng-0008FK-9O; Thu, 12 Jun 2014 16:16:22 +0200 Received: from fw-tnat.austin.arm.com ([217.140.110.23] helo=collaborate-mta1.arm.com) by mail1.atrpms.net with esmtp (Exim 4.80.1) id 1Wv5na-0008DH-CQ for lm-sensors@lm-sensors.org; Thu, 12 Jun 2014 16:16:16 +0200 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.92]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 7EB9913F6FA; Thu, 12 Jun 2014 09:14:41 -0500 (CDT) X-ACL-Warn: From: Pawel Moll To: Jean Delvare , Guenter Roeck Date: Thu, 12 Jun 2014 15:14:33 +0100 Message-Id: <1402582473-12447-1-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 X-HELO-Warning: Remote host 217.140.110.23 (fw-tnat.austin.arm.com) incorrectly presented itself as collaborate-mta1.arm.com X-Scanned: No viruses found. X-Spam-Status: No (score -2.2) X-Spam-Level: -- X-Spam-Report: No (score -2.2) -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.4 AWL AWL: From: address is in the auto white-list X-Scan-Signature: a82caf81542a054dec8db101233f2fdc Cc: Pawel Moll , lm-sensors@lm-sensors.org Subject: [lm-sensors] [PATCH v2 RESENT] hwmon: vexpress: Use devm helper for hwmon device registration X-BeenThere: lm-sensors@lm-sensors.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: lm-sensors-bounces@lm-sensors.org Errors-To: lm-sensors-bounces@lm-sensors.org X-Scanned: No viruses found. X-Spam-Status: No (score -1.9) X-Spam-Level: - X-Spam-Report: No (score -1.9) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 AWL AWL: From: address is in the auto white-list X-Scan-Signature: 68ea64d7031295bf775ea257a0a48e82 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) 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, unroll the attribute group macros for better code readability. Signed-off-by: Pawel Moll Reviewed-by: Guenter Roeck --- drivers/hwmon/vexpress.c | 82 +++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 54 deletions(-) Now, as the base vexpress changes have been merged, this patch can be finally queued for next... diff --git a/drivers/hwmon/vexpress.c b/drivers/hwmon/vexpress.c index 611f34c..c536190 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,7 +95,11 @@ 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 *vexpress_hwmon_attrs_volt[] = { + &dev_attr_in1_label.attr, + &sensor_dev_attr_in1_input.dev_attr.attr, + NULL +}; static struct attribute_group vexpress_hwmon_group_volt = { .is_visible = vexpress_hwmon_attr_is_visible, .attrs = vexpress_hwmon_attrs_volt, @@ -131,7 +116,11 @@ 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 *vexpress_hwmon_attrs_amp[] = { + &dev_attr_curr1_label.attr, + &sensor_dev_attr_curr1_input.dev_attr.attr, + NULL +}; static struct attribute_group vexpress_hwmon_group_amp = { .is_visible = vexpress_hwmon_attr_is_visible, .attrs = vexpress_hwmon_attrs_amp, @@ -147,7 +136,11 @@ 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 *vexpress_hwmon_attrs_temp[] = { + &dev_attr_temp1_label.attr, + &sensor_dev_attr_temp1_input.dev_attr.attr, + NULL +}; static struct attribute_group vexpress_hwmon_group_temp = { .is_visible = vexpress_hwmon_attr_is_visible, .attrs = vexpress_hwmon_attrs_temp, @@ -163,7 +156,11 @@ 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 *vexpress_hwmon_attrs_power[] = { + &dev_attr_power1_label.attr, + &sensor_dev_attr_power1_input.dev_attr.attr, + NULL +}; static struct attribute_group vexpress_hwmon_group_power = { .is_visible = vexpress_hwmon_attr_is_visible, .attrs = vexpress_hwmon_attrs_power, @@ -179,7 +176,11 @@ 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 *vexpress_hwmon_attrs_energy[] = { + &dev_attr_energy1_label.attr, + &sensor_dev_attr_energy1_input.dev_attr.attr, + NULL +}; static struct attribute_group vexpress_hwmon_group_energy = { .is_visible = vexpress_hwmon_attr_is_visible, .attrs = vexpress_hwmon_attrs_energy, @@ -218,7 +219,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 +232,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 (IS_ERR(data->reg)) return PTR_ERR(data->reg); - 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; - } - - 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,