Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp623255imw; Fri, 8 Jul 2022 08:48:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t/gTK4qom3/U2d5+sDU+9SyzUpcy1DCxBET7L1kzvUHVuNZA/1gXskvohIq5DAwA2kGv/R X-Received: by 2002:a17:90b:1c12:b0:1ef:9067:ed4a with SMTP id oc18-20020a17090b1c1200b001ef9067ed4amr557924pjb.90.1657295304437; Fri, 08 Jul 2022 08:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657295304; cv=none; d=google.com; s=arc-20160816; b=Xcueo5zAzvU7Rs7qu8aNIjKLuF8RUXu0BcFspG+Z1xjBFaNpGWBmaglDFWme8kWO8A ro42wKyUQvGgEtSgqfpX32mRJNgBS/qFaYW3AnLW0UALd4gPq4Ergj6sgjKcwQtjkmjh XJCcyRNC1AQBlnxtMfg1gi8qZQ0aEdbIZups6LDw9rDc14sGy+fVtl0/9reqRdFfXff9 aC5FDfaBwJ4NrmMxTTcNuX6dRG98d2ObuRb8m8QGQUxT7MxrHD4Ev3fHc6GiGfaaSowO CjbqbdWYcjfg7pxZsRRhk8BH2YzGZXsr6G4dfJRwcZcqxImsv91zUdkIiraZHugzgDOH J1LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EIFiVH9lUi23KkCa9V/IOGOENSKqD85uGqpTdZl7zAY=; b=DQa73+uIBZpA0LYMy3erbjnl9tqY7cOMgBxveY6Dhl5DsbIG488NBB2Sox3vP4/t5F PTZ4eNeTcWSkJitLVdfMAyM1WdOMZ1dUqrQNjxKbKuYvLSLuSMGHjlLprCot0VjxG9rB 3KMkdevXhRNCPpdxPX39Z5ADcjL65ZqzRMZKgtkH9Pp0TC3tXf1BYWI0O7yAT3wngePt VmiXz2EvBenydctv4/5GOHQIDw/gzCl9kP436e/vbpxHFGroccqnJ4vJFKtw0lW/IT3/ Wck9pcjzLJ4HVZFI03Kh2ehxzn0zgo5SgtQ+gtqCJorA889WUg54tK3j4sNbX+aeSP84 bo9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fWK7HkQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j28-20020a634a5c000000b004152331e6a2si4846659pgl.829.2022.07.08.08.48.11; Fri, 08 Jul 2022 08:48:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fWK7HkQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238542AbiGHP0A (ORCPT + 99 others); Fri, 8 Jul 2022 11:26:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238099AbiGHPZ7 (ORCPT ); Fri, 8 Jul 2022 11:25:59 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C72030F43 for ; Fri, 8 Jul 2022 08:25:58 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id 136so6563708ybl.5 for ; Fri, 08 Jul 2022 08:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=EIFiVH9lUi23KkCa9V/IOGOENSKqD85uGqpTdZl7zAY=; b=fWK7HkQgFIGRyNUeE7G9RPw3OTeLrtzQBU6e4ZqpzOQamkRYX5OaqR/9XQ1BNla4l8 fJVA0X6+czUZHqfcGk1SUUtBiciNfPjS8ygo/Q6RuZd7jfYz/j2GMp1DCbjY/7bRvfpJ F5onpKz8wwWV2aFzs1edfnh8TuAa9hui6zfGFkGILvjlCaqauUH3edoBJz90XprJjq5m sMhL3cew/FXdjmQBFlFsMQ+Ru5D5bCwlsKsBL01juon4WXx5g2yHPcu1T1hPjrqs7dWS LKo91I2os4Gs4yuSPHvZW0PEQrbAREEz95O7WuFrbHmojuhknjtDUp7BdZBRHGa+lJhT bafw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=EIFiVH9lUi23KkCa9V/IOGOENSKqD85uGqpTdZl7zAY=; b=s+jjh8bHFbeSWgo1aR21vwEo8SJnxU/aRr5P4uZr2Z7/pJC0K/Axksit6b2W184AdK 3SlWdVHWGSFlZyMi4AY+/yHQjIiC2rXaXHEw/0KO8T9ECDLkoVG/hacOevQrnlQBJQta vx2n0uInNbRC0llZk8L8HTLwQuylFtSbYduHKR8dANQmzEpVC6GJzxQS28+mCf+YloRr qS3C06K/uonCgCDg8vr2W73hgKR7vxGNzVsX8fJ1oeghbptL+IaU8TopF/f8v2sax3jt XOpPfunARn6sRxgaxYCgC1LlXic8lNatOnR5hHWn2ygvN1ScsDWismj/WzzDMUw8R/jE gc/w== X-Gm-Message-State: AJIora+hUgTbdVsFqu7NUaDXT6kT9o3hGEe1nDh4Zo2m6GRtqs/Un854 scchR589K+8tSgyxGW+00mAXk0/wMGTAeAxFK+I= X-Received: by 2002:a25:dd83:0:b0:66c:8d8d:4f5f with SMTP id u125-20020a25dd83000000b0066c8d8d4f5fmr4307324ybg.79.1657293957266; Fri, 08 Jul 2022 08:25:57 -0700 (PDT) MIME-Version: 1.0 References: <20220707091301.1282291-1-cezary.rojewski@intel.com> <6c8e4104-2239-a188-649d-585f059cabdd@intel.com> In-Reply-To: From: Andy Shevchenko Date: Fri, 8 Jul 2022 17:25:20 +0200 Message-ID: Subject: Re: [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32() To: =?UTF-8?Q?P=C3=A9ter_Ujfalusi?= Cc: Cezary Rojewski , Andy Shevchenko , Mark Brown , ALSA Development Mailing List , Takashi Iwai , Jaroslav Kysela , amadeuszx.slawinski@linux.intel.com, Pierre-Louis Bossart , Hans de Goede , Ranjani Sridharan , Linux Kernel Mailing List , Liam Girdwood , Kai Vehmanen , Bard Liao Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 8, 2022 at 2:34 PM P=C3=A9ter Ujfalusi 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 wher= e you > > can do get number upfront, it would just require two passes, but it's n= othing > > in comparison of heave realloc(). > > > > unsigned int *tokens; > > char *p; > > int num; > > > > p =3D get_options(str, 0, &num); > > if (num =3D=3D 0) > > // No numbers in the string! > > > > tokens =3D kcalloc(num + 1, sizeof(*tokens), GFP_KERNEL); > > if (!tokens) > > return -ENOMEM; > > > > p =3D 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 wi= thin 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. --=20 With Best Regards, Andy Shevchenko