Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp434256imw; Fri, 8 Jul 2022 05:44:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u7i0LyWfG25fnFjk1HDyXaMs+zsGHGg8TEcV3TstFY3UICFmPEYihaa1N7paKX5yuQN7C3 X-Received: by 2002:a17:902:7290:b0:16b:b6b5:7e6c with SMTP id d16-20020a170902729000b0016bb6b57e6cmr3765594pll.116.1657284275026; Fri, 08 Jul 2022 05:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657284275; cv=none; d=google.com; s=arc-20160816; b=JbQJCXgjvZ5Qd2aZ/R55aSAk0XwFDY7DX5ReIUr5OtNY0BNHs5UoCLV4xfbiEqbTl0 uxdeRr0LcBBX0j66hHbUT41vo6C+kde1ivWf7kOQXd8fKBdV6oSPLQBv5hP/lVTCrXsk UW2RmsTd8mULPZYpDuWd/jcxJ0cOLOotwwg9052sJADTN0HlLTbpCUzM8rLnrPW+nlWY nSg55kyGRTKTT3nx2PL8ms5eMhvKvFC3YVaDXtkVEciv+er7BBHPahw3IJcKqxAEDJ8V BFP4ML0enAMm7kTvhUhdTQ09l7p54CFuJDb4l4tS1r05V5oo3S9MrwDGtAlzc95CETvx o0Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Y9RkMjhCEeiK1GYpLADtTY7BE5GgRvPn0kmnIBh0v/8=; b=wXXg2RkbXuKZL4O43NyvO5qfF29+8WfSmxs/kdN7aCcDfOQfwyvOtpuhgPQpkL43yp XhA5veW09tmd7QsjpSEQned+ZBNxMK58CkDwQMAWNzOiuG68byAHaCMoXfGOAJhrTIZu 7EpEG+zytKMjQgCfKAn0ky6ubrxzdAQc+4/KuFeJr8yyq2GkYE5Ffx+Wht1KWDJYTsqM CnSQ0oweibfQHOdxeek78DZzYDGoEmAYp73/F1eu+K0kVByFGEXLBdOh3S5ocQuin7oq MqlEcWZtAMT8LHGF+1Kdo7R3xu0TKMH8l/o2geuH3Le86dCnyNpxXIGyGmn+x7K3pCM4 4EEg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 n8-20020a170902d2c800b0016c0593be3dsi4522444plc.320.2022.07.08.05.44.21; Fri, 08 Jul 2022 05:44:35 -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; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237970AbiGHMax (ORCPT + 99 others); Fri, 8 Jul 2022 08:30:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237891AbiGHMaw (ORCPT ); Fri, 8 Jul 2022 08:30:52 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ED4E326C8 for ; Fri, 8 Jul 2022 05:30:51 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6400,9594,10401"; a="264049734" X-IronPort-AV: E=Sophos;i="5.92,255,1650956400"; d="scan'208";a="264049734" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2022 05:30:50 -0700 X-IronPort-AV: E=Sophos;i="5.92,255,1650956400"; d="scan'208";a="661758508" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2022 05:30:47 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1o9n88-00183d-0o; Fri, 08 Jul 2022 15:30:44 +0300 Date: Fri, 8 Jul 2022 15:30:44 +0300 From: Andy Shevchenko To: Cezary Rojewski Cc: Andy Shevchenko , Mark Brown , ALSA Development Mailing List , Takashi Iwai , Jaroslav Kysela , amadeuszx.slawinski@linux.intel.com, Pierre-Louis Bossart , Hans de Goede , =?iso-8859-1?Q?P=E9ter?= Ujfalusi , Ranjani Sridharan , Linux Kernel Mailing List , Liam Girdwood , Kai Vehmanen , Bard Liao Subject: Re: [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32() Message-ID: References: <20220707091301.1282291-1-cezary.rojewski@intel.com> <6c8e4104-2239-a188-649d-585f059cabdd@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6c8e4104-2239-a188-649d-585f059cabdd@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no 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 08, 2022 at 02:13:14PM +0200, Cezary Rojewski wrote: > On 2022-07-08 1:46 PM, Andy Shevchenko wrote: > > On Fri, Jul 8, 2022 at 1:33 PM Cezary Rojewski > > wrote: ... > > > When I'd written the very first version of this function many months > > > ago, get_options() looked as it does not fulfill our needs. It seems to > > > be true even today: caller needs to know the number of elements in an > > > array upfront. > > > > Have you read a kernel doc for it? It does return the number of > > elements at the first pass. > > Yes, I've checked several parts of it. Perhaps I did miss something but > simple_strtoull() doc reads: use kstrtox() instead. Doc was fixed to make clearer that in some cases it's okay to use simple_strtox(). And this was exactly due to obfuscation code with this recommendation. Yes, in general one supposed to use kstrtox(), but it's not 100% obligatory. > Thus the strsplit_u32() > makes use of kstrtox(). Yeah... > > > Also, kstrtox() takes into account '0x' and modifies the > > > base accordingly if that's the case. simple_strtoull() looks as not > > > capable of doing the same thing. > > > > How come?! It does parse all known prefixes: 0x, 0, +, -. > > Hmm.. doc says that it stops at the first non-digit character. Will > re-check. Yes, but under non-digit implies the standard prefixes of digits. simple_strtox() and kstrotox() use the very same function for prefixes. > > > The goal is to be able to parse input such as: > > > > > > 0x1000003,0,0,0x1000004,0,0 > > > > > > into a sequence of 6 uints, filling the *tkns and *num_tkns for the caller. > > > > Yes. Have you checked the test cases for get_options()? (1) ... > > > avs-driver, which is also part of the ASoC framework has very similar > > > debug-interface. I believe there's no need to duplicate the functions - > > > move them to common code instead. > > > > Taking the above into account, please try to use get_options() and > > then tell me what's not working with it. If so, we will add test cases > > to get_options() and fix it. > > There is a difference: > > // get_options > int ints[5]; > > s = get_options(str, ARRAY_SIZE(ints), ints); > > // strsplit_u32() > u32 *tkns, num_tkns; > > ret = strsplit_u32(str, delim, &tkns, &num_tkns); > > Nothing has been told upfront for in the second case. 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; -- With Best Regards, Andy Shevchenko