From: Jean Delvare <khali@linux-fr.org>
To: Tomaz Mertelj <tomaz.mertelj@guest.arnes.si>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org
Subject: Re: [lm-sensors] [PATCH] hwmon: Driver for Texas Instruments amc6821 chip
Date: Wed, 9 Sep 2009 14:45:54 +0200 [thread overview]
Message-ID: <20090909144554.4cda2297@hyperion.delvare> (raw)
In-Reply-To: <5.1.0.14.2.20090909140903.038dbd90@pop3.arnes.si>
On Wed, 09 Sep 2009 14:24:05 +0200, Tomaz Mertelj wrote:
> At 09:34 9. 9. 2009 +0200, Jean Delvare wrote:
> >Yes please. We got rid of macro-generated callbacks in most hwmon
> >drivers a couple years ago already.
>
> I do not like macro-generated callbacks myself as well. However, I was
> impatient to get the
> driver working and since I have seen similar things in a few other drivers ...
>
> I would prefer a single callback (would require some more work):
>
> static ssize_t set_temp(
> 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 nr = to_sensor_dev_attr(attr)->index;
> int val = simple_strtol(buf, NULL, 10);
> val = SENSORS_LIMIT(val / 1000, -128, 127);
> int *pvar;
> u8 reg;
>
> switch (nr) {
> case GET_SET_TEMP1_MIN:
> pvar=&data->temp1_min;
> reg=AMC6821_REG_LTEMP_LIMIT_MIN;
> break;
> case ...
>
> ...
>
> default:
> dev_dbg(dev, "Unknown attr->index (%d)\n", nr);
> return SOME_ERROR;
> }
> mutex_lock(&data->update_lock);
> *pvar=val;
> if (i2c_smbus_write_byte_data(client, reg, *pvar)) {
> dev_err(&client->dev, "Register write error, aborting.\n");
> count = -EIO;
> }
> mutex_unlock(&data->update_lock);
> return count;
> }
>
>
> static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, get_temp,
> set_temp, GET_SET_TEMP1_MIN);
> ...
Yes, would be much better. Or you can make things even better by
defining arrays of variables in your data structure, and arrays for
register numbers too. And if you need to pass 2 identifiers per entry,
you can take a look at struct sensor_device_attribute_2. So you have a
lot of possibilities to make the code more compact. To which degree you
want that, is up to you.
> > > 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.
> >
> >Is there any legitimate use of simple_strtol then? I'm wondering why we
> >don't just get rid of it and rename strict_strtol to just strtol.
>
> I have seen simple_strtol in many hwmon drivers so I thought there might be
> a reason to do it this way?
Historical, as I recall, the strict variant did not exist when we
converted the first driver. And then copy-and-paste from driver to
driver, and here we are.
--
Jean Delvare
next prev parent reply other threads:[~2009-09-09 12:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-05 12:08 [PATCH] hwmon: Driver for Texas Instruments amc6821 chip tomaz.mertelj
2009-09-09 0:06 ` Andrew Morton
2009-09-09 7:34 ` [lm-sensors] " Jean Delvare
2009-09-09 8:06 ` Andrew Morton
2009-09-09 12:24 ` Tomaz Mertelj
2009-09-09 12:45 ` Jean Delvare [this message]
2009-09-21 21:44 ` Andrew Morton
2009-09-22 5:59 ` Tomaz Mertelj
2009-09-22 6:02 ` Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2009-10-01 7:42 Tomaz Mertelj
2009-09-23 9:32 tomaz.mertelj
2009-09-30 19:44 ` Andrew Morton
2009-08-31 20:24 tomaz.mertelj
2009-09-01 17:56 ` [lm-sensors] " Andre Prendel
2009-09-02 8:20 ` Tomaz Mertelj
2009-09-02 8:45 ` corentin.labbe
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=20090909144554.4cda2297@hyperion.delvare \
--to=khali@linux-fr.org \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox