From: Cezary Rojewski <cezary.rojewski@intel.com>
To: "Dan Carpenter" <dan.carpenter@oracle.com>,
"Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
alsa-devel@alsa-project.org,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Daniel Baluta <daniel.baluta@nxp.com>,
kernel-janitors@vger.kernel.org,
Liam Girdwood <lgirdwood@gmail.com>,
Takashi Iwai <tiwai@suse.com>, Mark Brown <broonie@kernel.org>,
Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
Bard Liao <yung-chuan.liao@linux.intel.com>,
sound-open-firmware@alsa-project.org
Subject: Re: [PATCH 2/2] ASoC: SOF: sof-client-probes: cleanup tokenize_input()
Date: Wed, 6 Jul 2022 12:56:57 +0200 [thread overview]
Message-ID: <b256c70d-baf8-7f3e-ca52-e7f920e4602d@intel.com> (raw)
In-Reply-To: <20220706104443.GE2338@kadam>
On 2022-07-06 12:44 PM, Dan Carpenter wrote:
> On Wed, Jul 06, 2022 at 12:27:49PM +0300, Péter Ujfalusi wrote:
>>
>>
>> On 06/07/2022 10:25, Dan Carpenter wrote:
>>> The tokenize_input() function is cleaner if it uses strndup_user()
>>> instead of simple_write_to_buffer(). The way it's written now, if
>>> *ppos is non-zero then it returns -EIO but normally we would return
>>> 0 in that case. It's easier to handle that in the callers.
>>
>> This patch breaks the probe point settings:
>>
>> # echo 52,1,0 > /sys/kernel/debug/sof/probe_points
>> -bash: echo: write error: Invalid argument
>>
>> I did not looked for the exact reason, but something is not correct.
>>
>
> Crud...
>
> Thanks for testing.
>
> I used strndup_user() in a couple other patches today and I didn't
> realize how strict it was. I've NAKed my patches which used
> strndup_user(). One of the patches was an infoleak patch so I'm going
> to resend that using memdup_user() instead but let's just drop this one.
>
> I guess another safer option would be to just always zero the buffers
> going into simple_write_to_buffer()...
>
> regards,
> dan carpenter
>
Hello,
Indeed the strsplit_u32() contains some bugs - tokenize_input() needs no
fixes if I'm not mistaken though.
It seems I did not realize the bugs were not fixed. As the avs-driver
makes use of probes too and these are being tested there regularly the
team did notice the problems. Below is the implementation. I'm saying
this as the plan is to move both strsplit_u32() and tokenize_input()
into the common code so it can be re-used by both drivers. Will send the
patches soon :)
Regards,
Czarek
static 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) {
max_count *= 2;
tmp = krealloc(buf, max_count * sizeof(*buf),
GFP_KERNEL);
if (!tmp) {
ret = -ENOMEM;
goto free_buf;
}
buf = tmp;
}
}
if (!count)
goto free_buf;
*tkns = kmemdup(buf, count * sizeof(*buf), GFP_KERNEL);
if (*tkns == NULL) {
ret = -ENOMEM;
goto free_buf;
}
*num_tkns = count;
free_buf:
kfree(buf);
return ret;
}
next prev parent reply other threads:[~2022-07-06 10:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-06 7:23 [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Dan Carpenter
2022-07-06 7:25 ` [PATCH 2/2] ASoC: SOF: sof-client-probes: cleanup tokenize_input() Dan Carpenter
2022-07-06 9:27 ` Péter Ujfalusi
2022-07-06 10:44 ` Dan Carpenter
2022-07-06 10:56 ` Cezary Rojewski [this message]
2022-07-06 9:05 ` [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Péter Ujfalusi
2022-07-06 10:00 ` Péter Ujfalusi
2022-07-06 10:21 ` Dan Carpenter
2022-07-06 10:31 ` Dan Carpenter
2022-07-06 10:36 ` Dan Carpenter
2022-07-06 10:41 ` Péter Ujfalusi
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=b256c70d-baf8-7f3e-ca52-e7f920e4602d@intel.com \
--to=cezary.rojewski@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=daniel.baluta@nxp.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=lgirdwood@gmail.com \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=ranjani.sridharan@linux.intel.com \
--cc=sound-open-firmware@alsa-project.org \
--cc=tiwai@suse.com \
--cc=yung-chuan.liao@linux.intel.com \
/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