From: khali@linux-fr.org (Jean Delvare)
To: lm-sensors@vger.kernel.org
Subject: [lm-sensors] [RFC PATCH 2.6.18-rc4-mm1] hwmon: unchecked return
Date: Mon, 14 Aug 2006 13:02:21 +0000 [thread overview]
Message-ID: <20060814150221.61d7138a.khali@linux-fr.org> (raw)
In-Reply-To: <20060814020407.GA3327@jupiter.solarsys.private>
Hi Mark,
> Added w83627hf, which should demonstrate how to do all the remaining
> hwmon drivers. There is more (ab)use of sysfs_remove_group() here to
> make life easier.
Yeah, I like it. Your approach deals nicely with chip-dependent files
and it can be applied to all drivers as far as I can see.
> This patch was lightly tested against w83627thf. Testing on the other
> variants supported by that driver would be nice.
I don't have any supported chip here (yet), sorry.
> --- linux-2.6.18-rc4-mm1.orig/drivers/hwmon/w83627hf.c
> +++ linux-2.6.18-rc4-mm1/drivers/hwmon/w83627hf.c
> @@ -1107,62 +1138,93 @@ static int w83627hf_detect(struct i2c_ad
> data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2));
> data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3));
>
> - /* Register sysfs hooks */
> - data->class_dev = hwmon_device_register(&new_client->dev);
> - if (IS_ERR(data->class_dev)) {
> - err = PTR_ERR(data->class_dev);
> + /* Register common device attributes */
> + if ((err = sysfs_create_group(&new_client->dev.kobj, &w83627hf_group)))
> goto ERROR3;
> +
> + /* Register chip-specific device attributes */
> + if (kind != w83697hf) {
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in1_input)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in1_min)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in1_max)))
> + goto ERROR4;
> }
What about:
if (kind != w83697hf) {
if ((err = device_create_file(&new_client->dev,
&dev_attr_in1_input))
|| (err = device_create_file(&new_client->dev,
&dev_attr_in1_min))
|| (err = device_create_file(&new_client->dev,
&dev_attr_in1_max)))
goto ERROR4;
}
More concise and it works just as fine, doesn't it? Same applies below.
Maybe you can also group the two (kind != w83697hf) blocks?
>
> - device_create_file_in(new_client, 0);
> - if (kind != w83697hf)
> - device_create_file_in(new_client, 1);
> - device_create_file_in(new_client, 2);
> - device_create_file_in(new_client, 3);
> - device_create_file_in(new_client, 4);
> if (kind = w83627hf || kind = w83697hf) {
> - device_create_file_in(new_client, 5);
> - device_create_file_in(new_client, 6);
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in5_input)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in5_min)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in5_max)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in6_input)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in6_min)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_in6_max)))
> + goto ERROR4;
> + }
> +
> + if (kind != w83697hf) {
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_fan3_input)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_fan3_min)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_fan3_div)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_temp3_input)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_temp3_max)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_temp3_max_hyst)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_temp3_type)))
> + goto ERROR4;
> }
> - device_create_file_in(new_client, 7);
> - device_create_file_in(new_client, 8);
> -
> - device_create_file_fan(new_client, 1);
> - device_create_file_fan(new_client, 2);
> - if (kind != w83697hf)
> - device_create_file_fan(new_client, 3);
> -
> - device_create_file_temp(new_client, 1);
> - device_create_file_temp(new_client, 2);
> - if (kind != w83697hf)
> - device_create_file_temp(new_client, 3);
>
> if (kind != w83697hf && data->vid != 0xff) {
> - device_create_file_vid(new_client);
> - device_create_file_vrm(new_client);
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_cpu0_vid)))
> + goto ERROR4;
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_vrm)))
> + goto ERROR4;
> }
>
> - device_create_file_fan_div(new_client, 1);
> - device_create_file_fan_div(new_client, 2);
> - if (kind != w83697hf)
> - device_create_file_fan_div(new_client, 3);
> -
> - device_create_file_alarms(new_client);
> -
> - device_create_file_beep(new_client);
> -
> - device_create_file_pwm(new_client, 1);
> - device_create_file_pwm(new_client, 2);
> if (kind = w83627thf || kind = w83637hf || kind = w83687thf)
> - device_create_file_pwm(new_client, 3);
> + if ((err = device_create_file(&new_client->dev,
> + &dev_attr_pwm3)))
> + goto ERROR4;
>
> - device_create_file_sensor(new_client, 1);
> - device_create_file_sensor(new_client, 2);
> - if (kind != w83697hf)
> - device_create_file_sensor(new_client, 3);
> + data->class_dev = hwmon_device_register(&new_client->dev);
> + if (IS_ERR(data->class_dev)) {
> + err = PTR_ERR(data->class_dev);
> + goto ERROR4;
> + }
>
> return 0;
>
> + ERROR4:
> + sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group);
> + sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group_opt);
> ERROR3:
> i2c_detach_client(new_client);
> ERROR2:
Thanks,
--
Jean Delvare
next prev parent reply other threads:[~2006-08-14 13:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-14 2:04 [lm-sensors] [RFC PATCH 2.6.18-rc4-mm1] hwmon: unchecked return Mark M. Hoffman
2006-08-14 13:02 ` Jean Delvare [this message]
2006-08-15 0:09 ` David Hubbard
2006-08-15 3:14 ` Mark M. Hoffman
2006-08-15 3:17 ` Mark M. Hoffman
2006-08-15 7:37 ` Jean Delvare
2006-08-15 8:01 ` Jean Delvare
2006-08-16 22:00 ` David Hubbard
2006-08-18 9:18 ` Jean Delvare
2006-08-20 2:15 ` David Hubbard
2006-08-20 12:23 ` Jean Delvare
2006-08-20 21:23 ` David Hubbard
2006-08-21 8:15 ` Jean Delvare
2006-08-22 5:21 ` David Hubbard
2006-08-23 6:50 ` Jean Delvare
2006-08-28 2:07 ` David Hubbard
2006-08-30 7:10 ` Jean Delvare
2006-09-01 10:21 ` Jean Delvare
2006-09-01 18:20 ` David Hubbard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060814150221.61d7138a.khali@linux-fr.org \
--to=khali@linux-fr.org \
--cc=lm-sensors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.