Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6059071rwb; Tue, 9 Aug 2022 08:27:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR6I/SOZMPtcbQWpPElYx+gAbbxp6zOJKDHYPouf+ZJPk2t4Am+xycGz9YbmmjlWB9OZRg42 X-Received: by 2002:a17:907:6d18:b0:731:219a:49a0 with SMTP id sa24-20020a1709076d1800b00731219a49a0mr11487408ejc.406.1660058864328; Tue, 09 Aug 2022 08:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660058864; cv=none; d=google.com; s=arc-20160816; b=Uqr4aP81KtF8rvca85R35Fs0uDO1HALmritXi6e9GGbQYBYG1SI0RsTnhoHf7xSNI1 i8NeYEJEXsKLGB2FAla/JDxEyoV1tA9rwbhfVnNfrqS6edF1Q26Zk+xsSfZ9snzVAPKB I6znmDsHpgHWsG6r0Djmo0TBkMDOyvUvIgtkRULCpEgPXRdT3+0P8aCotbR5xFHwU0CQ KrdVgi11rFYZoEaJw/TWyllgJU/fTLOt1QeimPjxtMViJJAgOvP/KmgfVpLpy6aGXUiA sNgSh1qOEEBHy5NLpui7uHZ2pwfgtoy/Mfh07P/4T+/LS117qKOnCTvqGPABmkgDVwge zXWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=A5REIXPZhx2QvQynwWaByU5xDx6beRgsM1q7t3M3QIc=; b=RMHaqZtpZl3/1fma5JYzO2tzGU0VVGkkRGgPHOvAsjAMa7+4bi+rH9m003s9W09moE fJyXNyVBdfxQH7tmAEMo7uj9INcHwPkunMPiFqp4Y7pgEB5Qdvm+Zzir5ZNAA3Gh5NT8 ROy7ENWOhfcbTBiRkfRboM3fTN4kD4w7hSxJ+kLfpweYij3VLxIUTVB0u0zTuhmQtThX 66u0lSTucOKkcb6l2jU8AcLFEkpqlNt673X2hWkMuk0Hr9f2g+pfR1WYj71XgIgVD09z pcgLUMlrMmtv7WDU/DOzyvGLhETodr9kkjxAmaE0YWVXW6H7PZUWNpE6V/U8le3Fs93l RhqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="A2SxNph/"; 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 e4-20020a17090658c400b0072b01ae9c69si2532967ejs.694.2022.08.09.08.27.15; Tue, 09 Aug 2022 08:27:44 -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="A2SxNph/"; 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 S240111AbiHIPXu (ORCPT + 99 others); Tue, 9 Aug 2022 11:23:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237621AbiHIPXs (ORCPT ); Tue, 9 Aug 2022 11:23:48 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF2B2101E for ; Tue, 9 Aug 2022 08:23:44 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id s11so2021636qtx.6 for ; Tue, 09 Aug 2022 08:23:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=A5REIXPZhx2QvQynwWaByU5xDx6beRgsM1q7t3M3QIc=; b=A2SxNph/DNpdrT9d3hveZB91fLfSAP4PkBx0flA7BTnis9Ybo6vd5+lOioDg+TZ0Ri UQXG2pBoHeTKCKeD415ZXXB5GWUv7NxTfeZNIK9crwiLoYhbiKX+JToa4SGqgAXWIIJc g26La4rUgq/xtdJNAyy0KfalOqEaD5+d4Llx1bemL99Oqk+5WARcSBiZDEI0t+vXFF04 jFDPS6JycPQH4FYLHi944/szEz5e5Sz73adaax9pmd/4AH9NYDw9PgbxO3i4T//u0t8/ PZ1ZBAlmtXlQsjMITCrfaxckXef1/o+lKmNcU/N7gmO39+qBPOFN05XmP4w56jgPRU1o V3mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=A5REIXPZhx2QvQynwWaByU5xDx6beRgsM1q7t3M3QIc=; b=AKFe8qTgAPs4p/N40p7BUnWTbKg5Z7kxcDbnMDnFJ6EzAu98D9G240eRos+yzZDz27 8TIRJ5pU3GnA8wS8JLDTopuF1yJHHssvIZkI0Ht8zkMwjMA7cKtenbLBZJHhLXmN4bDz j37zfPpGOvTL0+kZh8u/jK++HRpbvK3n6qRvWlXIa9+F5xLKMF+91ndhoEY3vYaZ7Ouv 39yx0wwuGocHny2vMrS3BfoIWKo1kbvrFRSsABhuydxmQqeJq0hTW0Po3nLv4PxrADj3 qyZtA0DsaH6aZUQFkIcX7Pjnpz7Nlr8TOsZOw68qOhD+RI2LrYF8mb7yaWS3URSecEPV QPZQ== X-Gm-Message-State: ACgBeo2pNhNhm4pQHK+z/CHh6UEu68bkOyQsQh48+zjp9Y1Rz6HHXuzD mzuGAhTbKNWdKGqU5Eg0qBHkWKQJbeWDr+owWZ4= X-Received: by 2002:ac8:7f88:0:b0:342:e9dc:ee77 with SMTP id z8-20020ac87f88000000b00342e9dcee77mr14870523qtj.384.1660058623938; Tue, 09 Aug 2022 08:23:43 -0700 (PDT) MIME-Version: 1.0 References: <6c8e4104-2239-a188-649d-585f059cabdd@intel.com> <2c6a4a61-e6c8-0487-8d29-dc3fbb90bbe2@intel.com> In-Reply-To: From: Andy Shevchenko Date: Tue, 9 Aug 2022 17:23:06 +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" 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, Aug 9, 2022 at 11:55 AM Cezary Rojewski wrote: > On 2022-07-12 4:24 PM, Andy Shevchenko wrote: ... > I've spent some time analyzing possible utilization of _Generic() in > context of get_options() but in my opinion get_range() complicates > things enough that get_range() and get_option() would basically need a > copy per type. Thanks for keeping us updated. > If Linux kernel guarantees that sizeof(int), sizeof(unsigned int), > sizeof(s32) and sizeof(u32) are all equal (given the currently supported > arch set), then indeed modifying get_options() may not be necessary. > This plus shamelessly casting (u32 *) to (int *) of course. I think as long as Linux kernel states that it requires (at least) 32-bit architecture to run, we are fine. I have heard of course about a funny project of running Linux on 8-bit microcontrollers, but it's such a fun niche, which by the way uses emulation without changing actual 32-bit code, that I won't even talk about. > What's left to do is the __user helper function. What I have in mind is: > > int tokenize_user_input(const char __user *from, size_t count, loff_t > *ppos, int **tkns) > { > int *ints, nints; > char *buf; > int ret; > > buf = kmalloc(count + 1, GFP_KERNEL); > if (!buf) > return -ENOMEM; > > ret = simple_write_to_buffer(buf, count, ppos, from, count); > if (ret != count) { > ret = (ret < 0) ? ret : -EIO; > goto free_buf; > } > > buf[count] = '\0'; I guess this may be simplified with memdup_user(). Otherwise it looks like that. > get_options(buf, 0, &nints); (You don't use ppos here, so it's pointless to use simple_write_to_buffer(), right? I have noticed this pattern in SOF code, which might be simplified the same way as I suggested above) > if (!nints) { > ret = -ENOENT; > goto free_buf; > } > > ints = kcalloc(nints + 1, sizeof(*ints), GFP_KERNEL); > if (!ints) { > ret = -ENOMEM; > goto free_buf; > } > > get_options(buf, nints + 1, ints); > *tkns = ints; > ret = 0; > > free_buf: > kfree(buf); > return ret; > } ... > as a part of fs/libfs.c not lib/cmdline.c. Is such approach acceptable? I think so. -- With Best Regards, Andy Shevchenko