[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f05a9b04-b635-df6f-1c94-b44371d24041@intel.com>
Date: Fri, 8 Jul 2022 13:33:37 +0200
From: Cezary Rojewski <cezary.rojewski@...el.com>
To: Péter Ujfalusi <peter.ujfalusi@...ux.intel.com>,
<andy@...nel.org>, <broonie@...nel.org>
CC: <alsa-devel@...a-project.org>, <tiwai@...e.com>, <perex@...ex.cz>,
<amadeuszx.slawinski@...ux.intel.com>,
<pierre-louis.bossart@...ux.intel.com>, <hdegoede@...hat.com>,
<ranjani.sridharan@...ux.intel.com>,
<linux-kernel@...r.kernel.org>, <lgirdwood@...il.com>,
<kai.vehmanen@...ux.intel.com>, <yung-chuan.liao@...ux.intel.com>
Subject: Re: [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32()
On 2022-07-07 3:51 PM, Péter Ujfalusi wrote:
> On 07/07/2022 12:13, Cezary Rojewski wrote:
...
>> +int strsplit_u32(const char *str, const char *delim, u32 **tkns, size_t *num_tkns)
>> +{
>> + size_t max_count = 32;
>> + size_t count = 0;
>> + char *s, **p;
>> + u32 *buf, *tmp;
>> + int ret = 0;
>> +
>> + p = (char **)&str;
>> + *tkns = NULL;
>> + *num_tkns = 0;
>> +
>> + buf = kcalloc(max_count, sizeof(*buf), GFP_KERNEL);
>> + if (!buf)
>> + return -ENOMEM;
>> +
>> + while ((s = strsep(p, delim)) != NULL) {
>> + ret = kstrtouint(s, 0, buf + count);
>> + if (ret)
>> + goto free_buf;
>> +
>> + if (++count > max_count) {
>
> I think this should be as it was originally:
> if (++count >= max_count) {
>
> Otherwise when we reach the max_count we would not realloc to get more
> space and the data + max_count is pointing outside of the allocated area.
I believe you're right. Will change in v2.
Regards,
Czarek
Powered by blists - more mailing lists