From: Andrew Morton <akpm@linux-foundation.org>
To: tomaz.mertelj@guest.arnes.si
Cc: lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments
Date: Wed, 09 Sep 2009 00:06:49 +0000 [thread overview]
Message-ID: <20090908170649.855dd1ff.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090905_120834_010267.tomaz.mertelj@guest.arnes.si>
On Sat, 5 Sep 2009 14:08:34 +0200
tomaz.mertelj@guest.arnes.si wrote:
> + int temp1_input;
> + int temp1_min;
> + int temp1_max;
> + int temp1_crit;
> +
> + int temp2_input;
> + int temp2_min;
> + int temp2_max;
> + int temp2_crit;
> +
> + u16 fan1_input;
> + u16 fan1_min;
> + u16 fan1_max;
> + u8 fan1_div;
> +
> + u8 pwm1;
> + u8 temp1_auto_point_temp[3];
> + u8 temp2_auto_point_temp[3];
> + u8 pwm1_auto_point_pwm[3];
> + u8 pwm1_enable;
> + u8 pwm1_auto_channels_temp;
> +
> + u8 stat1;
> + u8 stat2;
> +};
> +
> +
> +#define get_temp_para(name) \
> +static ssize_t get_##name(\
> + struct device *dev,\
> + struct device_attribute *devattr,\
> + char *buf)\
> +{\
> + struct amc6821_data *data = amc6821_update_device(dev);\
> + return sprintf(buf, "%d\n", data->name * 1000);\
> +}
> +
> +get_temp_para(temp1_input);
> +get_temp_para(temp1_min);
> +get_temp_para(temp1_max);
> +get_temp_para(temp2_input);
> +get_temp_para(temp2_min);
> +get_temp_para(temp2_max);
> +get_temp_para(temp1_crit);
> +get_temp_para(temp2_crit);
> +
> +#define set_temp_para(name, reg)\
> +static ssize_t set_##name(\
> + struct device *dev,\
> + struct device_attribute *attr,\
> + const char *buf,\
> + size_t count)\
> +{ \
> + struct i2c_client *client = to_i2c_client(dev); \
> + struct amc6821_data *data = i2c_get_clientdata(client); \
> + int val = simple_strtol(buf, NULL, 10); \
> + \
> + mutex_lock(&data->update_lock); \
> + data->name = SENSORS_LIMIT(val / 1000, -128, 127); \
> + if (i2c_smbus_write_byte_data(client, reg, data->name)) {\
> + dev_err(&client->dev, "Register write error, aborting.\n");\
> + count = -EIO;\
> + } \
> + mutex_unlock(&data->update_lock); \
> + return count; \
> +}
I'm wondering if these functions need to be so huge. Couldn't you do
#define set_temp_para(name, reg)\
static ssize_t set_##name(\
struct device *dev,\
struct device_attribute *attr,\
const char *buf,\
size_t count)\
{\
return set_helper(dev, attr, buf, count, &dev->name);\
}
And then do all the real work in a common function? Rather than
expanding tens of copies of the same thing?
Also, the checkpatch warning
WARNING: consider using strict_strtol in preference to simple_strtol
#381: FILE: drivers/hwmon/amc6821.c:228:
+ int val = simple_strtol(buf, NULL, 10); \
is valid. The problem with simple_strtol() is that it will treat input
of the form "43foo" as "43". Even though the input was invalid. A
minor thing, but easily fixed too.
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Morton <akpm@linux-foundation.org>
To: tomaz.mertelj@guest.arnes.si
Cc: lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon: Driver for Texas Instruments amc6821 chip
Date: Tue, 8 Sep 2009 17:06:49 -0700 [thread overview]
Message-ID: <20090908170649.855dd1ff.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090905_120834_010267.tomaz.mertelj@guest.arnes.si>
On Sat, 5 Sep 2009 14:08:34 +0200
tomaz.mertelj@guest.arnes.si wrote:
> + int temp1_input;
> + int temp1_min;
> + int temp1_max;
> + int temp1_crit;
> +
> + int temp2_input;
> + int temp2_min;
> + int temp2_max;
> + int temp2_crit;
> +
> + u16 fan1_input;
> + u16 fan1_min;
> + u16 fan1_max;
> + u8 fan1_div;
> +
> + u8 pwm1;
> + u8 temp1_auto_point_temp[3];
> + u8 temp2_auto_point_temp[3];
> + u8 pwm1_auto_point_pwm[3];
> + u8 pwm1_enable;
> + u8 pwm1_auto_channels_temp;
> +
> + u8 stat1;
> + u8 stat2;
> +};
> +
> +
> +#define get_temp_para(name) \
> +static ssize_t get_##name(\
> + struct device *dev,\
> + struct device_attribute *devattr,\
> + char *buf)\
> +{\
> + struct amc6821_data *data = amc6821_update_device(dev);\
> + return sprintf(buf, "%d\n", data->name * 1000);\
> +}
> +
> +get_temp_para(temp1_input);
> +get_temp_para(temp1_min);
> +get_temp_para(temp1_max);
> +get_temp_para(temp2_input);
> +get_temp_para(temp2_min);
> +get_temp_para(temp2_max);
> +get_temp_para(temp1_crit);
> +get_temp_para(temp2_crit);
> +
> +#define set_temp_para(name, reg)\
> +static ssize_t set_##name(\
> + struct device *dev,\
> + struct device_attribute *attr,\
> + const char *buf,\
> + size_t count)\
> +{ \
> + struct i2c_client *client = to_i2c_client(dev); \
> + struct amc6821_data *data = i2c_get_clientdata(client); \
> + int val = simple_strtol(buf, NULL, 10); \
> + \
> + mutex_lock(&data->update_lock); \
> + data->name = SENSORS_LIMIT(val / 1000, -128, 127); \
> + if (i2c_smbus_write_byte_data(client, reg, data->name)) {\
> + dev_err(&client->dev, "Register write error, aborting.\n");\
> + count = -EIO;\
> + } \
> + mutex_unlock(&data->update_lock); \
> + return count; \
> +}
I'm wondering if these functions need to be so huge. Couldn't you do
#define set_temp_para(name, reg)\
static ssize_t set_##name(\
struct device *dev,\
struct device_attribute *attr,\
const char *buf,\
size_t count)\
{\
return set_helper(dev, attr, buf, count, &dev->name);\
}
And then do all the real work in a common function? Rather than
expanding tens of copies of the same thing?
Also, the checkpatch warning
WARNING: consider using strict_strtol in preference to simple_strtol
#381: FILE: drivers/hwmon/amc6821.c:228:
+ int val = simple_strtol(buf, NULL, 10); \
is valid. The problem with simple_strtol() is that it will treat input
of the form "43foo" as "43". Even though the input was invalid. A
minor thing, but easily fixed too.
next prev parent reply other threads:[~2009-09-09 0:06 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-31 20:24 [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 tomaz.mertelj
2009-08-31 20:24 ` [PATCH] hwmon: Driver for Texas Instruments amc6821 chip tomaz.mertelj
2009-09-01 17:56 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Andre Prendel
2009-09-01 17:56 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Andre Prendel
2009-09-02 8:20 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Tomaz Mertelj
2009-09-02 8:20 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Tomaz Mertelj
2009-09-02 8:45 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments corentin.labbe
2009-09-02 8:45 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip corentin.labbe
2009-09-02 23:55 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Andrew Morton
2009-09-02 23:55 ` [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Andrew Morton
2009-09-05 12:08 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments tomaz.mertelj
2009-09-05 12:08 ` [PATCH] hwmon: Driver for Texas Instruments amc6821 chip tomaz.mertelj
2009-09-09 0:06 ` Andrew Morton [this message]
2009-09-09 0:06 ` Andrew Morton
2009-09-09 7:34 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Jean Delvare
2009-09-09 7:34 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Jean Delvare
2009-09-09 8:06 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Andrew Morton
2009-09-09 8:06 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Andrew Morton
2009-09-09 12:24 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Tomaz Mertelj
2009-09-09 12:24 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Tomaz Mertelj
2009-09-09 12:45 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Jean Delvare
2009-09-09 12:45 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Jean Delvare
2009-09-21 21:44 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Andrew Morton
2009-09-21 21:44 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Andrew Morton
2009-09-22 5:59 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Tomaz Mertelj
2009-09-22 5:59 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Tomaz Mertelj
2009-09-22 6:02 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Andrew Morton
2009-09-22 6:02 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip Andrew Morton
2013-01-13 0:16 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments INA209 Guenter Roeck
2013-01-14 21:17 ` Ira W. Snyder
2013-01-15 6:04 ` Guenter Roeck
2013-01-15 22:10 ` Paul Hays
2013-01-15 22:56 ` Guenter Roeck
2013-01-22 21:43 ` Ira W. Snyder
2013-01-22 22:15 ` Ira W. Snyder
2013-01-23 4:30 ` Guenter Roeck
-- strict thread matches above, loose matches on Subject: below --
2009-09-23 9:32 [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip tomaz.mertelj
2009-09-30 19:44 ` [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments Andrew Morton
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=20090908170649.855dd1ff.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
--cc=tomaz.mertelj@guest.arnes.si \
/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.