Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4392187imw; Tue, 12 Jul 2022 07:13:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vVmBNWXhm2P/MXhU3B6pJ9K7VZwiETPXrDevNtdI/+eI8l2C+Rk4+5DoFwbKYSeoMdwezI X-Received: by 2002:a05:6402:42c8:b0:43a:a1ee:a097 with SMTP id i8-20020a05640242c800b0043aa1eea097mr31891015edc.150.1657635217970; Tue, 12 Jul 2022 07:13:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657635217; cv=none; d=google.com; s=arc-20160816; b=jWVlKw7P10ok9NzoCmpZUDLuKa68l0u4Pc701yVtzPI1tSEeLoX2uau8SFjTgT7au2 5brIwEDk9cQfVYeIivGbbDxM0ZK9YRzxV69+hBdHsYGCDxJriz0WJw2yxVSdDHAS82a/ oJRrmY2BZfLEgrAFXguyuXeiV6vgUnGQ4wHn6GW0xjARp8GzJkay2bJ5//U639XCYcsK xMWvQ7c6ReRrWKPOshwcWw1Njd+wqfqtZPWGRba/6Q5eYd6mSG8npBlYzxXz2EAO8oOU iuiOZaU0J6c9dy8AEdnHUQwS52jVGUMfzamajaFzA9/giNa+F8g0eLgSuLK09d9OPCS7 XMgA== 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=sYY6nXCKD6t30QeXZzY/iyGlqBqf+vc2z0phNL/Eg5g=; b=leiZNX94nMjHHvItG2bNq6WFtMEAyARj28xeYeZwQ04rzzgAUSxiVn4DlUH/f8T/KX Oi9IZ8XuAYCW3IEf3LFCCaR6OA1wl3oSiQySLnkTKyicVoZjBli8ExMriKhqY7lpGIU2 xCsSA6VoX90Ja3aOw9JUL29eCkDDjW26qGLUr6ykYRQLzCu1QYSgUKLYKnMnFlMVptx4 aQtlS8gsKMQK33tO9rX7JGso5eeAS1DUkth/pg/9og9FOM1z69Ul7J/r+oIDKZPiyTj0 1nWe6Kc0WN/Ac0SLjlYvMfM7gM8ThSYOBb7Ff8CMCLuuy8tzdz6c9vO+uVvckgR3BW7d kTuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=k8HJGhE9; 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 nb8-20020a1709071c8800b00715849159c7si16949261ejc.56.2022.07.12.07.13.12; Tue, 12 Jul 2022 07:13:37 -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=k8HJGhE9; 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 S233414AbiGLOBX (ORCPT + 99 others); Tue, 12 Jul 2022 10:01:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbiGLOAy (ORCPT ); Tue, 12 Jul 2022 10:00:54 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA6B7CE0D for ; Tue, 12 Jul 2022 07:00:32 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id i14so14086713yba.1 for ; Tue, 12 Jul 2022 07:00:32 -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=sYY6nXCKD6t30QeXZzY/iyGlqBqf+vc2z0phNL/Eg5g=; b=k8HJGhE9i7B3f6fXvhZ3P0HZBKpKwDS1pIja6IaScsD/R4cHnW/TfG0WC2C/yGAR0H lW83iJwH0EyDvfLzP9E+VKMVCEnWEEoR6GrJPtGn1utXHOoX/4ADJariDHDERwoniiOc DWPMIjXUca8RrVQceMUeI0KBsTI7oMAo1XuXoMuLCD4KixLFKsePYP1wwfQY2xo6EE2w vxBSuUpmkDFV+WgLqc45N1VfEAtHfARRedGII5h4s5EmWfwGUi4X++V4U30TJr1tHb1K sabpmRyvwLsIPOS8Zjpcxwg9t5NckJil5NJcITxrM0cCE/f95Z+wi15uKyCcWybfjaCS Wo+A== 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=sYY6nXCKD6t30QeXZzY/iyGlqBqf+vc2z0phNL/Eg5g=; b=iTUUorcn5cPTrSyV2arXD8WmcE8jNp9z7PNfp7iUMPMLbHmDXM13dpdff0hZLD+Thu 0yeMJIabRyu1hjKG8COGMk/QC998jJxok/XJ/jytTEQ7n33cGAuB5NTMhvaVkeQ9Hh4v 0VApSQIF09grGMTf2UhOnNZUVwWl83xwvZVhYM3jRZvPfFwbXsPzfgfdkE7PupRVXpJ0 03T6/vFyU95kVqudIt2gMvI3sgT5KAEl8l+sJRJT+B7Zr84IYhO7FbzBCjejJ9KOIQVi Setl9RGO24HfuKJN0+YEDT8uSUOMDoVtw2DfzL8FwWokihQY11F0LomsbokHzKnBJlG2 /BPA== X-Gm-Message-State: AJIora/DdFS8/XyKezXrf/zZJQr/7xv1UXAuCrIFw4P959Z4yudUIeE4 J9UDv8izWkM+FSLVqc7G+vQMEPdGoV4SOCa7WHM= X-Received: by 2002:a05:6902:686:b0:66e:627f:4d29 with SMTP id i6-20020a056902068600b0066e627f4d29mr21041851ybt.385.1657634432032; Tue, 12 Jul 2022 07:00:32 -0700 (PDT) MIME-Version: 1.0 References: <6c8e4104-2239-a188-649d-585f059cabdd@intel.com> <2c6a4a61-e6c8-0487-8d29-dc3fbb90bbe2@intel.com> In-Reply-To: <2c6a4a61-e6c8-0487-8d29-dc3fbb90bbe2@intel.com> From: Andy Shevchenko Date: Tue, 12 Jul 2022 15:59:54 +0200 Message-ID: Subject: Re: [PATCH 1/2] lib/string_helpers: Introduce strsplit_u32() To: Cezary Rojewski Cc: =?UTF-8?Q?P=C3=A9ter_Ujfalusi?= , 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 Tue, Jul 12, 2022 at 3:51 PM Cezary Rojewski wrote: > On 2022-07-09 10:42 PM, Andy Shevchenko wrote: > > On Sat, Jul 09, 2022 at 10:45:49AM +0200, Cezary Rojewski wrote: > >> On 2022-07-08 6:49 PM, Andy Shevchenko wrote: > >>> On Fri, Jul 8, 2022 at 6:32 PM Cezary Rojewski > >>> wrote: > >>>> On 2022-07-08 5:25 PM, Andy Shevchenko wrote: > >>>>> On Fri, Jul 8, 2022 at 2:34 PM P=C3=A9ter Ujfalusi > >>>>> wrote: ... > >>>> A long shot, but what if we were to modify get_options() so it takes > >>>> additional element-size parameter instead? > >>> > >>> But why? int / unsigned int, u32 / s32 are all compatible in the cur= rent cases. > >> > >> I'd like to avoid any additional operations, so that the retrieved pay= load > >> can be provided to the IPC handler directly. The IPC handlers for Audi= oDSP > >> drivers are expecting payload in u32s. > >> > >> // u32 **tkns, size_t *num_tkns as foo() arguments > >> // u32 *ints, int nints as locals > >> > >> get_options(buf, 0, &nints); > >> if (!nints) { > >> ret =3D -ENOENT; > >> goto free_buf; > >> } > >> > >> ints =3D kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL); > >> if (!ints) { > >> ret =3D -ENOMEM; > >> goto free_buf; > >> } > >> > >> get_num_options(buf, nints + 1, ints, sizeof(*ints)); > >> > >> *tkns =3D ints; > >> *num_tkns =3D nints; > >> > >> No additional operations in between. The intermediate IPC handler can = later > >> refer to the actual payload via &tkns[1] before passing it to the gene= ric > >> one. > >> > >> Casting int array into u32 array does not feel right, or perhaps I'm m= issing > >> something like in the doc case. > > > > C standard. > > > > int to unsigned int is not promoted. And standard says that "The rank o= f any > > unsigned integer type shall equal the rank of the corresponding signed = integer > > type, if any." > > > > I don't know why one needs to have an additional churn here. int and un= signed > > int are interoperable with the adjustment to the sign when the other ar= gument > > is signed or lesser rank of. > > I still believe that casting blindly is not the way to go. I did > explicitly ask about int vs u32, There is no such type in the C standard. > not int vs unsigned int. Please note > that these values are later passed to the IPC handlers, and this changes > the context a bit. If hw expects u32, then u32 it shall be. H/W doesn't expect u32, HW expects bytes or group of bytes with: 1) dedicated address alignment (if required); 2) dedicated byte order; 3) dedicated padding (if required). Correct me if I'm wrong. > Please correct me if I'm wrong, but there is no guarantee that int is > always 32bits long. There is no guarantee by the C standard, indeed, but there is an upper level guarantee, by the Linux kernel. > What is guaranteed though, is that int holds at > least -/+ 32,767. Also, values larger than INT_MAX are allowed in the > IPC payload. Yeah... this is binary protocol, right? So, what limits are you talking about here if they are not applicable there anyway. It's simply different dimension of limits (i.e. bytes and bits and not C language types). --=20 With Best Regards, Andy Shevchenko