From: Ben Dooks <ben@simtec.co.uk>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] HWMON: S3C24XX series ADC driver
Date: Sat, 30 May 2009 15:43:30 +0000 [thread overview]
Message-ID: <4A215422.3050504@simtec.co.uk> (raw)
In-Reply-To: <20090520215029.692678819@fluff.org.uk>
Jean Delvare wrote:
> On Sat, 30 May 2009 14:47:03 +0100, Ben Dooks wrote:
>> Jean Delvare wrote:
>>> On Thu, 28 May 2009 21:42:20 +0100, Ben Dooks wrote:
>>>> +static int s3c_hwmon_read_ch(struct device *dev,
>>>> + struct s3c_hwmon *hwmon, int channel)
>>>> +{
>>>> + int ret;
>>>> +
>>>> + ret = down_interruptible(&hwmon->lock);
>>>> + if (ret < 0)
>>>> + return ret;
>>> Why do you need locking here? If any locking is needed, I am reasonably
>>> certain it should be handled by the s3c adc core rather than drivers
>>> using it.
>> I'd rather leave the locking to the client, as in this case
>> we use down_interruptible() so the user can interrupt the
>> call if necessary.
>
> What are you protecting? And how are you protecting it with a
> per-client lock, if there are several clients?
The ADC core code has a simple lock on it to handle
multiple clients, but doesn't handle the same client
trying >1 conversions at a time.
In this case the caller ensures the exclusivity of one
call per client in the way that best suits the caller,
ie something that can be interrupted by the user if
necessary.
>>>> (...)
>>>> +static inline int s3c_hwmon_add_raw(struct device *dev)
>>>> +{
>>>> + int ret, i;
>>>> +
>>>> + for (i = 0; i < ARRAY_SIZE(s3c_hwmon_attrs); i++) {
>>>> + ret = device_create_file(dev, s3c_hwmon_attrs[i]);
>>> Is it OK to create entries for channels which do not exist?
>> The channels always exist, the pdata specifies which channels
>> the board wants to export to userspace via hwmon.
>
> OK. Then you may want to consider declaring a group of attribute and
> register it all at once. This saves you the hassle of handling the
> errors manually.
>
>>>> (...)
>>>> +static int s3c_hwmon_create_attr(struct device *dev,
>>>> + struct s3c_hwmon_chcfg *cfg,
>>>> + struct s3c_hwmon_attr *attrs,
>>>> + int channel)
>>>> +{
>>>> + struct sensor_device_attribute *attr;
>>>> + int ret;
>>>> +
>>>> + if (!cfg)
>>>> + return 0;
>>>> +
>>>> + snprintf(attrs->in_name, sizeof(attrs->in_name), "in%d_input", channel);
>>>> +
>>>> + attr = &attrs->in;
>>>> + attr->index = channel;
>>>> + attr->dev_attr.attr.name = attrs->in_name;
>>>> + attr->dev_attr.attr.mode = S_IRUGO;
>>>> + attr->dev_attr.attr.owner = THIS_MODULE;
>>>> + attr->dev_attr.show = s3c_hwmon_ch_show;
>>>> +
>>>> + ret = device_create_file(dev, &attr->dev_attr);
>>>> + if (ret < 0) {
>>>> + dev_err(dev, "failed to create input attribute\n");
>>>> + return ret;
>>>> + }
>>>> +
>>>> + /* if this has a name, add a label */
>>>> + if (cfg->name) {
>>>> + snprintf(attrs->label_name, sizeof(attrs->label_name),
>>>> + "in%d_label", channel);
>>>> +
>>>> + attr = &attrs->label;
>>>> + attr->index = channel;
>>>> + attr->dev_attr.attr.name = attrs->label_name;
>>>> + attr->dev_attr.attr.mode = S_IRUGO;
>>>> + attr->dev_attr.attr.owner = THIS_MODULE;
>>>> + attr->dev_attr.show = s3c_hwmon_label_show;
>>>> +
>>>> + ret = device_create_file(dev, &attr->dev_attr);
>>>> + if (ret < 0) {
>>>> + device_remove_file(dev, &attrs->in.dev_attr);
>>>> + dev_err(dev, "failed to create label attribute\n");
>>>> + }
>>>> + }
>>>> +
>>>> + return ret;
>>>> +}
>>> I don't understand why you insist on creating these attributes
>>> dynamically. Almost all other hwmon drivers declare the attributes in a
>>> static manner, and only the decision to create each attribute for a
>> you probably wanted to use add here instead of reusing create.
>>> given device is decided at runtime. This makes the code much smaller.
>> I've always prefered to avoid static data when there's a possiblity
>> the device may not be instantiated for the particular machine the
>> kernel is being booted on.
>>
>> The code itself is 256 bytes, wheras having two arrays of attributes
>> would turn up at 384 bytes not including the code to call
>> device_create_file() as appropriate.
>
> You didn't count the memory you have to allocate in the dynamic case,
> so the comparison is hardly fair. That can't be less than the static
> data if all 8 channels are used, and it's even likely to be somewhat
> more due to memory fragmentation. Then of course the exact computation
> depends on how many channels you expect to have on average.
I removed the per-channel allocation, so it will either allocate
enough for 8 channels no matter how many are used, or not allocate
anything if the device is not instantiated. This removes the frag
argument, as we use kmalloc() to instantiate the device context
from the platform device.
The dynamic case makes the built kernel smaller, it doesn't make
the memory usage smaller (the probe code will get thrown away after
initialisation time).
--
Ben Dooks, Software Engineer, Simtec Electronics
http://www.simtec.co.uk/
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
next prev parent reply other threads:[~2009-05-30 15:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-20 21:50 [lm-sensors] HWMON: S3C24XX series ADC driver Ben Dooks
2009-05-25 9:39 ` Ramax Lo
2009-05-26 8:01 ` Ben Dooks
2009-05-26 8:07 ` Ben Dooks
2009-05-26 15:08 ` Hector Oron
2009-05-26 19:20 ` Hector Oron
2009-05-26 21:25 ` Ben Dooks
2009-05-27 20:01 ` Jean Delvare
2009-05-28 11:22 ` Ben Dooks
2009-05-28 11:47 ` Jean Delvare
2009-05-28 13:16 ` Ben Dooks
2009-05-28 15:21 ` Ben Dooks
2009-05-28 15:55 ` Jean Delvare
2009-05-28 20:42 ` Ben Dooks
2009-05-30 12:41 ` Jean Delvare
2009-05-30 13:47 ` Ben Dooks
2009-05-30 14:53 ` Jean Delvare
2009-05-30 15:43 ` Ben Dooks [this message]
2009-06-03 10:14 ` Hector Oron
2009-06-08 11:35 ` Ben Dooks
2009-06-10 7:59 ` Jean Delvare
2009-06-12 9:04 ` Ben Dooks
2009-06-12 9:15 ` Jean Delvare
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=4A215422.3050504@simtec.co.uk \
--to=ben@simtec.co.uk \
--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.