From: Henrik Rydberg <rydberg@euromail.se>
To: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Jean Delvare <khali@linux-fr.org>,
"lm-sensors@lm-sensors.org" <lm-sensors@lm-sensors.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [lm-sensors] [PATCH] hwmon: (applesmc) Fix checkpatch errors
Date: Wed, 10 Nov 2010 19:56:20 +0000 [thread overview]
Message-ID: <4CDAF8E4.7030609@euromail.se> (raw)
In-Reply-To: <20101110193930.GA31650@ericsson.com>
>>> @@ -977,7 +975,11 @@ static ssize_t applesmc_key_at_index_show
>>> static ssize_t applesmc_key_at_index_store(struct device *dev,
>>> struct device_attribute *attr, const char *sysfsbuf, size_t count)
>>> {
>>> - key_at_index = simple_strtoul(sysfsbuf, NULL, 10);
>>> + unsigned long newkey;
>>> +
>>> + if (strict_strtoul(sysfsbuf, 10, &newkey) < 0)
>>> + return -EINVAL;
>>> + key_at_index = newkey;
>>
>>
>> Crash alert - key_at_index is not range checked, and the remake uses this value
>> as an array index...
>>
> Good that I made this change ;). I'll add the check and re-send.
Indeed! The downside of remakes... sorry about that. :-)
I guess the change should go into patch 4 already? There is also the option to
put the bounds check in applesmc_get_entry_by_index, but I like the simplicity
of "|| newkey >= smcreg.key_count".
> This points to another problem, though. You allocate key_count entries,
> ie cache[0]..cache[key_count-1]. Yet, the key searches are from 0..key_count,
> ie span key_count+1 entries. Is that another problem ?
>
> Seems to me you would either have to allocate key_count+1 entries, or terminate
> the search at key_count - 1. Not sure which one would be correct. Let me know,
> and I'll update the affected patch(es).
If you are referring to the lower and upper bound functions, those use the
one-past-the-last-element convention, so it is actually still 0..key_count - 1.
I stayed very close to the stl reference implementation, which relies on the
fact that when begin != end, (begin + (end - begin) / 2) < end.
Cheers,
Henrik
_______________________________________________
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: Henrik Rydberg <rydberg@euromail.se>
To: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Jean Delvare <khali@linux-fr.org>,
"lm-sensors@lm-sensors.org" <lm-sensors@lm-sensors.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] hwmon: (applesmc) Fix checkpatch errors
Date: Wed, 10 Nov 2010 20:56:20 +0100 [thread overview]
Message-ID: <4CDAF8E4.7030609@euromail.se> (raw)
In-Reply-To: <20101110193930.GA31650@ericsson.com>
>>> @@ -977,7 +975,11 @@ static ssize_t applesmc_key_at_index_show
>>> static ssize_t applesmc_key_at_index_store(struct device *dev,
>>> struct device_attribute *attr, const char *sysfsbuf, size_t count)
>>> {
>>> - key_at_index = simple_strtoul(sysfsbuf, NULL, 10);
>>> + unsigned long newkey;
>>> +
>>> + if (strict_strtoul(sysfsbuf, 10, &newkey) < 0)
>>> + return -EINVAL;
>>> + key_at_index = newkey;
>>
>>
>> Crash alert - key_at_index is not range checked, and the remake uses this value
>> as an array index...
>>
> Good that I made this change ;). I'll add the check and re-send.
Indeed! The downside of remakes... sorry about that. :-)
I guess the change should go into patch 4 already? There is also the option to
put the bounds check in applesmc_get_entry_by_index, but I like the simplicity
of "|| newkey >= smcreg.key_count".
> This points to another problem, though. You allocate key_count entries,
> ie cache[0]..cache[key_count-1]. Yet, the key searches are from 0..key_count,
> ie span key_count+1 entries. Is that another problem ?
>
> Seems to me you would either have to allocate key_count+1 entries, or terminate
> the search at key_count - 1. Not sure which one would be correct. Let me know,
> and I'll update the affected patch(es).
If you are referring to the lower and upper bound functions, those use the
one-past-the-last-element convention, so it is actually still 0..key_count - 1.
I stayed very close to the stl reference implementation, which relies on the
fact that when begin != end, (begin + (end - begin) / 2) < end.
Cheers,
Henrik
next prev parent reply other threads:[~2010-11-10 19:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-10 18:53 [lm-sensors] [PATCH] hwmon: (applesmc) Fix checkpatch errors Guenter Roeck
2010-11-10 18:53 ` Guenter Roeck
2010-11-10 18:52 ` [lm-sensors] " Henrik Rydberg
2010-11-10 18:52 ` Henrik Rydberg
2010-11-10 19:39 ` [lm-sensors] " Guenter Roeck
2010-11-10 19:39 ` Guenter Roeck
2010-11-10 19:56 ` Henrik Rydberg [this message]
2010-11-10 19:56 ` Henrik Rydberg
2010-11-10 20:12 ` [lm-sensors] " Guenter Roeck
2010-11-10 20:12 ` Guenter Roeck
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=4CDAF8E4.7030609@euromail.se \
--to=rydberg@euromail.se \
--cc=guenter.roeck@ericsson.com \
--cc=khali@linux-fr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.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.