Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp825524rwe; Thu, 25 Aug 2022 09:44:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5UBjqe5vNXImC/TdYf/yQB8Zy4yybni9W7oNxjrmgdghcWJMKg3NsrAOiqTUTw1+a2Jn5i X-Received: by 2002:a05:6402:4313:b0:446:ffc0:50b5 with SMTP id m19-20020a056402431300b00446ffc050b5mr3768757edc.153.1661445857800; Thu, 25 Aug 2022 09:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661445857; cv=none; d=google.com; s=arc-20160816; b=HezPfOmEZPzCNoV34UFfhyPdsW9bk2fnRuhLit6xGUp9mvUXQ6427LctEap3NH8+XR t6feznW3HvNyekpfOCticZHJPJkzePazlFwdpwQYzPpKECNZdss8gcXyNLGw+IzG6i64 8isjXiFLV7/IVnXdBY6BY8WQ3CfBQVOqqavNzQByKjpCX0B9x0tuEuJVN2S8DOo2CvLQ ckLWzfwMszgGSAkXppnbCJDn2ZEhhjS0rNIGxhX5ert29yABrBYO3oI561/SbxQuXnw1 EmtoxtBc1TmrXoKhnfkV3fXi12IAllIusLGeuLeqjNe1pSqXvPQQxzS2WSoIoBlu/Zt9 faig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v/OmEx+Mr24RWa1XFUEZ1trK1uijocaq1rEnOlOsIUA=; b=c2Jg2bk6uNhRu1xJzFDyHJBR+3DWhC94iMKPOEWpq5dKREiFkZGWI3kOjLkiuazAqT G+YNMM94Oqhxihx921wL6qNZ5xo91H7zODkoQvOBsSqaNGOXUDJqxqLrKA2dTXjEj+EC aJn1fsacgPyGl/uRUubmcLh3Z0Auj5z40RKCSObUyrPupZt3Hje6v+lQqCXuvs6EU5NO 33tu2lBfkd58pr/Ygdh3+cNJ9J6Zq8tZjIlE3Rbos9rsoDgmrWTewQtAb6myJVMQtSis BOF2tg650xrDZlJdLD8FSbKWy36L6hNvicIBIrPabMvBG3giRAD6g9t5rAkL6dIJi/E+ 89yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Agz2JhW3; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a056402500b00b0043dcc0d6eb4si4291807eda.607.2022.08.25.09.43.50; Thu, 25 Aug 2022 09:44:17 -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=@intel.com header.s=Intel header.b=Agz2JhW3; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231604AbiHYQjC (ORCPT + 99 others); Thu, 25 Aug 2022 12:39:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242363AbiHYQiz (ORCPT ); Thu, 25 Aug 2022 12:38:55 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F754BA14F; Thu, 25 Aug 2022 09:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661445535; x=1692981535; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=liGkXhlAm+VXFh8bREExCiBE1UTrJqRblYdv6sZW+iA=; b=Agz2JhW31MrmRDkWVWiNtMxFjltjQTz8+fqte9tu+6VugEgLn5XAUePi dLLMlKeuUsoMgn1TydzNw8nfMR65Ep5ryChU5nNOVcLDtD8Ct52MlmyqR F+d7ZDfrQalVHdreBtKDclnA9lGYG9FM5EDml7gpmh5k3kkihhw2yVXbZ ZrFz3aP0nwQ5P4VO1hHm1WzqKBWjZoudZuKGdOufXgnxTVhRiS4ehswaf z0b2tt6l7vbWRFfibWLx3Vo3OSXbNVCqhwd+++KCDUM8Jjk3ZSNJrZrgF RBCTCnqwAnsbUqDpt+9BoEeOhZtu0/xXhF+YsTgYmqq1npSnLGCC7AcCi g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="320375166" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="320375166" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 09:38:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="671070433" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by fmsmga008.fm.intel.com with ESMTP; 25 Aug 2022 09:38:51 -0700 From: Cezary Rojewski To: alsa-devel@alsa-project.org, broonie@kernel.org Cc: tiwai@suse.com, perex@perex.cz, amadeuszx.slawinski@linux.intel.com, pierre-louis.bossart@linux.intel.com, hdegoede@redhat.com, lgirdwood@gmail.com, kai.vehmanen@linux.intel.com, peter.ujfalusi@linux.intel.com, ranjani.sridharan@linux.intel.com, yung-chuan.liao@linux.intel.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, andy.shevchenko@gmail.com, Cezary Rojewski Subject: [PATCH v2 1/2] libfs: Introduce tokenize_user_input() Date: Thu, 25 Aug 2022 18:48:32 +0200 Message-Id: <20220825164833.3923454-2-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220825164833.3923454-1-cezary.rojewski@intel.com> References: <20220825164833.3923454-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Add new helper function to allow for splitting specified user string into a sequence of integers. Internally it makes use of get_options() so the returned sequence contains the integers extracted plus an additional element that begins the sequence and specifies the integers count. Suggested-by: Andy Shevchenko Signed-off-by: Cezary Rojewski --- fs/libfs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 46 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 31b0ddf01c31..078b23e26741 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -809,6 +809,51 @@ ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, } EXPORT_SYMBOL(simple_write_to_buffer); +/** + * tokenize_user_input - Split string into a sequence of integers + * @from: The user space buffer to read from + * @ppos: The current position in the buffer + * @count: The maximum number of bytes to read + * @tkns: Returned pointer to sequence of integers + * + * On success @tkns is allocated and initialized with a sequence of + * integers extracted from the @from plus an additional element that + * begins the sequence and specifies the integers count. + * + * Caller takes responsibility for freeing @tkns when it is no longer + * needed. + */ +int tokenize_user_input(const char __user *from, size_t count, int **tkns) +{ + int *ints, nints; + char *buf; + int ret = 0; + + buf = memdup_user_nul(from, count); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + get_options(buf, 0, &nints); + 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; + +free_buf: + kfree(buf); + return ret; +} +EXPORT_SYMBOL(tokenize_user_input); + /** * memory_read_from_buffer - copy data from the buffer * @to: the kernel space buffer to read to diff --git a/include/linux/fs.h b/include/linux/fs.h index 9eced4cc286e..ab04cc7f9efa 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3345,6 +3345,7 @@ extern ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos, const void *from, size_t available); extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, const void __user *from, size_t count); +extern int tokenize_user_input(const char __user *from, size_t count, int **tkns); extern int __generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_file_fsync(struct file *, loff_t, loff_t, int); -- 2.25.1