[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <194d943e-e840-2941-22b9-f6a1a096c539@suse.de>
Date: Fri, 10 Mar 2023 13:38:24 +0100
From: Thomas Zimmermann <tzimmermann@...e.de>
To: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: deller@....de, timur@...nel.org, rdunlap@...radead.org,
paulus@...ba.org, benh@...nel.crashing.org, linux@...linux.org.uk,
pjones@...hat.com, adaplas@...il.com, s.hauer@...gutronix.de,
shawnguo@...nel.org, mbroemme@...mpq.org, thomas@...ischhofer.net,
James.Bottomley@...senpartnership.com, sudipm.mukherjee@...il.com,
teddy.wang@...iconmotion.com, corbet@....net,
linux-fbdev@...r.kernel.org, dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 001/101] lib: Add option iterator
Hi
Am 10.03.23 um 09:21 schrieb Geert Uytterhoeven:
> Hi Thomas,
>
> On Thu, Mar 9, 2023 at 5:02 PM Thomas Zimmermann <tzimmermann@...e.de> wrote:
>> Add struct option_iter and helpers that walk over individual options
>> of an option string. Add documentation.
>>
>> Kernel parameters often have the format of
>>
>> param=opt1,opt2:val,opt3
>>
>> where the option string contains a number of comma-separated options.
>> Drivers usually use strsep() in a loop to extract individual options
>> from the string. Each call to strsep() modifies the given string, so
>> callers have to duplicate kernel parameters that are to be parsed
>> multiple times.
>>
>> The new struct option_iter and its helpers wrap this code behind a
>> clean interface. Drivers can iterate over the options without having
>> to know the details of the option-string format. The iterator handles
>> string memory internally without modifying the original options.
>>
>> v2:
>> * improve documentation (Randy)
>> * implement option_iter_next() as function
>> * allow modification of the returned options
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@...e.de>
>
> Thanks for your patch!
>
> I> ---
>> Documentation/core-api/kernel-api.rst | 9 +++
>> include/linux/cmdline.h | 36 +++++++++
>> lib/Makefile | 2 +-
>> lib/cmdline_iter.c | 109 ++++++++++++++++++++++++++
>> 4 files changed, 155 insertions(+), 1 deletion(-)
>> create mode 100644 include/linux/cmdline.h
>> create mode 100644 lib/cmdline_iter.c
>
> Just wondering, is there any code that can be shared with/reused from
> the existing lib/cmdline.c?
AFAIU, cmdline.o is linked into early-boot code, which prevents it from
using dynamic memory allocation, such as kstrdup() and kfree(). The
linker warns about this:
LD arch/x86/boot/compressed/vmlinux
ld: arch/x86/boot/compressed/kaslr.o: in function `get_option':
kaslr.c:(.text+0x532): undefined reference to `kstrdup'
ld: arch/x86/boot/compressed/vmlinux: hidden symbol `kstrdup' isn't
defined
ld: final link failed: bad value
So the iterator is in a separate source file.
The code in cmdline.c mostly deals with parsing individual values or
key-value pairs. Nothing moves over the complete string and returns
options one by one. There's not much to share AFAICT.
Best regards
Thomas
>
> Gr{oetje,eeting}s,
>
> Geert
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Download attachment "OpenPGP_signature" of type "application/pgp-signature" (841 bytes)
Powered by blists - more mailing lists