[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vd4D0KF7ik+aMOwv-+bofWja_tDe4YUmihQBF+RiHZTmA@mail.gmail.com>
Date: Fri, 8 Jul 2022 17:25:20 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Péter Ujfalusi <peter.ujfalusi@...ux.intel.com>
Cc: Cezary Rojewski <cezary.rojewski@...el.com>,
Andy Shevchenko <andy@...nel.org>,
Mark Brown <broonie@...nel.org>,
ALSA Development Mailing List <alsa-devel@...a-project.org>,
Takashi Iwai <tiwai@...e.com>,
Jaroslav Kysela <perex@...ex.cz>,
amadeuszx.slawinski@...ux.intel.com,
Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>,
Hans de Goede <hdegoede@...hat.com>,
Ranjani Sridharan <ranjani.sridharan@...ux.intel.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Liam Girdwood <lgirdwood@...il.com>,
Kai Vehmanen <kai.vehmanen@...ux.intel.com>,
Bard Liao <yung-chuan.liao@...ux.intel.com>
Subject: Re: [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32()
On Fri, Jul 8, 2022 at 2:34 PM Péter Ujfalusi
<peter.ujfalusi@...ux.intel.com> wrote:
> On 08/07/2022 15:30, Andy Shevchenko wrote:
> > On Fri, Jul 08, 2022 at 02:13:14PM +0200, Cezary Rojewski wrote:
...
> > It seems you are missing the (1). The code has checks for the case where you
> > can do get number upfront, it would just require two passes, but it's nothing
> > in comparison of heave realloc().
> >
> > unsigned int *tokens;
> > char *p;
> > int num;
> >
> > p = get_options(str, 0, &num);
> > if (num == 0)
> > // No numbers in the string!
> >
> > tokens = kcalloc(num + 1, sizeof(*tokens), GFP_KERNEL);
> > if (!tokens)
> > return -ENOMEM;
> >
> > p = get_oprions(str, num, &tokens);
> > if (*p)
> > // String was parsed only partially!
> > // assuming it's not a fatal error
> >
> > return tokens;
> This diff is tested and works:
Thanks, Peter!
But at least you can memove() to avoid second allocation.
ideally to refactor that the result of get_options is consumed as is
(it may be casted to struct tokens { int n; u32 v[]; })
...
> Could be made nicer with some brain work put to it, we need strict u32 within the IPC message for the array...
True, it needs to be thought through. But I guess you got the idea of
how to use existing library routines.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists